public function postPersonalizedBusinesses() { $processing = array(); $not_processing = array(); $post = json_decode(file_get_contents("php://input")); if ($post) { $user_timezone = isset($post->user_timezone) ? $post->user_timezone : 'Asia/Manila'; //ARA set user timezone if any if ($post->latitude && $post->longitude) { $res = Business::getBusinessByLatitudeLongitude($post->latitude, $post->longitude, $user_timezone); // get location first if (!count($res)) { $res = Business::all(); } } else { $res = Business::all(); } foreach ($res as $count => $data) { $first_service = Service::getFirstServiceOfBusiness($data->business_id); $all_numbers = ProcessQueue::allNumbers($first_service->service_id); $time_open = $data->open_hour . ':' . Helper::doubleZero($data->open_minute) . ' ' . strtoupper($data->open_ampm); $time_close = $data->close_hour . ':' . Helper::doubleZero($data->close_minute) . ' ' . strtoupper($data->close_ampm); // check if business is currently processing numbers if (Business::processingBusinessBool($data->business_id)) { if (Auth::check()) { $processing[] = array('business_id' => $data->business_id, 'business_name' => $data->name, 'local_address' => $data->local_address, 'time_open' => Helper::changeBusinessTimeTimezone($time_open, $data->timezone, $user_timezone), 'time_close' => Helper::changeBusinessTimeTimezone($time_close, $data->timezone, $user_timezone), 'waiting_time' => Analytics::getWaitingTimeString($data->business_id), 'last_number_called' => count($all_numbers->called_numbers) > 0 ? $all_numbers->called_numbers[0]['priority_number'] : 'none', 'next_available_number' => $all_numbers->next_number, 'last_active' => Analytics::getLastActive($data->business_id), 'card_bool' => true); } else { $processing[] = array('business_id' => $data->business_id, 'business_name' => $data->name, 'local_address' => $data->local_address); } } else { if (Auth::check()) { $not_processing[] = array('business_id' => $data->business_id, 'business_name' => $data->name, 'local_address' => $data->local_address, 'time_open' => Helper::changeBusinessTimeTimezone($time_open, $data->timezone, $user_timezone), 'time_close' => Helper::changeBusinessTimeTimezone($time_close, $data->timezone, $user_timezone), 'waiting_time' => Analytics::getWaitingTimeString($data->business_id), 'last_number_called' => count($all_numbers->called_numbers) > 0 ? $all_numbers->called_numbers[0]['priority_number'] : 'none', 'next_available_number' => $all_numbers->next_number, 'last_active' => Analytics::getLastActive($data->business_id), 'card_bool' => false); } else { $not_processing[] = array('business_id' => $data->business_id, 'business_name' => $data->name, 'local_address' => $data->local_address); } } } $merged_businesses = array_merge($processing, $not_processing); if (Auth::check()) { // dashboard business boxes should be 8; known users will be redirected to dashboard $merged_businesses = array_slice($merged_businesses, 0, 8); } else { // homepage business boxes should be only 7 to give space for (more business) box; anon users will be redirected to homepage $merged_businesses = array_slice($merged_businesses, 0, 7); } return json_encode($merged_businesses); } }
/** * @author Ruffy * @return JSON response containing list of active businesses */ public function getActiveBusiness() { $active_businesses = array(); $businesses = Business::all(); foreach ($businesses as $count => $business) { $branches = Branch::getBranchesByBusinessId($business->business_id); foreach ($branches as $count2 => $branch) { $services = Service::getServicesByBranchId($branch->branch_id); foreach ($services as $count3 => $service) { $priority_numbers = PriorityNumber::getTrackIdByServiceId($service->service_id); foreach ($priority_numbers as $count4 => $priority_number) { $priority_queues = PriorityQueue::getTransactionNumberByTrackId($priority_number->track_id); foreach ($priority_queues as $count5 => $priority_queue) { $terminal_transactions = TerminalTransaction::getTimesByTransactionNumber($priority_queue->transaction_number); foreach ($terminal_transactions as $count6 => $terminal_transaction) { $grace_period = time() - $terminal_transaction->time_queued; // issued time must be on the current day to count as active if ($terminal_transaction->time_queued != 0 && $terminal_transaction->time_completed == 0 && $terminal_transaction->time_removed == 0 && $grace_period < 86400) { // 1 day; 60secs * 60 min * 24 hours $active_businesses[] = array('business_id' => $business->business_id, 'local_address' => $business->local_address, 'name' => $business->name); $actives = array('active-business' => $active_businesses); break; } } if (array_key_exists($business->business_id, $active_businesses)) { break; } } if (array_key_exists($business->business_id, $active_businesses)) { break; } } if (array_key_exists($business->business_id, $active_businesses)) { break; } } if (array_key_exists($business->business_id, $active_businesses)) { break; } } } return Response::json($actives, 200, array(), JSON_PRETTY_PRINT); }
/** * Display a listing of products * * @return Response */ public function index() { $businesses = Business::all(); return Response::json($businesses); }
public function getJsonFixer() { $res = Business::all(); foreach ($res as $count => $business) { $business_id = $business->business_id; //$data = json_decode(file_get_contents(public_path() . '/json/' . $business_id . '.json')); $data = json_decode(file_get_contents(public_path() . '/json/' . $business_id . '.json')); if (!isset($data->show_issued)) { $data->show_issued = TRUE; } if (!isset($data->ad_image)) { $data->ad_image = ""; } if (!isset($data->ad_video)) { $data->ad_video = ""; } if (!isset($data->ad_type) || $data->ad_type == "") { $data->ad_type = "image"; } if (!isset($data->turn_on_tv)) { $data->turn_on_tv = FALSE; } if (!isset($data->tv_channel)) { $data->tv_channel = ""; } if (!isset($data->ticker_message)) { $data->ticker_message = ""; } if (!isset($data->ticker_message2)) { $data->ticker_message2 = ""; } if (!isset($data->ticker_message3)) { $data->ticker_message3 = ""; } if (!isset($data->ticker_message4)) { $data->ticker_message4 = ""; } if (!isset($data->ticker_message5)) { $data->ticker_message5 = ""; } //$data->display = "1-6"; $encode = json_encode($data); file_put_contents(public_path() . '/json/' . $business_id . '.json', $encode); } echo 'JSON files are now fixed.'; }