public function postLocationlog() { $device_name = Input::get('device_identifier'); $timestamp = Input::get('timestamp'); $courier = Input::get('courier'); $status = Input::get('status'); $stepping = Input::get('stepping'); $device_name = $device_name == '' ? 'all' : $device_name; $timestamp = $timestamp == '' ? date('Y-m-d', time()) : $timestamp; $courier = $courier == '' ? 'all' : $courier; $status = $status == '' ? 'all' : $status; //$stepping = ($stepping == '')?10:$stepping; $statuses = Config::get('jex.mapdefstatus'); $model = new Geolog(); if ($device_name == 'all') { $devices = Geolog::distinct('deviceId')->get(); } else { $devices = Geolog::distinct('deviceId')->where('deviceId', 'regexp', '/' . $device_name . '/i')->get('deviceId'); } $locations = array(); $paths = array(); $pathdummy = array(); foreach ($devices->toArray() as $d) { $deviceId = $d[0]; $mapcolor = Prefs::get_device_color($deviceId); $timestamps = explode(' - ', $timestamp); if (count($timestamps) == 2) { $daystart = trim($timestamps[0]) . ' 00:00:00'; $dayend = trim($timestamps[1]) . ' 23:59:59'; } else { $daystart = $timestamp . ' 00:00:00'; $dayend = $timestamp . ' 23:59:59'; } $daystart = new MongoDate(strtotime($daystart)); $dayend = new MongoDate(strtotime($dayend)); $model = new Geolog(); $model = $model->where('deviceId', '=', $deviceId)->whereBetween('mtimestamp', array($daystart, $dayend)); if ($status != 'all') { $model = $model->where('status', 'regexp', '/' . $status . '/i'); } /* else{ $model = $model->whereIn('status',$statuses); }*/ $model = $model->where('appname', '=', Config::get('jex.tracker_app')); $locs = $model->orderBy('mtimestamp', 'desc')->get(); //print_r($locs); if (count($locs->toArray()) > 0) { $path = array(); $locv = array(); $curr = null; $next = 1; $locarr = $locs->toArray(); //print count($locarr)."|\r\n"; //for($i = 0; $i < count($locs->toArray());$i++){ while (!is_null($next)) { if (is_null($curr)) { $curr = array_shift($locarr); $locv[] = (object) $curr; } $next = array_shift($locarr); if (!is_null($next)) { $st = true; $key = strtotime($next['datetimestamp']); if (isset($next['status']) && in_array($next['status'], $statuses)) { $curr = $next; $locv[$key] = (object) $next; $st = false; } if ($st) { $span = doubleval($next['timestamp']) - doubleval($curr['timestamp']); if (abs($span) >= doubleval($stepping) * 60) { $curr = $next; $locv[$key] = (object) $next; } } } } krsort($locv); //print count($locv)."||\r\n"; foreach ($locv as $t => $l) { //print_r($l); $lat = isset($l->latitude) ? doubleval($l->latitude) : 0; $lng = isset($l->longitude) ? doubleval($l->longitude) : 0; $status = isset($l->status) && $l->status == '' ? $l->status : 'report'; if ($lat != 0 && $lng != 0) { $locations[] = array('data' => array('id' => $l->_id, 'lat' => $lat, 'lng' => $lng, 'timestamp' => $l->datetimestamp, 'identifier' => $l->deviceId, 'delivery_id' => $l->deliveryId, 'status' => $status)); $path[] = array($lat, $lng); $pathdummy[] = array($l->deviceId, $l->timestamp, $lat, $lng); } } $paths[] = array('color' => $mapcolor, 'poly' => $path); } } print json_encode(array('result' => 'ok', 'locations' => $locations, 'paths' => $paths, 'pathdummy' => $pathdummy, 'q' => '')); }