Пример #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_Api::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;
 }
Пример #2
0
 /**
  * Prepare set data for API, along with all its 
  * groups and attributes
  * 
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         $response = array('id' => $this->id, 'url' => Ushahidi_Api::url('sets', $this->id), 'name' => $this->name, 'filter' => $this->filter, 'user' => empty($this->user_id) ? NULL : array('id' => $this->user_id, 'url' => Ushahidi_Api::url('users', $this->user_id)), 'created' => ($created = DateTime::createFromFormat('U', $this->created)) ? $created->format(DateTime::W3C) : $this->created, 'updated' => ($updated = DateTime::createFromFormat('U', $this->updated)) ? $updated->format(DateTime::W3C) : $this->updated);
     } else {
         $response = array('errors' => array('Set does not exist'));
     }
     return $response;
 }
Пример #3
0
 /**
  * Prepare group data for API
  *
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         $response = array('id' => $this->id, 'url' => Ushahidi_Api::url('forms/' . $this->form_id . '/groups', $this->id), 'form' => empty($this->form_id) ? NULL : array('url' => Ushahidi_Api::url('forms', $this->form_id), 'id' => $this->form_id), 'label' => $this->label, 'priority' => $this->priority, 'icon' => $this->icon, 'attributes' => array());
         foreach ($this->form_attributes->find_all() as $attribute) {
             $response['attributes'][] = $attribute->for_api();
         }
     } else {
         $response = array('errors' => array('Group does not exist'));
     }
     return $response;
 }
Пример #4
0
 /**
  * Prepare form data for API, along with all its
  * stages and attributes
  *
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         $response = array('id' => $this->id, 'url' => Ushahidi_Api::url('forms/', $this->id), 'name' => $this->name, 'description' => $this->description, 'type' => $this->type, 'disabled' => (bool) $this->disabled, 'created' => ($created = DateTime::createFromFormat('U', $this->created)) ? $created->format(DateTime::W3C) : $this->created, 'updated' => ($updated = DateTime::createFromFormat('U', $this->updated)) ? $updated->format(DateTime::W3C) : $this->updated, 'groups' => array());
         foreach ($this->form_stages->find_all() as $stages) {
             $response['stages'][] = $stage->for_api();
         }
     } else {
         $response = array('errors' => array('Form does not exist'));
     }
     return $response;
 }
Пример #5
0
 /**
  * Prepare media data for API
  *
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         // Set image dimensions from the config file
         $medium_width = Kohana::$config->load('media.image_medium_width');
         $medium_height = Kohana::$config->load('media.image_medium_height');
         $thumbnail_width = Kohana::$config->load('media.image_thumbnail_width');
         $thumbnail_height = Kohana::$config->load('media.image_thumbnail_height');
         $upload_path = Kohana::$config->load('media.media_upload_dir');
         $relative_path = str_replace(Kohana::$config->load('imagefly.source_dir'), '', Kohana::$config->load('media.media_upload_dir'));
         $original_file = $upload_path . $this->o_filename;
         $response = array('id' => $this->id, 'user' => empty($this->user_id) ? NULL : array('id' => $this->user_id, 'url' => Ushahidi_Api::url('users', $this->user_id)), 'url' => Ushahidi_Api::url('media', $this->id), 'caption' => $this->caption, 'mime' => $this->mime, 'original_file_url' => URL::site(Media::uri($relative_path . $this->o_filename), Request::current()), 'original_file_size' => is_file($original_file) ? filesize($upload_path . $this->o_filename) : 0, 'original_width' => $this->o_width, 'original_height' => $this->o_height, 'medium_file_url' => $this->_resized_url($medium_width, $medium_height, $relative_path . $this->o_filename), 'medium_width' => $medium_width, 'medium_height' => $medium_height, 'thumbnail_file_url' => $this->_resized_url($thumbnail_width, $thumbnail_height, $relative_path . $this->o_filename), 'thumbnail_width' => $thumbnail_width, 'thumbnail_height' => $thumbnail_height, 'created' => ($created = DateTime::createFromFormat('U', $this->created)) ? $created->format(DateTime::W3C) : $this->created, 'updated' => ($updated = DateTime::createFromFormat('U', $this->updated)) ? $updated->format(DateTime::W3C) : $this->updated);
     } else {
         $response = array('errors' => array('Media does not exist'));
     }
     return $response;
 }
Пример #6
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_Api::url($resource, $id), Request::current())];
 }
Пример #7
0
 /**
  * Prepare data for API
  *
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         $response = array('id' => $this->id, 'url' => Ushahidi_Api::url('contacts', $this->id), 'user' => empty($this->user_id) ? NULL : array('id' => $this->user_id, 'url' => Ushahidi_Api::url('users', $this->user_id)), 'contact' => $this->contact, 'type' => $this->type, 'data_provider' => $this->data_provider, 'created' => ($created = DateTime::createFromFormat('U', $this->created)) ? $created->format(DateTime::W3C) : $this->created);
     } else {
         $response = array('errors' => array('Message does not exist'));
     }
     return $response;
 }
Пример #8
0
 /**
  * Prepare form data for API, along with all its
  * groups and attributes
  *
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         $response = array('id' => $this->id, 'url' => Ushahidi_Api::url('tags', $this->id), 'parent' => empty($this->parent_id) ? NULL : array('id' => $this->parent_id, 'url' => Ushahidi_Api::url('tags', $this->parent_id)), 'tag' => $this->tag, 'slug' => $this->slug, 'type' => $this->type, 'color' => $this->color ? '#' . $this->color : null, 'icon' => $this->icon, 'description' => $this->description, 'priority' => $this->priority, 'created' => ($created = DateTime::createFromFormat('U', $this->created)) ? $created->format(DateTime::W3C) : $this->created);
     } else {
         $response = array('errors' => array('Tag does not exist'));
     }
     return $response;
 }
Пример #9
0
 /**
  * Prepare model data for API
  *
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         $response = array('id' => $this->id, 'url' => Ushahidi_Api::url('messages', $this->id), 'parent' => empty($this->parent_id) ? NULL : array('id' => $this->parent_id, 'url' => Ushahidi_Api::url('messages', $this->parent_id)), 'contact' => empty($this->contact_id) ? NULL : $this->contact->for_api(), 'post' => empty($this->post_id) ? NULL : array('id' => $this->post_id, 'url' => Ushahidi_Api::url('posts', $this->post_id)), 'data_provider' => $this->data_provider, 'data_provider_message_id' => $this->data_provider_message_id, 'title' => $this->title, 'message' => $this->message, 'datetime' => ($date = DateTime::createFromFormat('Y-m-d H:i:s', $this->datetime)) ? $date->format(DateTime::W3C) : $this->datetime, 'type' => $this->type, 'status' => $this->status, 'direction' => $this->direction, 'created' => ($created = DateTime::createFromFormat('U', $this->created)) ? $created->format(DateTime::W3C) : $this->created);
     } else {
         $response = array('errors' => array('Message does not exist'));
     }
     return $response;
 }
Пример #10
0
 public function url()
 {
     switch ($this->type) {
         case 'revision':
             return Ushahidi_Api::url('posts/' . $this->parent_id . '/revisions', $this->id);
             break;
         case 'translation':
             return Ushahidi_Api::url('posts/' . $this->parent_id . '/translations', $this->id);
             break;
         case 'report':
         default:
             // @todo maybe put 'updates' url as /post/:parent_id/updates/:id
             return Ushahidi_Api::url('posts', $this->id);
             break;
     }
 }
Пример #11
0
 /**
  * Prepare attribute data for API
  *
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         $response = array('id' => $this->id, 'url' => Ushahidi_Api::url('attributes', $this->id), 'key' => $this->key, 'label' => $this->label, 'input' => $this->input, 'type' => $this->type, 'required' => $this->required ? TRUE : FALSE, 'default' => $this->default, 'priority' => $this->priority, 'options' => $this->options, 'cardinality' => $this->cardinality);
     } else {
         $response = array('errors' => array('Attribute does not exist'));
     }
     return $response;
 }