Exemplo n.º 1
0
 public static function getPopularBusinesses()
 {
     $business_ids = Business::select('business_id')->get();
     $business_arr = [];
     foreach ($business_ids as $business) {
         array_push($business_arr, Business::getBusinessArray($business->business_id));
     }
     $date = new DateTime();
     $newDate = $date->modify('-7 days');
     $enddate = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
     $startdate = mktime(0, 0, 0, $newDate->format('m'), $newDate->format('d'), $newDate->format('Y'));
     $currMax = 0;
     $new_bizz_array = [];
     foreach ($business_arr as $b_id => $business) {
         $count = Analytics::getTotalNumbersCalledByBusinessIdWithDate($business->business_id, $startdate, $enddate);
         $business_arr[$b_id]->count = $count;
         if ($count > $currMax) {
             array_unshift($new_bizz_array, $business_arr[$b_id]);
             $currMax = $count;
         } else {
             array_push($new_bizz_array, $business_arr[$b_id]);
         }
     }
     return $new_bizz_array;
 }