Ejemplo n.º 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;
 }
Ejemplo n.º 2
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())];
 }