public function add(DeviceReport $report) { $sp = "sp_deviceReport_add"; $pos = $report->getPosition(); // var_dump($pos); // var_dump($report); $params = new SDMDBParameters(); $params->add($report->getUserId()); $params->add($report->getDateTime()); $params->add($report->getBatt()); $params->add($report->getGPS()); $params->add($report->getMovement()); $params->add($report->getSignal()); $params->add($pos->getLat()); $params->add($pos->getLng()); $params->add($pos->getAccuracy()); $params->add($pos->getAtt()); $params->add($pos->getDateTime()); $params->add($report->getPlaceStatus()); // var_dump($params); // echo "<BR>"; $result = $this->handler->execute_stored_procedure($sp, $params, 'array'); // var_dump($result); $ret = false; if ($result && $result['response']['system']['errorNo'] == 0) { if (isset($result['response']['resultSet'])) { if (isset($result['response']['resultSet'][0]['result'])) { $ret = $result['response']['resultSet'][0]['result']; } else { throw new SSSException(ErrorFactory::ERR_DB_INVALID_RESULT); } } else { $ret = false; } } else { throw new SSSException(ErrorFactory::ERR_DB_EXECUTE); } return $ret; }
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; }