本文整理匯總了PHP中Incident_Model::get_incidents方法的典型用法代碼示例。如果您正苦於以下問題:PHP Incident_Model::get_incidents方法的具體用法?PHP Incident_Model::get_incidents怎麽用?PHP Incident_Model::get_incidents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Incident_Model
的用法示例。
在下文中一共展示了Incident_Model::get_incidents方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetIncidentsByLimit
/**
* Tests fetching of incidents when the limit parameter is specified
* @test
*/
public function testGetIncidentsByLimit()
{
// Randomly generate the record limit
$limit = rand(1, Incident_Model::get_incidents()->count());
// HTTP GET data
$_GET = array('task' => 'incidents', 'limit' => $limit);
ob_start();
$this->api_controller->index();
$contents = json_decode(ob_get_clean());
$this->assertEquals("0", $contents->error->code);
$this->assertEquals($limit, count($contents->payload->incidents));
}
示例2: _get_report_listing_view
/**
* Helper method to load the report listing view
*/
private function _get_report_listing_view($locale = '')
{
// Check if the local is empty
if (empty($locale)) {
$locale = Kohana::config('locale.language.0');
}
// Load the report listing view
$report_listing = new View('reports_listing');
// Fetch all incidents
$all_incidents = reports::fetch_incidents();
// Pagination
$pagination = new Pagination(array('style' => 'front-end-reports', 'query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => $all_incidents->count()));
// Reports
$incidents = Incident_Model::get_incidents(reports::$params, $pagination);
// Swap out category titles with their proper localizations using an array (cleaner way to do this?)
$localized_categories = array();
foreach ($incidents as $incident) {
$incident = ORM::factory('incident', $incident->incident_id);
foreach ($incident->category as $category) {
$ct = (string) $category->category_title;
if (!isset($localized_categories[$ct])) {
$translated_title = Category_Lang_Model::category_title($category->id, $locale);
$localized_categories[$ct] = $category->category_title;
if ($translated_title) {
$localized_categories[$ct] = $translated_title;
}
}
}
}
// Set the view content
$report_listing->incidents = $incidents;
$report_listing->localized_categories = $localized_categories;
//Set default as not showing pagination. Will change below if necessary.
$report_listing->pagination = "";
// Pagination and Total Num of Report Stats
$plural = $pagination->total_items == 1 ? "" : "s";
// Set the next and previous page numbers
$report_listing->next_page = $pagination->next_page;
$report_listing->previous_page = $pagination->previous_page;
if ($pagination->total_items > 0) {
$current_page = $pagination->sql_offset / $pagination->items_per_page + 1;
$total_pages = ceil($pagination->total_items / $pagination->items_per_page);
if ($total_pages >= 1) {
$report_listing->pagination = $pagination;
// Show the total of report
// @todo This is only specific to the frontend reports theme
$report_listing->stats_breadcrumb = $pagination->current_first_item . '-' . $pagination->current_last_item . ' of ' . $pagination->total_items . ' ' . Kohana::lang('ui_main.reports');
} else {
// If we don't want to show pagination
$report_listing->stats_breadcrumb = $pagination->total_items . ' ' . Kohana::lang('ui_admin.reports');
}
} else {
$report_listing->stats_breadcrumb = '(' . $pagination->total_items . ' report' . $plural . ')';
}
// Return
return $report_listing;
}
示例3: fetch_incidents
//.........這裏部分代碼省略.........
}
/**
* ---------------------------
* NOTES: E.Kala July 13, 2011
* ---------------------------
* Additional checks for date parameters specified in timestamp format
* This only affects those submitted from the main page
*/
// Start Date
if (isset($_GET['s']) and intval($_GET['s']) > 0) {
$start_date = intval($_GET['s']);
array_push(self::$params, 'i.incident_date >= "' . date("Y-m-d H:i:s", $start_date) . '"');
}
// End Date
if (isset($_GET['e']) and intval($_GET['e'])) {
$end_date = intval($_GET['e']);
array_push(self::$params, 'i.incident_date <= "' . date("Y-m-d H:i:s", $end_date) . '"');
}
//
// Check for media type parameter
//
if (isset($url_data['m']) and is_array($url_data['m'])) {
// An array of media filters has been specified
// Validate the media types
$media_types = array();
foreach ($url_data['m'] as $media_type) {
if (intval($media_type) > 0) {
$media_types[] = intval($media_type);
}
}
if (count($media_types) > 0) {
array_push(self::$params, 'i.id IN (SELECT DISTINCT incident_id FROM ' . $table_prefix . 'media WHERE media_type IN (' . implode(",", $media_types) . '))');
}
} elseif (isset($url_data['m']) and !is_array($url_data['m'])) {
// A single media filter has been specified
$media_type = $url_data['m'];
// Sanitization
if (intval($media_type) > 0) {
array_push(self::$params, 'i.id IN (SELECT DISTINCT incident_id FROM ' . $table_prefix . 'media WHERE media_type = ' . $media_type . ')');
}
}
//
// Check if the verification status has been specified
//
if (isset($url_data['v']) and is_array($url_data['v'])) {
$verified_status = array();
foreach ($url_data['v'] as $verified) {
if (intval($verified) >= 0) {
$verified_status[] = intval($verified);
}
}
if (count($verified_status) > 0) {
array_push(self::$params, 'i.incident_verified IN (' . implode(",", $verified_status) . ')');
}
} elseif (isset($url_data['v']) and !is_array($url_data['v']) and intval($url_data) >= 0) {
array_push(self::$param, 'i.incident_verified = ' . intval($url_data['v']));
}
//
// Check if they're filtering over custom form fields
//
if (isset($url_data['cff']) and is_array($url_data['cff'])) {
$where_text = "";
$i = 0;
foreach ($url_data['cff'] as $field) {
$field_id = $field[0];
if (intval($field_id) < 1) {
break;
}
$field_value = $field[1];
if (is_array($field_value)) {
$field_value = implode(",", $field_value);
}
$i++;
if ($i > 1) {
$where_text .= " OR ";
}
$where_text .= "(form_field_id = " . intval($field_id) . " AND form_response = '" . Database::instance()->escape_str(trim($field_value)) . "')";
}
// Make sure there was some valid input in there
if ($i > 0) {
array_push(self::$params, 'i.id IN (SELECT DISTINCT incident_id FROM ' . $table_prefix . 'form_response WHERE ' . $where_text . ')');
}
}
// End of handling cff
// In case a plugin or something wants to get in on the parameter fetching fun
Event::run('ushahidi_filter.fetch_incidents_set_params', self::$params);
//> END PARAMETER FETCH
// Fetch all the incidents
$all_incidents = Incident_Model::get_incidents(self::$params);
if ($paginate) {
// Set up pagination
$page_limit = intval($items_per_page) > 0 ? $items_per_page : intval(Kohana::config('settings.items_per_page'));
$pagination = new Pagination(array('style' => 'front-end-reports', 'query_string' => 'page', 'items_per_page' => $page_limit, 'total_items' => $all_incidents->count()));
// Return paginated results
return Incident_Model::get_incidents(self::$params, $pagination);
} else {
// Return
return $all_incidents;
}
}
示例4: fetch_incidents
//.........這裏部分代碼省略.........
//
if (isset($url_data['m']) and is_array($url_data['m'])) {
// An array of media filters has been specified
// Validate the media types
$media_types = array();
foreach ($url_data['m'] as $media_type) {
if (intval($media_type) > 0) {
$media_types[] = intval($media_type);
}
}
if (count($media_types) > 0) {
array_push(self::$params, 'i.id IN (SELECT DISTINCT incident_id FROM ' . $table_prefix . 'media WHERE media_type IN (' . implode(",", $media_types) . '))');
}
}
//
// Check if the verification status has been specified
//
if (isset($url_data['v']) and is_array($url_data['v'])) {
$verified_status = array();
foreach ($url_data['v'] as $verified) {
if (intval($verified) >= 0) {
$verified_status[] = intval($verified);
}
}
if (count($verified_status) > 0) {
array_push(self::$params, 'i.incident_verified IN (' . implode(",", $verified_status) . ')');
}
}
//
// Check if they're filtering over custom form fields
//
if (isset($url_data['cff']) and is_array($url_data['cff'])) {
$where_text = "";
$i = 0;
foreach ($url_data['cff'] as $field) {
$field_id = $field[0];
if (intval($field_id) < 1) {
continue;
}
$field_value = $field[1];
if (is_array($field_value)) {
$field_value = implode(",", $field_value);
}
$i++;
if ($i > 1) {
$where_text .= " OR ";
}
$where_text .= "(form_field_id = " . intval($field_id) . " AND form_response = '" . Database::instance()->escape_str(trim($field_value)) . "')";
}
// Make sure there was some valid input in there
if ($i > 0) {
// Get the valid IDs - faster in a separate query as opposed
// to a subquery within the main query
$db = new Database();
$rows = $db->query('SELECT DISTINCT incident_id FROM ' . $table_prefix . 'form_response WHERE ' . $where_text);
$incident_ids = '';
foreach ($rows as $row) {
if ($incident_ids != '') {
$incident_ids .= ',';
}
$incident_ids .= $row->incident_id;
}
//make sure there are IDs found
if ($incident_ids != '') {
array_push(self::$params, 'i.id IN (' . $incident_ids . ')');
} else {
array_push(self::$params, 'i.id IN (0)');
}
}
}
// End of handling cff
// In case a plugin or something wants to get in on the parameter fetching fun
Event::run('ushahidi_filter.fetch_incidents_set_params', self::$params);
//> END PARAMETER FETCH
// Check for order and sort params
$order_field = NULL;
$sort = NULL;
$order_options = array('title' => 'i.incident_title', 'date' => 'i.incident_date', 'id' => 'i.id');
if (isset($url_data['order']) and isset($order_options[$url_data['order']])) {
$order_field = $order_options[$url_data['order']];
}
if (isset($url_data['sort'])) {
$sort = strtoupper($url_data['sort']) == 'ASC' ? 'ASC' : 'DESC';
}
if ($paginate) {
// Fetch incident count
$incident_count = Incident_Model::get_incidents(self::$params, false, $order_field, $sort, TRUE);
// Set up pagination
$page_limit = intval($items_per_page) > 0 ? $items_per_page : intval(Kohana::config('settings.items_per_page'));
$total_items = $incident_count->current() ? $incident_count->current()->report_count : 0;
$pagination = new Pagination(array('style' => 'front-end-reports', 'query_string' => 'page', 'items_per_page' => $page_limit, 'total_items' => $total_items));
Event::run('ushahidi_filter.pagination', $pagination);
self::$pagination = $pagination;
// Return paginated results
return Incident_Model::get_incidents(self::$params, self::$pagination, $order_field, $sort);
} else {
// Return
return Incident_Model::get_incidents(self::$params, false, $order_field, $sort);
}
}
示例5: _get_incidents
/**
* Generic function to get reports by given set of parameters
*
* @param string $where SQL where clause
* @param int $limit No. of records to return - set to 20 by default
* @return string XML or JSON string
*/
public function _get_incidents($where = array())
{
// STEP 1.
// Get the incidents
$items = Incident_Model::get_incidents($where, $this->list_limit, $this->order_field, $this->sort);
//No record found.
if ($items->count() == 0) {
return $this->response(4, $this->error_messages);
}
// Records found - proceed
// Set the no. of records returned
$this->record_count = $items->count();
// Will hold the XML/JSON string to return
$ret_json_or_xml = '';
$json_reports = array();
$json_report_media = array();
$json_report_categories = array();
$json_incident_media = array();
$upload_path = str_replace("media/uploads/", "", Kohana::config('upload.relative_directory') . "/");
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->writeElement('domain', $this->domain);
$xml->startElement('incidents');
// Records found, proceed
// Store the incident ids
$incidents_ids = array();
foreach ($items as $item) {
$incident_ids[] = $item->incident_id;
}
//
// STEP 2.
// Fetch the incident categories
//
$this->query = "SELECT c.category_title AS categorytitle, ic.incident_id, " . "c.id AS cid, c.category_image_thumb AS categorythumb, " . "d.decayimage_thumb AS decayimagethumb " . "FROM " . $this->table_prefix . "category AS c " . "INNER JOIN " . $this->table_prefix . "incident_category AS ic ON ic.category_id = c.id " . "LEFT JOIN " . $this->table_prefix . "decayimage as d ON c.id = d.category_id " . "WHERE ic.incident_id IN (" . implode(',', $incident_ids) . ")";
// Execute the query
$incident_categories = $this->db->query($this->query);
// To hold the incident category items
$category_items = array();
// Temporary counter
$i = 1;
// Fetch items into array
foreach ($incident_categories as $incident_category) {
$category_items[$incident_category->incident_id][$i]['cid'] = $incident_category->cid;
$category_items[$incident_category->incident_id][$i]['categorytitle'] = $incident_category->categorytitle;
$category_items[$incident_category->incident_id][$i]['categorythumb'] = $incident_category->categorythumb;
$category_items[$incident_category->incident_id][$i]['decayimagethumb'] = $incident_category->decayimagethumb;
$i++;
}
// Free temporary variables from memory
unset($incident_categories);
//
// STEP 3.
// Fetch the media associated with all the incidents
//
$this->query = "SELECT i.id AS incident_id, m.id AS mediaid, m.media_title AS mediatitle, " . "m.media_type AS mediatype, m.media_link AS medialink, m.media_thumb AS mediathumb " . "FROM " . $this->table_prefix . "media AS m " . "INNER JOIN " . $this->table_prefix . "incident AS i ON i.id = m.incident_id " . "WHERE i.id IN (" . implode(",", $incident_ids) . ")";
$media_items_result = $this->db->query($this->query);
// To store the fetched media items
$media_items = array();
// Reset the temporary counter
$i = 1;
// Fetch items into array
foreach ($media_items_result as $media_item) {
$media_items[$media_item->incident_id][$i]['mediaid'] = $media_item->mediaid;
$media_items[$media_item->incident_id][$i]['mediatitle'] = $media_item->mediatitle;
$media_items[$media_item->incident_id][$i]['mediatype'] = $media_item->mediatype;
$media_items[$media_item->incident_id][$i]['medialink'] = $media_item->medialink;
$media_items[$media_item->incident_id][$i]['mediathumb'] = $media_item->mediathumb;
$i++;
}
// Free temporary variables
unset($media_items_result, $i);
//
// STEP 4.
// Fetch the comments associated with the incidents
//
if ($this->comments) {
$this->query = "SELECT id, incident_id, comment_author, comment_email, " . "comment_description, comment_rating, comment_date " . "FROM " . $this->table_prefix . "comment AS c " . "WHERE c.incident_id IN (" . implode(',', $incident_ids) . ")";
// Execute the query
$incident_comments = $this->db->query($this->query);
// To hold the incident category items
$comment_items = array();
// Temporary counter
$i = 1;
// Fetch items into array
foreach ($incident_comments as $incident_comment) {
$comment_items[$incident_comment->incident_id][$i]['id'] = $incident_comment->id;
$comment_items[$incident_comment->incident_id][$i]['incident_id'] = $incident_comment->incident_id;
$comment_items[$incident_comment->incident_id][$i]['comment_author'] = $incident_comment->comment_author;
$comment_items[$incident_comment->incident_id][$i]['comment_email'] = $incident_comment->comment_email;
//.........這裏部分代碼省略.........
示例6: index
//.........這裏部分代碼省略.........
$update->incident_alert_status = '0';
}
$update->save();
$verify = new Verify_Model();
$verify->incident_id = $item;
$verify->verified_status = '0';
// Record 'Verified By' Action
$verify->user_id = $_SESSION['auth_user']->id;
$verify->verified_date = date("Y-m-d H:i:s", time());
$verify->save();
// Action::report_unapprove - Unapprove a Report
Event::run('ushahidi_action.report_unapprove', $update);
}
}
$form_action = strtoupper(Kohana::lang('ui_admin.unapproved'));
} elseif ($post->action == 'v') {
foreach ($post->incident_id as $item) {
$update = new Incident_Model($item);
$verify = new Verify_Model();
if ($update->loaded == TRUE) {
if ($update->incident_verified == '1') {
$update->incident_verified = '0';
$verify->verified_status = '0';
} else {
$update->incident_verified = '1';
$verify->verified_status = '2';
}
$update->save();
$verify->incident_id = $item;
// Record 'Verified By' Action
$verify->user_id = $_SESSION['auth_user']->id;
$verify->verified_date = date("Y-m-d H:i:s", time());
$verify->save();
}
}
// Set the form action
$form_action = strtoupper(Kohana::lang('ui_admin.verified_unverified'));
} elseif ($post->action == 'd') {
foreach ($post->incident_id as $item) {
$update = new Incident_Model($item);
if ($update->loaded == TRUE) {
$incident_id = $update->id;
$location_id = $update->location_id;
$update->delete();
// Delete Location
ORM::factory('location')->where('id', $location_id)->delete_all();
// Delete Categories
ORM::factory('incident_category')->where('incident_id', $incident_id)->delete_all();
// Delete Translations
ORM::factory('incident_lang')->where('incident_id', $incident_id)->delete_all();
// Delete Photos From Directory
foreach (ORM::factory('media')->where('incident_id', $incident_id)->where('media_type', 1) as $photo) {
deletePhoto($photo->id);
}
// Delete Media
ORM::factory('media')->where('incident_id', $incident_id)->delete_all();
// Delete Sender
ORM::factory('incident_person')->where('incident_id', $incident_id)->delete_all();
// Delete relationship to SMS message
$updatemessage = ORM::factory('message')->where('incident_id', $incident_id)->find();
if ($updatemessage->loaded == TRUE) {
$updatemessage->incident_id = 0;
$updatemessage->save();
}
// Delete Comments
ORM::factory('comment')->where('incident_id', $incident_id)->delete_all();
// Delete form responses
ORM::factory('form_response')->where('incident_id', $incident_id)->delete_all();
// Action::report_delete - Deleted a Report
Event::run('ushahidi_action.report_delete', $incident_id);
}
}
$form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
}
$form_saved = TRUE;
} else {
$form_error = TRUE;
}
}
// Fetch all incidents
$all_incidents = reports::fetch_incidents();
// Pagination
$pagination = new Pagination(array('style' => 'front-end-reports', 'query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => $all_incidents->count()));
Event::run('ushahidi_filter.pagination', $pagination);
// Reports
$incidents = Incident_Model::get_incidents(reports::$params, $pagination);
Event::run('ushahidi_filter.filter_incidents', $incidents);
$this->template->content->countries = Country_Model::get_countries_list();
$this->template->content->incidents = $incidents;
$this->template->content->pagination = $pagination;
$this->template->content->form_error = $form_error;
$this->template->content->form_saved = $form_saved;
$this->template->content->form_action = $form_action;
// Total Reports
$this->template->content->total_items = $pagination->total_items;
// Status Tab
$this->template->content->status = $status;
// Javascript Header
$this->template->js = new View('admin/reports_js');
}
示例7: fetch_incidents
//.........這裏部分代碼省略.........
}
//make sure there are IDs found
if ($incident_ids != '') {
array_push(self::$params, 'i.id IN (' . $incident_ids . ')');
} else {
array_push(self::$params, 'i.id IN (0)');
}
}
}
// End of handling cff
// JP: Check if the reports are being filtered via search.
if (isset($url_data['q']) and is_string($url_data['q'])) {
$filter_search_query = $url_data['q'];
if (!empty($filter_search_query)) {
$search_query = "";
$keyword_string = "";
$where_string = "";
$plus = "";
$or = "";
$search_info = "";
$html = "";
$pagination = "";
// Stop words that we won't search for
// Add words as needed!!
$stop_words = array('the', 'and', 'a', 'to', 'of', 'in', 'i', 'is', 'that', 'it', 'on', 'you', 'this', 'for', 'but', 'with', 'are', 'have', 'be', 'at', 'or', 'as', 'was', 'so', 'if', 'out', 'not');
// Phase 1 - Fetch the search string and perform initial sanitization
$keyword_raw = preg_replace('#/\\w+/#', '', $filter_search_query);
// Phase 2 - Strip the search string of any HTML and PHP tags that may be present for additional safety
$keyword_raw = strip_tags($keyword_raw);
// Phase 3 - Apply Kohana's XSS cleaning mechanism
$keyword_raw = security::xss_clean($keyword_raw);
// Database instance
$db = new Database();
$keywords = explode(' ', $keyword_raw);
if (is_array($keywords) and !empty($keywords)) {
array_change_key_case($keywords, CASE_LOWER);
$i = 0;
foreach ($keywords as $value) {
if (!in_array($value, $stop_words) and !empty($value)) {
// Escape the string for query safety
$chunk = $db->escape_str($value);
if ($i > 0) {
$plus = ' + ';
$or = ' OR ';
}
$where_string = $where_string . $or . "(incident_title LIKE '%{$chunk}%' OR incident_description LIKE '%{$chunk}%')";
$i++;
}
}
if (!empty($keyword_string) and !empty($where_string)) {
// Limit the result set to only those reports that have been approved
$where_string = '(' . $where_string . ') AND incident_active = 1';
$search_query = "SELECT *, (" . $keyword_string . ") AS relevance FROM " . $table_prefix . "incident " . "WHERE " . $where_string . " " . "ORDER BY relevance DESC LIMIT ?, ?";
}
}
$rows = $db->query('SELECT DISTINCT id FROM ' . $table_prefix . 'incident WHERE ' . $where_string);
$incident_ids = '';
foreach ($rows as $row) {
if ($incident_ids != '') {
$incident_ids .= ',';
}
$incident_ids .= $row->id;
}
//make sure there are IDs found
if ($incident_ids != '') {
array_push(self::$params, 'i.id IN (' . $incident_ids . ')');
} else {
array_push(self::$params, 'i.id IN (0)');
}
}
}
// In case a plugin or something wants to get in on the parameter fetching fun
Event::run('ushahidi_filter.fetch_incidents_set_params', self::$params);
//> END PARAMETER FETCH
// Check for order and sort params
$order_field = NULL;
$sort = NULL;
$order_options = array('title' => 'i.incident_title', 'date' => 'i.incident_date', 'id' => 'i.id');
if (isset($url_data['order']) and isset($order_options[$url_data['order']])) {
$order_field = $order_options[$url_data['order']];
}
if (isset($url_data['sort'])) {
$sort = strtoupper($url_data['sort']) == 'ASC' ? 'ASC' : 'DESC';
}
if ($paginate) {
// Fetch incident count
$incident_count = Incident_Model::get_incidents(self::$params, false, $order_field, $sort, TRUE);
// Set up pagination
$page_limit = intval($items_per_page) > 0 ? $items_per_page : intval(Kohana::config('settings.items_per_page'));
$total_items = $incident_count->current() ? $incident_count->current()->report_count : 0;
$pagination = new Pagination(array('style' => 'front-end-reports', 'query_string' => 'page', 'items_per_page' => $page_limit, 'total_items' => $total_items));
Event::run('ushahidi_filter.pagination', $pagination);
self::$pagination = $pagination;
// Return paginated results
return Incident_Model::get_incidents(self::$params, self::$pagination, $order_field, $sort);
} else {
// Return
return Incident_Model::get_incidents(self::$params, false, $order_field, $sort);
}
}
示例8: _get_incidents
/**
* Generic function to get reports by given set of parameters
*
* @param string $where SQL where clause
* @return string XML or JSON string
*/
public function _get_incidents($where = array())
{
// STEP 1.
// Get the incidents
$items = Incident_Model::get_incidents($where, $this->list_limit, $this->order_field, $this->sort);
//No record found.
if ($items->count() == 0) {
return $this->response(4, $this->error_messages);
}
// Records found - proceed
// Set the no. of records returned
$this->record_count = $items->count();
// Will hold the XML/JSON string to return
$ret_json_or_xml = '';
$json_reports = array();
$json_report_media = array();
$json_report_categories = array();
$json_incident_media = array();
$upload_path = str_replace("media/uploads/", "", Kohana::config('upload.relative_directory') . "/");
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->writeElement('domain', $this->domain);
$xml->startElement('incidents');
// Records found, proceed
// Store the incident ids
$incidents_ids = array();
$custom_field_items = array();
foreach ($items as $item) {
$incident_ids[] = $item->incident_id;
$thiscustomfields = customforms::get_custom_form_fields($item->incident_id, null, false, "view");
if (!empty($thiscustomfields)) {
$custom_field_items[$item->incident_id] = $thiscustomfields;
}
}
//
// STEP 2.
// Fetch the incident categories
//
// Execute the query
$incident_categories = ORM::factory('category')->select('category.*, incident_category.incident_id')->join('incident_category', 'category.id', 'incident_category.category_id')->in('incident_category.incident_id', $incident_ids)->find_all();
// To hold the incident category items
$category_items = array();
// Fetch items into array
foreach ($incident_categories as $incident_category) {
$category_items[$incident_category->incident_id][] = $incident_category->as_array();
}
// Free temporary variables from memory
unset($incident_categories);
//
// STEP 3.
// Fetch the media associated with all the incidents
//
$media_items_result = ORM::factory('media')->in('incident_id', $incident_ids)->find_all();
// To store the fetched media items
$media_items = array();
// Fetch items into array
foreach ($media_items_result as $media_item) {
$media_item_array = $media_item->as_array();
if ($media_item->media_type == 1 and !empty($media_item->media_thumb)) {
$media_item_array["media_thumb_url"] = url::convert_uploaded_to_abs($media_item->media_thumb);
$media_item_array["media_link_url"] = url::convert_uploaded_to_abs($media_item->media_link);
}
$media_items[$media_item->incident_id][] = $media_item_array;
}
// Free temporary variables
unset($media_items_result, $media_item_array);
//
// STEP 4.
// Fetch the comments associated with the incidents
//
if ($this->comments) {
// Execute the query
$incident_comments = ORM::factory('comment')->in('incident_id', $incident_ids)->where('comment_spam', 0)->find_all();
// To hold the incident category items
$comment_items = array();
// Fetch items into array
foreach ($incident_comments as $incident_comment) {
$comment_items[$incident_comment->incident_id][] = $incident_comment->as_array();
}
// Free temporary variables from memory
unset($incident_comments);
}
//
// STEP 5.
// Return XML
//
foreach ($items as $item) {
// Build xml file
$xml->startElement('incident');
$xml->writeElement('id', $item->incident_id);
//.........這裏部分代碼省略.........
示例9: index
//.........這裏部分代碼省略.........
if ($update->loaded == TRUE) {
$update->incident_active = $update->incident_active == 0 ? '1' : '0';
// Tag this as a report that needs to be sent out as an alert
if ($update->incident_alert_status != '2') {
// 2 = report that has had an alert sent
$update->incident_alert_status = '1';
}
$update->save();
$verify = new Verify_Model();
$verify->incident_id = $item;
$verify->verified_status = '1';
// Record 'Verified By' Action
$verify->user_id = $_SESSION['auth_user']->id;
$verify->verified_date = date("Y-m-d H:i:s", time());
$verify->save();
// Action::report_approve - Approve a Report
Event::run('ushahidi_action.report_approve', $update);
}
}
$form_action = strtoupper(Kohana::lang('ui_admin.approved'));
}
} elseif ($post->action == 'u') {
foreach ($post->incident_id as $item) {
$update = new Incident_Model($item);
if ($update->loaded == TRUE) {
$update->incident_active = '0';
// If Alert hasn't been sent yet, disable it
if ($update->incident_alert_status == '1') {
$update->incident_alert_status = '0';
}
$update->save();
$verify = new Verify_Model();
$verify->incident_id = $item;
$verify->verified_status = '0';
// Record 'Verified By' Action
$verify->user_id = $_SESSION['auth_user']->id;
$verify->verified_date = date("Y-m-d H:i:s", time());
$verify->save();
// Action::report_unapprove - Unapprove a Report
Event::run('ushahidi_action.report_unapprove', $update);
}
}
$form_action = strtoupper(Kohana::lang('ui_admin.unapproved'));
} elseif ($post->action == 'v') {
foreach ($post->incident_id as $item) {
$update = new Incident_Model($item);
$verify = new Verify_Model();
if ($update->loaded == TRUE) {
if ($update->incident_verified == '1') {
$update->incident_verified = '0';
$verify->verified_status = '0';
} else {
$update->incident_verified = '1';
$verify->verified_status = '2';
}
$update->save();
$verify->incident_id = $item;
// Record 'Verified By' Action
$verify->user_id = $_SESSION['auth_user']->id;
$verify->verified_date = date("Y-m-d H:i:s", time());
$verify->save();
}
}
// Set the form action
$form_action = strtoupper(Kohana::lang('ui_admin.verified_unverified'));
} elseif ($post->action == 'd') {
foreach ($post->incident_id as $item) {
$update = new Incident_Model($item);
if ($update->loaded) {
$update->delete();
}
}
$form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
}
$form_saved = TRUE;
} else {
$form_error = TRUE;
}
}
// Fetch all incidents
$all_incidents = reports::fetch_incidents();
// Pagination
$pagination = new Pagination(array('style' => 'front-end-reports', 'query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => $all_incidents->count()));
Event::run('ushahidi_filter.pagination', $pagination);
// Reports
$incidents = Incident_Model::get_incidents(reports::$params, $pagination);
Event::run('ushahidi_filter.filter_incidents', $incidents);
$this->template->content->countries = Country_Model::get_countries_list();
$this->template->content->incidents = $incidents;
$this->template->content->pagination = $pagination;
$this->template->content->form_error = $form_error;
$this->template->content->form_saved = $form_saved;
$this->template->content->form_action = $form_action;
// Total Reports
$this->template->content->total_items = $pagination->total_items;
// Status Tab
$this->template->content->status = $status;
// Javascript Header
$this->template->js = new View('admin/reports_js');
}
示例10: _get_report_listing_view
/**
* Helper method to load the report listing view
*/
private function _get_report_listing_view($locale = '')
{
// Check if the local is empty
if (empty($locale)) {
$locale = Kohana::config('locale.language.0');
}
// Load the report listing view
$report_listing = new View('reports_listing');
// Fetch all incidents
$all_incidents = reports::fetch_incidents();
// Reports
$incidents = Incident_Model::get_incidents(reports::$params);
// Swap out category titles with their proper localizations using an array (cleaner way to do this?)
$localized_categories = array();
foreach ($incidents as $incident) {
$incident = ORM::factory('incident', $incident->incident_id);
foreach ($incident->category as $category) {
$ct = (string) $category->category_title;
if (!isset($localized_categories[$ct])) {
$localized_categories[$ct] = Category_Lang_Model::category_title($category->id, $locale);
}
}
}
// Set the view content
$report_listing->incidents = $incidents;
$report_listing->localized_categories = $localized_categories;
//Set default as not showing pagination. Will change below if necessary.
$report_listing->pagination = "";
// Pagination and Total Num of Report Stats
$plural = count($incidents) > 1 ? "" : "s";
$report_listing->stats_breadcrumb = count($incidents) . ' ' . Kohana::lang('ui_admin.reports') . $plural;
// Return
return $report_listing;
}