/** * Generate GEOJSON from incidents * * @param ORM_Iterator|Database_Result|array $incidents collection of incidents * @param int $category_id * @param string $color * @param string $icon * @return array $json_features geojson features array **/ protected function markers_geojson($incidents, $category_id, $color, $icon, $include_geometries = TRUE) { $json_features = array(); // Extra params for markers only // Get the incidentid (to be added as first marker) $first_incident_id = (isset($_GET['i']) and intval($_GET['i']) > 0) ? intval($_GET['i']) : 0; $media_type = (isset($_GET['m']) and intval($_GET['m']) > 0) ? intval($_GET['m']) : 0; foreach ($incidents as $marker) { // Handle both reports::fetch_incidents() response and actual ORM objects $marker->id = isset($marker->incident_id) ? $marker->incident_id : $marker->id; if (isset($marker->latitude) and isset($marker->longitude)) { $latitude = $marker->latitude; $longitude = $marker->longitude; } elseif (isset($marker->location) and isset($marker->location->latitude) and isset($marker->location->longitude)) { $latitude = $marker->location->latitude; $longitude = $marker->location->longitude; } else { // No location - skip this report continue; } // Get thumbnail $thumb = ""; $media = ORM::factory('incident', $marker->id)->media; if ($media->count()) { foreach ($media as $photo) { if ($photo->media_thumb) { // Get the first thumb $thumb = url::convert_uploaded_to_abs($photo->media_thumb); break; } } } // Get URL from object, fallback to Incident_Model::get() if object doesn't have url or url() if (method_exists($marker, 'url')) { $link = $marker->url(); } elseif (isset($marker->url)) { $link = $marker->url; } else { $link = Incident_Model::get_url($marker); } $item_name = $this->get_title($marker->incident_title, $link); $json_item = array(); $json_item['type'] = 'Feature'; $json_item['properties'] = array('id' => $marker->id, 'name' => $item_name, 'link' => $link, 'category' => array($category_id), 'color' => $color, 'icon' => $icon, 'thumb' => $thumb, 'timestamp' => strtotime($marker->incident_date), 'count' => 1, 'class' => get_class($marker), 'title' => $marker->incident_title); $json_item['geometry'] = array('type' => 'Point', 'coordinates' => array($longitude, $latitude)); if ($marker->id == $first_incident_id) { array_unshift($json_features, $json_item); } else { array_push($json_features, $json_item); } // Get Incident Geometries if ($include_geometries) { $geometry = $this->get_geometry($marker->id, $marker->incident_title, $marker->incident_date, $link); if (count($geometry)) { foreach ($geometry as $g) { array_push($json_features, $g); } } } } Event::run('ushahidi_filter.json_index_features', $json_features); return $json_features; }
</td> </tr> </table> </div> <!-- /Top reportbox section--> <!-- Report listing --> <div class="r_cat_tooltip"><a href="#" class="r-3"></a></div> <div class="rb_list-and-map-box"> <div id="rb_list-view"> <?php foreach ($incidents as $incident) { $incident_id = $incident->incident_id; $incident_title = strip_tags($incident->incident_title); $incident_description = strip_tags($incident->incident_description); $incident_url = Incident_Model::get_url($incident_id); //$incident_category = $incident->incident_category; // Trim to 150 characters without cutting words // XXX: Perhaps delcare 150 as constant $incident_description = text::limit_chars(strip_tags($incident_description), 140, "...", true); $incident_date = date('H:i M d, Y', strtotime($incident->incident_date)); //$incident_time = date('H:i', strtotime($incident->incident_date)); $location_id = $incident->location_id; $location_name = $incident->location_name; $comment_count = ORM::Factory('comment')->where('incident_id', $incident_id)->count_all(); $incident_thumb = url::file_loc('img') . "media/img/report-thumb-default.jpg"; $media = ORM::Factory('media')->where('incident_id', $incident_id)->find_all(); if ($media->count()) { foreach ($media as $photo) { if ($photo->media_thumb) { // Get the first thumb
/** * Generate GEOJSON from incidents * * @param ORM_Iterator|Database_Result|array $incidents collection of incidents * @param int $category_id * @param string $color * @param string $icon * @return array $json_features geojson features array **/ protected function markers_geojson($incidents, $category_id, $color, $icon, $include_geometries = TRUE) { $json_features = array(); // Extra params for markers only // Get the incidentid (to be added as first marker) $first_incident_id = (isset($_GET['i']) and intval($_GET['i']) > 0) ? intval($_GET['i']) : 0; $media_type = (isset($_GET['m']) and intval($_GET['m']) > 0) ? intval($_GET['m']) : 0; $incident_model = new Incident_Model(); $all_categories = $incident_model::get_active_categories(); foreach ($incidents as $marker) { // Handle both reports::fetch_incidents() response and actual ORM objects $marker->id = isset($marker->incident_id) ? $marker->incident_id : $marker->id; if (isset($marker->latitude) and isset($marker->longitude)) { $latitude = $marker->latitude; $longitude = $marker->longitude; } elseif (isset($marker->location) and isset($marker->location->latitude) and isset($marker->location->longitude)) { $latitude = $marker->location->latitude; $longitude = $marker->location->longitude; } else { // No location - skip this report continue; } // Get thumbnail $thumb = ""; $media = ORM::factory('incident', $marker->id)->media; //Invisible Cities customisation //Requires to uncluster markers and present them in their category color // get category for incident, we only visualise the first category present in the incident - gotcha but ok $incident_category_result = ORM::factory('incident_category')->where(array('incident_id' => $marker->id))->find(); if (array_key_exists($incident_category_result->category_id, $all_categories)) { //get category details $category_details = $all_categories[$incident_category_result->category_id]; //get the color $color = $category_details[1]; } //code for debugging // $categories = array(); // foreach ($incident_categories_result as $category) { // // $category_details = ORM::factory('category', $category->category_id); // $category_details = $all_categories[$category->category_id]; // $color = $category_details[1]; // array_push($categories, array( // 'category_id' => $category->category_id, // 'color' => $category_details[1] // )); // } if ($media->count()) { foreach ($media as $photo) { if ($photo->media_thumb) { // Get the first thumb $thumb = url::convert_uploaded_to_abs($photo->media_thumb); break; } } } // Get URL from object, fallback to Incident_Model::get() if object doesn't have url or url() if (method_exists($marker, 'url')) { $link = $marker->url(); } elseif (isset($marker->url)) { $link = $marker->url; } else { $link = Incident_Model::get_url($marker); } $item_name = $this->get_title($marker->incident_title, $link); $json_item = array(); $json_item['type'] = 'Feature'; $json_item['properties'] = array('id' => $marker->id, 'name' => $item_name, 'link' => $link, 'category' => array($category_id), 'color' => $color, 'icon' => $icon, 'thumb' => $thumb, 'timestamp' => strtotime($marker->incident_date), 'count' => 1, 'class' => get_class($marker), 'title' => $marker->incident_title); $json_item['geometry'] = array('type' => 'Point', 'coordinates' => array((double) $longitude, (double) $latitude)); if ($marker->id == $first_incident_id) { array_unshift($json_features, $json_item); } else { array_push($json_features, $json_item); } // Get Incident Geometries if ($include_geometries) { $geometry = $this->get_geometry($marker->id, $marker->incident_title, $marker->incident_date, $link); if (count($geometry)) { foreach ($geometry as $g) { array_push($json_features, $g); } } } } Event::run('ushahidi_filter.json_index_features', $json_features); return $json_features; }