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; }
$result = $ctr->checkClientLogin($user, $device); } catch (SSSException $e) { $result = ErrorFactory::getError($e->getCode()); } } break; // Student Features // Student Features case "regularReport": if (validate_input_param($params, array('id', 'datetime', 'batt', 'pos', 'signal', 'movement'))) { $pos = $params['pos']; $batt = $params['batt']; $signal = $params['signal']; $movement = $params['movement']; $dt = $params['datetime']; $report = new DeviceReport(); $p = new Position(); $p->setAtt($pos['att']); $p->setLat($pos['lat']); $p->setLng($pos['lng']); $p->setDateTime($pos['dt']); $p->setAccuracy($pos['acy']); // $p->setEnable($pos['gpsStatus']); // var_dump($p); $report->setUserId($params['id']); $report->setPosition($p); $report->setBatt($batt); $report->setSignal($signal); $report->setMovement($movement); $report->setDateTime($dt); $report->setGPS($pos['gpsStatus']);
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; }