Example #1
0
 public function __invoke($entities)
 {
     if (!is_array($entities)) {
         throw new FormatterException('Collection formatter requries an array of entities');
     }
     $output = ['type' => 'FeatureCollection', 'features' => []];
     foreach ($entities as $entity) {
         $geometries = [];
         foreach ($entity->values as $attribute => $values) {
             foreach ($values as $value) {
                 if ($geometry = $this->valueToGeometry($value)) {
                     $geometries[] = $geometry;
                 }
             }
         }
         if (!empty($geometries)) {
             $output['features'][] = ['type' => 'Feature', 'geometry' => ['type' => 'GeometryCollection', 'geometries' => $geometries], 'properties' => ['title' => $entity->title, 'description' => $entity->content, 'id' => $entity->id, 'url' => URL::site(Ushahidi_Rest::url($entity->getResource(), $entity->id), Request::current())]];
         }
     }
     if ($this->search->bbox) {
         if (is_array($this->search->bbox)) {
             $bbox = $this->search->bbox;
         } else {
             $bbox = explode(',', $this->search->bbox);
         }
         $output['bbox'] = $bbox;
     }
     return $output;
 }
Example #2
0
 protected function _is_auth_required()
 {
     if (parent::_is_auth_required()) {
         // Completely anonymous access is allowed for (some) GET requests.
         // Further checks are made down the stack.
         return $this->request->method() !== Request::GET;
     }
     return FALSE;
 }
Example #3
0
 /**
  * Retrieve All Posts
  *
  * GET /api/posts
  *
  * @return void
  */
 public function action_get_index_collection()
 {
     parent::action_get_index_collection();
     // Ensure identifiers are set for parent checks
     $this->_usecase->setIdentifiers($this->_identifiers());
 }
Example #4
0
 public function action_post_index_collection()
 {
     parent::action_post_index_collection();
     $this->_usecase->setIdentifiers($this->request->param());
 }
Example #5
0
 /**
  * Format relations into url/id arrays
  * @param  string $resource resource name as used in urls
  * @param  int    $id       resource id
  * @return array
  */
 protected function get_relation($resource, $id)
 {
     return !$id ? NULL : ['id' => $id, 'url' => URL::site(Ushahidi_Rest::url($resource, $id), Request::current())];
 }
Example #6
0
 public function action_get_index_collection()
 {
     parent::action_get_index_collection();
     $this->_usecase->setIdentifiers($this->request->param());
     $this->_usecase->setFilters($this->request->query() + ['form_id' => $this->request->param('form_id')]);
 }