public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { OffPod::create(['pod_id' => rand(1, 5), 'state' => array_rand(array('X', '0', '1', '2')), 'from_time' => $faker->time($format = 'H:i:s', $max = 'now')]); } }
public function quickIntervalCron() { date_default_timezone_set('Asia/Kathmandu'); $podsOff = OffPod::all(); $grace_time = GraceTime::first()->period; $currentDay = date('w'); $currentTime = date("H:i:s"); foreach ($podsOff as $podOff) { //check the schedule if ($podOff->pod->schedule_type == 0) { //check whether the pods are within schedule or not if ($podOff->schedule_id == 0 or $podOff->schedule_id == null) { $pod_off_from_time = $podOff->from_time; $added_to_grace_time = date('H:i:s', strtotime("+{$grace_time} minutes", strtotime($pod_off_from_time))); if ($currentTime <= $added_to_grace_time) { //do nothing } else { //check whether now it lies within someschedule or not $schedule = $podOff->pod()->first()->groupSchedules()->first()->schedules()->where('day', '=', $currentDay)->where('from_time', '<=', $currentTime)->where('to_time', '>=', $currentTime)->first(); if (is_object($schedule)) { //change to state 1 and add schedule $podOff->schedule_id = $schedule->id; $podOff->state = "1"; $podOff->save(); } else { //change to state 3 and send notification $podOff->state = "3"; $podOff->save(); //$this->send_sms('9808103913',$podOff->pod->apiPod->pod.' pod has entered in red zone.'); } } } else { $schedule_to_time = $podOff->schedule->to_time; if ($currentTime <= $schedule_to_time) { //do nothing } else { //check for the garce time $added_time = date('H:i:s', strtotime("+{$grace_time} minutes", strtotime($schedule_to_time))); if ($currentTime <= $added_time) { //change the state to 2 $podOff->state = "2"; $podOff->save(); } else { //change the state to 3 $podOff->state = "3"; $podOff->save(); } } } } else { //check the grace time $exceptionTime = $podOff->pod()->first()->expSchedules()->first()->timespan; $added_to_exp_time = date('H:i:s', strtotime("+{$exceptionTime} minutes", strtotime($podOff->from_time))); echo $currentTime . ' ' . $added_to_exp_time; if ($currentTime <= $added_to_exp_time) { //do nothing } else { $added_to_grace_time = date('H:i:s', strtotime("+{$grace_time} minutes", strtotime($added_to_exp_time))); echo " " . $added_to_grace_time; if ($currentTime <= $added_to_grace_time) { $podOff->state = "2"; $podOff->save(); } else { $podOff->state = "3"; $podOff->save(); //send sms //$this->send_sms('9808103913',$podOff->pod->apiPod->pod.' pod has entered in red zone.'); } } } } }