77 lines
1.9 KiB
PHP
77 lines
1.9 KiB
PHP
<?php
|
|
|
|
class GeofenceApi extends Api
|
|
{
|
|
public $apiName = 'geofence';
|
|
|
|
public function indexAction()
|
|
{
|
|
return $this->response(
|
|
array(
|
|
'error' => 'Data not found'
|
|
), 404);
|
|
}
|
|
|
|
/**
|
|
* Method GET
|
|
* Get single record (by id)
|
|
* http://DOMAIN/trips/1
|
|
* @return string
|
|
*/
|
|
public function viewAction()
|
|
{
|
|
//id must be the first parameter after /trips/x
|
|
$id = array_shift($this->requestUri);
|
|
|
|
if($id && (int)$id>0){
|
|
$db = new Db();
|
|
$tripOptions = NULL; //Trips::getOptionsById($db->getConnect(), (int)$id);
|
|
if(is_array($tripOptions) && count($tripOptions)>0){
|
|
return $this->response(
|
|
array(
|
|
'id' => $id,
|
|
'count' => count($tripOptions),
|
|
'options' => $tripOptions
|
|
), 200);
|
|
}
|
|
}
|
|
return $this->response(
|
|
array(
|
|
'error'=> 'Data not found'
|
|
), 404);
|
|
}
|
|
|
|
public function createAction()
|
|
{
|
|
return $this->response(
|
|
array(
|
|
"error" => "Saving error"
|
|
), 500);
|
|
}
|
|
|
|
public function updateAction()
|
|
{
|
|
return $this->response(
|
|
array(
|
|
"error" => "Update error"
|
|
), 400);
|
|
}
|
|
|
|
public function deleteAction()
|
|
{
|
|
return $this->response(
|
|
array(
|
|
"error" => "Delete error"
|
|
), 500);
|
|
}
|
|
|
|
public static function getAnchor($db, $lat, $lng)
|
|
{
|
|
if ($lat===NULL || $lng===NULL || ($lat===0 && $lng===0)) {
|
|
return [NULL, "Invalid GPS coordinates"];
|
|
}
|
|
return Geofence::getAnchor($db->getConnect(), $lat, $lng);
|
|
//return [NULL, "Not implemented"];
|
|
}
|
|
}
|