Last active
August 29, 2015 14:07
-
-
Save dmdevoss/c9b30802e31c96c9ca25 to your computer and use it in GitHub Desktop.
Simple function to count up new listings based on type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Description: | |
* Returns a count of new listings, ratings, students, landlords, or roommate requests | |
* that were made within 30 days. | |
* | |
* Input: | |
* $type = 'listings', 'ratings', 'students', 'landlords', or 'roommate'. | |
* | |
*/ | |
private function total_new($type){ | |
$today = date('Y-m-d H:i:s'); | |
$thirty_days_ago = date('Y-m-d H:i:s', strtotime("-30 days") ); | |
if ($type == 'roommates'){ //count the new roommates | |
$count = DB::table('roommates') | |
->where('roommates.status', '=', 'active') | |
->whereBetween('roommates.created_at', array($thirty_days_ago, $today)) | |
->count(); | |
}elseif($type == 'listings'){ // count the listings | |
$count = DB::table('listings') | |
->where('listings.status', '=', 'available') | |
->whereBetween('listings.created_at', array($thirty_days_ago, $today)) | |
->count(); | |
}elseif($type == 'ratings'){ // count the ratings | |
$count = DB::table('ratings') | |
->where('ratings.enabled', '=', '1') | |
->whereBetween('ratings.created_at', array($thirty_days_ago, $today)) | |
->count(); | |
}else{ //count users, either landlords or students | |
$query = DB::table('users') | |
->join('group_user', 'group_user.user_id', '=', 'users.id') | |
->select('users.type') | |
->where('group_user.group_id', '>', '1') | |
->whereBetween('users.created_at', array($thirty_days_ago, $today)); | |
if($type == 'landlord') //get both students and landlord, but not non-registered users | |
$count = $query->where('type', '=', 'landlord')->count(); | |
else | |
$count = $query->where('type', '=', 'student')->count(); | |
} | |
return $count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment