Exemplo n.º 1
0
 public static function getBusinessByNameCountryIndustryTimeopen($name, $country, $industry, $time_open = null, $timezone = null)
 {
     if ($time_open) {
         $time_open_arr = Helper::parseTime($time_open);
     } else {
         $time_open_arr['hour'] = '';
         $time_open_arr['min'] = '';
         $time_open_arr['ampm'] = '';
     }
     if ($industry == 'Industry') {
         $industry = '';
     }
     if (is_numeric($timezone)) {
         $timezones = Helper::timezoneOffsetToNameArray($timezone);
     } else {
         $timezones = [$timezone];
     }
     //ARA this makes editing queries easier
     $query = Business::where('name', 'LIKE', '%' . $name . '%')->where('latitude', '<=', $country['ne_lat'])->where('latitude', '>=', $country['sw_lat'])->where('longitude', '<=', $country['ne_lng'])->where('longitude', '>=', $country['sw_lng'])->where('industry', 'LIKE', '%' . $industry . '%');
     if ($name == '') {
         $query->whereIn('timezone', $timezones);
     }
     if ($time_open_arr['ampm'] == 'PM' && $time_open_arr['min'] == '00') {
         $query->where('open_ampm', '=', 'PM')->where('open_hour', '>=', $time_open_arr['hour']);
     } elseif ($time_open_arr['ampm'] == 'PM' && $time_open_arr['min'] == '30') {
         $query->where('open_ampm', '=', 'PM')->whereRaw('open_hour > ? OR (open_hour = ? AND open_minute = ?)', array($time_open_arr['hour'], $time_open_arr['hour'], '30'));
     } elseif ($time_open_arr['ampm'] == 'AM' && $time_open_arr['min'] == '00') {
         $query->whereRaw('(open_hour >= ? AND open_ampm = ?) OR (open_hour < ? AND open_ampm = ?)', array($time_open_arr['hour'], 'AM', $time_open_arr['hour'], 'PM'));
     } elseif ($time_open_arr['ampm'] == 'AM' && $time_open_arr['min'] == '30') {
         $query->whereRaw('(open_hour > ? AND open_ampm = ?) OR (open_hour < ? AND open_ampm = ?) OR (open_hour = ? AND open_minute = ? AND open_ampm = ?)', array($time_open_arr['hour'], 'AM', $time_open_arr['hour'], 'PM', $time_open_arr['hour'], '30', 'AM'));
     }
     return $query->get();
 }