예제 #1
0
 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')]);
     }
 }
예제 #2
0
 public function podOff($ip_address = "172.20.16.5", $podname = "Dhading")
 {
     date_default_timezone_set('Asia/Kathmandu');
     //echo date('H:i:s');
     $apiPod = ApiPod::where('pod', '=', $podname)->first();
     if (is_object($apiPod)) {
         $apiPod_array = $apiPod->toArray();
         $pod = Pod::where('pod_api_id', '=', $apiPod_array['id'])->first();
         if (is_object($pod)) {
             $pod_array = $pod->toArray();
             if ($pod['schedule_type'] == 1) {
                 $podlog['state'] = "0";
                 $podlog['pod_id'] = $pod_array['id'];
                 $podlog['from_time'] = date('H:i:s');
                 $this->sendNotification($param = array('type' => 'off', 'pod_id' => $pod_array['id'], 'description' => $apiPod_array['pod'] . " went down unexpectedly"));
             } else {
                 $currentTime = date('H:i:s');
                 $currentDay = date('w');
                 $podlog['pod_id'] = $pod_array['id'];
                 $podlog['from_time'] = $currentTime;
                 $groupSchedules = $pod->groupSchedules()->first();
                 if (is_object($groupSchedules)) {
                     $schedules = $groupSchedules->schedules()->where('day', '=', $currentDay)->where('from_time', '<=', $currentTime)->where('to_time', '>=', $currentTime)->get();
                     $schedules_array = $schedules->toArray();
                     if (!empty($schedules_array)) {
                         $podlog['state'] = "1";
                         $podlog['schedule_id'] = $schedules_array['0']['id'];
                         $this->sendNotification($param = array('type' => 'off', 'pod_id' => $pod_array['id'], 'description' => $apiPod_array['pod'] . " went according to its schedule"));
                     } else {
                         $podlog['state'] = "2";
                         $this->sendNotification($param = array('type' => 'off', 'pod_id' => $pod_array['id'], 'description' => $apiPod_array['pod'] . " went off out of its schedule"));
                         // $this->send_sms('9849306373',$apiPod_array['pod'].' pod went down unexpectedly');
                     }
                 }
             }
             //check if th off pod alreday exists
             $offpod = OffPod::where('pod_id', '=', $pod_array['id'])->first();
             if (!is_object($offpod)) {
                 $offPod = OffPod::create($podlog);
             }
         }
     }
 }