public function regularReport(DeviceReport $report) { // add device status to database // var_dump($report); $locMod = new LocationModel(); $placeMod = new SafetyPlaceModel(); $notiMod = new NotificationModel(); $dReportMod = new DeviceReportModel(); $studMod = new StudentModel(); $userId = $report->getUserId(); $inSchool = false; $inHome = false; $placeMatched = false; $placeStatus = 3; try { //Get Latest Place Status $placeStatus = $placeMod->getLatestPlaceStatus($userId); // $place = $placeMod->getSchool(); // if($place != null){ // $inSchool = $locMod->isInArea( // $place->getLat(), // $place->getLng(), // $place->getRadius(), // $report->getPosition()->getLat(), // $report->getPosition()->getLng() // ); // if($inSchool){ // $placeMatched = true; // } // } if (!$placeMatched) { // print "user id :".$userId; $p = $placeMod->get($userId); // var_dump($p); foreach ($p as $placeItem) { $inHome = $locMod->isInArea($placeItem->getLat(), $placeItem->getLng(), $placeItem->getRadius(), $report->getPosition()->getLat(), $report->getPosition()->getLng()); // print "inHome :" . $inHome; if ($inHome) { $placeMatched = true; break; } } } if ($placeMatched && $inSchool) { // print "updated place status :" . 1; $report->setPlaceStatus(1); } else { if ($placeMatched && $inHome) { // print "updated place status :" . 2; $report->setPlaceStatus(2); } else { // print "updated place status :" . 3; $report->setPlaceStatus(3); } } // print 1111; // print "report place status : " . $report->getPlaceStatus() . " | place status in server : ". $placeStatus ; // Add notification if place status changed if ($report->getPlaceStatus() != $placeStatus) { // print 22222; $student = $studMod->getStudent($userId); $notification = new Notification(); $notification->setEventDt($report->getDateTime()); $notification->setProirity(2); $notification->setType("Place Changed"); $notification->setStatus("P"); $notification->setUserId($userId); switch ($report->getPlaceStatus()) { case 1: $notification->setMsg("Observee : " . $student->getName() . " - Student in school now"); break; case 2: $notification->setMsg("Observee : " . $student->getName() . " - Check in to a check point"); break; case 3: $notification->setMsg("Observee : " . $student->getName() . " - Check Out of Check point"); break; } // print 33333; $notiMod->addNotification($notification); // print 44444; } // print 55555; //Add Device report $res = $dReportMod->add($report); if ($res == 1) { $result['result'] = "success"; } else { $Result['result'] = "fail"; } } catch (SSSException $e) { $result = ErrorFactory::getError($e->getCode()); } return $result; }
/** * Get location by date * @param unknown $userId * @param unknown $date * @throws SSSException * @return array */ public function getLocationsByDate($userId, $date) { $sp = "sp_student_location_getByDate"; $params = new SDMDBParameters(); $params->add($userId); $params->add($date); // var_dump($params); $result = $this->handler->execute_stored_procedure($sp, $params, 'array'); $ret = false; // var_dump($result); if ($result && $result['response']['system']['errorNo'] == 0) { if (isset($result['response']['resultSet'])) { $deviceReports = array(); foreach ($result['response']['resultSet'] as $dataRow) { // $student = new Student(); // $student->setClassId($dataRow['class_id']); // $student->setId($dataRow['user_id']); // $student->setName($dataRow['login_name']); // $student->setStudentId($dataRow['student_id']); // $device = new Device(); // $device->setWifiMacAddress($dataRow['wifi_address']); $position = new Position(); $position->setAccuracy($dataRow['gps_accuracy']); $position->setAtt($dataRow['altitude']); $position->setDateTime($dataRow['gps_Dt']); // $position->setEnable($dataRow['gps_accuracy']); $position->setLat($dataRow['latitude']); $position->setLng($dataRow['longitude']); // $position->setPlace($dataRow['gps_accuracy']); $deviceReport = new DeviceReport(); $deviceReport->setBatt($dataRow['battery_status']); $deviceReport->setDateTime($dataRow['report_dt']); $deviceReport->setSignal($dataRow['network_coverage_status']); $deviceReport->setMovement($dataRow['movement_status']); $deviceReport->setUserId($dataRow['user_id']); $deviceReport->setId($dataRow['report_id']); $deviceReport->setGPS($dataRow['gps_status']); $deviceReport->setPlaceStatus($dataRow['place_status']); $deviceReport->setPosition($position); // $student->setDevice($device); // $student->setReport($deviceReport); array_push($deviceReports, $deviceReport); } // var_dump($students); return $deviceReports; } else { $ret = false; } } else { throw new SSSException(ErrorFactory::ERR_DB_EXECUTE); } return $ret; }