本文整理匯總了PHP中Incident_Model類的典型用法代碼示例。如果您正苦於以下問題:PHP Incident_Model類的具體用法?PHP Incident_Model怎麽用?PHP Incident_Model使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Incident_Model類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: add_reports
/**
* Adds reports in JSON format to the database
* @param string $data - CF JSON results
*/
private function add_reports($data)
{
$reports = json_decode($data, false);
foreach ($reports as $report) {
//Save the Report location
$location = new Location_Model();
$location->longitude = $report->{'longitude'};
$location->latitude = $report->{'latitude'};
$location->location_name = $report->{'location_city'};
$location->save();
// Save CF result as Report
$incident = new Incident_Model();
$incident->location_id = $location->id;
// $incident->id = $report->{'id'};
$incident->incident_title = date("Y-m-d H:i:s", time());
$incident->incident_description = $report->{'sms_text'};
$incident->incident_date = date("Y-m-d H:i:s", time());
$incident->incident_dateadd = date("Y-m-d H:i:s", time());
$incident->incident_active = 1;
$incident->incident_verified = 1;
$incident->save();
// Save Incident Category
$categories = explode(",", $report->{'categories'});
foreach ($categories as $category) {
$report_category_id = ORM::factory("category")->where("category_title", $category)->find();
if ($report_category_id->loaded) {
$incident_category = new Incident_Category_Model();
$incident_category->incident_id = $incident->id;
$incident_category->category_id = $report_category_id->id;
$incident_category->save();
}
}
}
}
示例2: index
function index()
{
$this->template->content = new View('admin/dashboard');
$this->template->content->title = Kohana::lang('ui_admin.dashboard');
$this->template->this_page = 'dashboard';
// Retrieve Dashboard Count...
// Total Reports
$this->template->content->reports_total = ORM::factory('incident')->count_all();
// Total Unapproved Reports
$this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->count_all();
// Total Unverified Reports
$this->template->content->reports_unverified = ORM::factory('incident')->where('incident_verified', '0')->count_all();
// Total Categories
$this->template->content->categories = ORM::factory('category')->count_all();
// Total Locations
$this->template->content->locations = ORM::factory('location')->count_all();
// Total Incoming Media
$this->template->content->incoming_media = ORM::factory('feed_item')->count_all();
// Messages By Service
$total_message_count = 0;
$message_services = array();
$services = ORM::factory('service')->find_all();
foreach ($services as $service) {
$message_count = ORM::factory('message')->join('reporter', 'message.reporter_id', 'reporter.id')->where('service_id', $service->id)->where('message_type', '1')->count_all();
$message_services[] = array('id' => $service->id, 'name' => $service->service_name, 'count' => $message_count);
$total_message_count += $message_count;
}
$this->template->content->message_services = $message_services;
// Total Messages
$this->template->content->message_count = $total_message_count;
// Get reports for display
$incidents = ORM::factory('incident')->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
$this->template->content->incidents = $incidents;
// Get Incoming Media (We'll Use NewsFeeds for now)
$this->template->content->feeds = ORM::factory('feed_item')->limit('3')->orderby('item_date', 'desc')->find_all();
/*
// Javascript Header
$this->template->flot_enabled = TRUE;
$this->template->js = new View('admin/dashboard_js');
// Graph
$this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL',NULL,NULL,'all');
$this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
*/
// Javascript Header
$this->template->protochart_enabled = TRUE;
$this->template->js = new View('admin/stats_js');
$this->template->content->failure = '';
// Build dashboard chart
// Set the date range (how many days in the past from today?)
// default to one year
$range = isset($_GET['range']) ? $_GET['range'] : 365;
if (isset($_GET['range']) and $_GET['range'] == 0) {
$range = NULL;
}
$this->template->content->range = $range;
$incident_data = Incident_Model::get_number_reports_by_date($range);
$data = array('Reports' => $incident_data);
$options = array('xaxis' => array('mode' => '"time"'));
$this->template->content->report_chart = protochart::chart('report_chart', $data, $options, array('Reports' => 'CC0000'), 410, 310);
}
示例3: index
function index()
{
$this->template->content = new View('members/dashboard');
$this->template->content->title = Kohana::lang('ui_admin.dashboard');
$this->template->this_page = 'dashboard';
// User
$this->template->content->user = $this->user;
// User Reputation Score
$this->template->content->reputation = reputation::calculate($this->user->id);
// Get Badges
$this->template->content->badges = Badge_Model::users_badges($this->user->id);
// Retrieve Dashboard Counts...
// Total Reports
$this->template->content->reports_total = ORM::factory('incident')->where("user_id", $this->user->id)->count_all();
// Total Unapproved Reports
$this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->where("user_id", $this->user->id)->count_all();
// Total Checkins
$this->template->content->checkins = ORM::factory('checkin')->where("user_id", $this->user->id)->count_all();
// Total Alerts
$this->template->content->alerts = ORM::factory('alert')->where("user_id", $this->user->id)->count_all();
// Total Votes
$this->template->content->votes = ORM::factory('rating')->where("user_id", $this->user->id)->count_all();
// Total Votes Positive
$this->template->content->votes_up = ORM::factory('rating')->where("user_id", $this->user->id)->where("rating", "1")->count_all();
// Total Votes Negative
$this->template->content->votes_down = ORM::factory('rating')->where("user_id", $this->user->id)->where("rating", "-1")->count_all();
// Get reports for display
$this->template->content->incidents = ORM::factory('incident')->where("user_id", $this->user->id)->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
// To support the "welcome" or "not enough info on user" form
if ($this->user->public_profile == 1) {
$this->template->content->profile_public = TRUE;
$this->template->content->profile_private = FALSE;
} else {
$this->template->content->profile_public = FALSE;
$this->template->content->profile_private = TRUE;
}
$this->template->content->hidden_welcome_fields = array('email' => $this->user->email, 'notify' => $this->user->notify, 'color' => $this->user->color, 'password' => '', 'needinfo' => 0);
/*
// Javascript Header
$this->template->flot_enabled = TRUE;
$this->template->js = new View('admin/dashboard_js');
// Graph
$this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL',NULL,NULL,'all');
$this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
*/
// Javascript Header
$this->template->protochart_enabled = TRUE;
$this->template->js = new View('admin/stats_js');
$this->template->content->failure = '';
// Build dashboard chart
// Set the date range (how many days in the past from today?)
// Default to one year if invalid or not set
$range = (isset($_GET['range']) and preg_match('/^\\d+$/', $_GET['range']) > 0) ? (int) $_GET['range'] : 365;
// Phase 3 - Invoke Kohana's XSS cleaning mechanism just incase an outlier wasn't caught
$range = $this->input->xss_clean($range);
$incident_data = Incident_Model::get_number_reports_by_date($range, $this->user->id);
$data = array('Reports' => $incident_data);
$options = array('xaxis' => array('mode' => '"time"'));
$this->template->content->report_chart = protochart::chart('report_chart', $data, $options, array('Reports' => 'CC0000'), 410, 310);
}
示例4: testIsValidIncident
/**
* Tests Incident_Model::is_valid_incident
* @test
*/
public function testIsValidIncident()
{
// Get any incident
$random_incident = testutils::get_random_id('incident');
$inactive_incident = testutils::get_random_id('incident', 'WHERE incident_active = 0');
$active_incident = testutils::get_random_id('incident', 'WHERE incident_active = 1');
//Test to see if there are data in the incident table to test with.
if (empty($random_incident)) {
$this->markTestSkipped('The incident table is empty.');
} elseif (empty($inactive_incident)) {
$this->markTestSkipped('No inactive incidents in incident table.');
} elseif (empty($active_incident)) {
$this->markTestSkipped('No active incidents in incident table.');
} else {
$this->assertEquals(TRUE, Incident_Model::is_valid_incident($random_incident, FALSE));
// Get inactive incident
$inactive_incident = testutils::get_random_id('incident', 'WHERE incident_active = 0');
// Check fails with default args and explicitly limit to active only
$this->assertEquals(FALSE, Incident_Model::is_valid_incident($inactive_incident));
$this->assertEquals(FALSE, Incident_Model::is_valid_incident($inactive_incident, TRUE));
// Check success when including inactive incidents
$this->assertEquals(TRUE, Incident_Model::is_valid_incident($inactive_incident, FALSE));
// Get active incident
$active_incident = testutils::get_random_id('incident', 'WHERE incident_active = 1');
// Check success with default args and explicitly limit to active only
$this->assertEquals(TRUE, Incident_Model::is_valid_incident($active_incident));
$this->assertEquals(TRUE, Incident_Model::is_valid_incident($active_incident, TRUE));
// Null incident value
$this->assertEquals(FALSE, Incident_Model::is_valid_incident(NULL));
// Non numeric incident value
$this->assertEquals(FALSE, Incident_Model::is_valid_incident('0.999'));
}
}
示例5: 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));
}
示例6: index
function index()
{
$this->template->content = new View('admin/dashboard');
$this->template->content->title = 'Dashboard';
$this->template->this_page = 'dashboard';
// $this->template->header = new View('header');
// Retrieve Dashboard Count...
// Total Reports
$this->template->content->reports_total = ORM::factory('incident')->count_all();
// Total Unapproved Reports
$this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->count_all();
// Total Unverified Reports
$this->template->content->reports_unverified = ORM::factory('incident')->where('incident_verified', '0')->count_all();
// Total Categories
$this->template->content->categories = ORM::factory('category')->count_all();
// Total Locations
$this->template->content->locations = ORM::factory('location')->count_all();
// Total Incoming Media
$this->template->content->incoming_media = ORM::factory('feed_item')->count_all();
// Messages By Service
$total_message_count = 0;
$message_services = array();
$services = ORM::factory('service')->find_all();
foreach ($services as $service) {
$message_count = ORM::factory('message')->join('reporter', 'message.reporter_id', 'reporter.id')->where('service_id', $service->id)->where('message_type', '1')->count_all();
$message_services[] = array('id' => $service->id, 'name' => $service->service_name, 'count' => $message_count);
$total_message_count += $message_count;
}
$this->template->content->message_services = $message_services;
// Total Messages
$this->template->content->message_count = $total_message_count;
// Get reports for display
$incidents = ORM::factory('incident')->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
$this->template->content->incidents = $incidents;
// Get Incoming Media (We'll Use NewsFeeds for now)
$this->template->content->feeds = ORM::factory('feed_item')->limit('3')->orderby('item_date', 'desc')->find_all();
// Javascript Header
$this->template->flot_enabled = TRUE;
$this->template->js = new View('admin/dashboard_js');
// Graph
$this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL', NULL, NULL, 'all');
$this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
}
示例7: testIsValidIncident
/**
* Tests Incident_Model::is_valid_incident
* @test
*/
public function testIsValidIncident()
{
// Get any incident
$random_incident = testutils::get_random_id('incident');
//Test to see if there are data in the incident table to test with.
if (empty($random_incident)) {
$this->markTestSkipped('The incident table is empty.');
} else {
$this->assertEquals(TRUE, Incident_Model::is_valid_incident($random_incident));
// Get inactive incident
$inactive_incident = testutils::get_random_id('incident', 'WHERE incident_active = 0');
$this->assertEquals(FALSE, Incident_Model::is_valid_incident($inactive_incident, TRUE));
// Get active incident
$active_incident = testutils::get_random_id('incident', 'WHERE incident_active = 1');
$this->assertEquals(TRUE, Incident_Model::is_valid_incident($active_incident, TRUE));
// Null incident value
$this->assertEquals(FALSE, Incident_Model::is_valid_incident(NULL));
// Non numeric incident value
$this->assertEquals(FALSE, Incident_Model::is_valid_incident('0.999'));
}
}
示例8: get_custom_form_fields
/**
* Retrieve Custom Form Fields
* @param bool|int $incident_id The unique incident_id of the original report
* @param int $form_id The unique form_id. Uses default form (1), if none selected
* @param bool $field_names_only Whether or not to include just fields names, or field names + data
* @param bool $data_only Whether or not to include just data
* @param string $action If this is being used to grab fields for submit or view of data
*/
public static function get_custom_form_fields($incident_id = FALSE, $form_id = 1, $data_only = FALSE, $action = "submit")
{
$fields_array = array();
if (!$form_id) {
$form_id = 1;
}
// Validation
if (!Form_Model::is_valid_form($form_id)) {
return $fields_array;
}
// Database table prefix
$table_prefix = Kohana::config('database.default.table_prefix');
//NOTE will probably need to add a user_level variable for non-web based requests
$user_level = self::get_user_max_auth();
// Get the predicates for the public state
$public_state = $action == "view" ? '<=' . $user_level : ' <= ' . $user_level;
// Query to fetch the form fields and their responses
$sql = "SELECT ff.*, '' AS form_response FROM " . $table_prefix . "form_field ff WHERE 1=1 ";
// Check if the provided incident exists
if (Incident_Model::is_valid_incident($incident_id)) {
// Overwrite the previous query
$sql = "SELECT ff.*, fr.form_response " . "FROM " . $table_prefix . "form_field ff " . "RIGHT JOIN " . $table_prefix . "form_response fr ON (fr.form_field_id = ff.id) " . "WHERE fr.incident_id = " . $incident_id . " ";
}
$sql .= "AND ff.form_id = " . $form_id . " " . "AND ff.field_ispublic_visible " . $public_state . " " . "ORDER BY ff.field_position ASC";
// Execute the SQL to fetch the custom form fields
$form_fields = Database::instance()->query($sql);
foreach ($form_fields as $custom_formfield) {
if ($data_only) {
// Return Data Only
$fields_array[$custom_formfield->id] = $custom_formfield->form_response;
} else {
// Return Field Structure
$fields_array[$custom_formfield->id] = array('field_id' => $custom_formfield->id, 'field_name' => $custom_formfield->field_name, 'field_type' => $custom_formfield->field_type, 'field_default' => $custom_formfield->field_default, 'field_required' => $custom_formfield->field_required, 'field_maxlength' => $custom_formfield->field_maxlength, 'field_height' => $custom_formfield->field_height, 'field_width' => $custom_formfield->field_width, 'field_isdate' => $custom_formfield->field_isdate, 'field_ispublic_visible' => $custom_formfield->field_ispublic_visible, 'field_ispublic_submit' => $custom_formfield->field_ispublic_submit, 'field_response' => $custom_formfield->form_response);
}
}
// Garbage collection
unset($form_fields);
// Return
return $fields_array;
}
示例9: get_custom_form_fields
/**
* Retrieve Custom Form Fields
* @param bool|int $incident_id The unique incident_id of the original report
* @param int $form_id The unique form_id. If none selected, retrieve custom form fields from ALL custom forms
* @param bool $data_only Whether or not to include just data
* @param string $action If this is being used to grab fields for submit or view of data
*/
public static function get_custom_form_fields($incident_id = FALSE, $form_id = NULL, $data_only = FALSE, $action = "submit")
{
$fields_array = array();
// If we have a form id but its invalid, return empty
if (!empty($form_id) and !Form_Model::is_valid_form($form_id)) {
return $fields_array;
}
// Database table prefix
$table_prefix = Kohana::config('database.default.table_prefix');
// Get field we'll check permissions against
$ispublic_field = $action == "view" ? 'field_ispublic_visible' : 'field_ispublic_submit';
// NOTE will probably need to add a user_level variable for non-web based requests
$user_level = self::get_user_max_auth();
// Check if incident is valid
// Have to do this early since we can't build 2 ORM queries at once.
$valid_incident = Incident_Model::is_valid_incident($incident_id, FALSE);
// Check if the provided incident exists, then fill in the data
if ($valid_incident) {
$sql = "SELECT ff.*, fr.form_response\n\t\t\tFROM `{$table_prefix}form_field` ff\n\t\t\tLEFT JOIN `{$table_prefix}roles` r ON (r.id = {$ispublic_field})\n\t\t\tLEFT JOIN\n\t\t\t\t`{$table_prefix}form_response` fr ON (\n\t\t\t\t\tfr.form_field_id = ff.id AND\n\t\t\t\t\tfr.incident_id = :incident_id\n\t\t\t\t)\n\t\t\tWHERE (access_level <= :user_level OR access_level IS NULL) " . (!empty($form_id) ? "AND form_id = :form_id " : '') . "ORDER BY field_position ASC";
} else {
$sql = "SELECT ff.*\n\t\t\tFROM `{$table_prefix}form_field` ff\n\t\t\tLEFT JOIN `{$table_prefix}roles` r ON (r.id = {$ispublic_field})\n\t\t\tWHERE (access_level <= :user_level OR access_level IS NULL) " . (!empty($form_id) ? "AND form_id = :form_id " : '') . "ORDER BY field_position ASC";
}
$form_fields = Database::instance()->query($sql, array(':form_id' => $form_id, ':user_level' => $user_level, ':incident_id' => $incident_id));
foreach ($form_fields as $custom_formfield) {
if ($data_only) {
// Return Data Only
$fields_array[$custom_formfield->id] = isset($custom_formfield->form_response) ? $custom_formfield->form_response : '';
} else {
// Return Field Structure
// JP: added field description
$fields_array[$custom_formfield->id] = array('field_id' => $custom_formfield->id, 'form_id' => $custom_formfield->form_id, 'field_name' => $custom_formfield->field_name, 'field_description' => $custom_formfield->field_description, 'field_type' => $custom_formfield->field_type, 'field_default' => $custom_formfield->field_default, 'field_required' => $custom_formfield->field_required, 'field_maxlength' => $custom_formfield->field_maxlength, 'field_height' => $custom_formfield->field_height, 'field_width' => $custom_formfield->field_width, 'field_isdate' => $custom_formfield->field_isdate, 'field_ispublic_visible' => $custom_formfield->field_ispublic_visible, 'field_ispublic_submit' => $custom_formfield->field_ispublic_submit, 'field_response' => isset($custom_formfield->form_response) ? $custom_formfield->form_response : '');
}
}
// Garbage collection
unset($form_fields);
// Return
return $fields_array;
}
示例10: index
function index()
{
$this->template->content = new View('admin/dashboard');
$this->template->content->title = 'Dashboard';
$this->template->this_page = 'dashboard';
// $this->template->header = new View('header');
// Retrieve Dashboard Count...
// Total Reports
$this->template->content->reports_total = ORM::factory('incident')->count_all();
// Total Unapproved Reports
$this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->count_all();
// Total Unverified Reports
$this->template->content->reports_unverified = ORM::factory('incident')->where('incident_verified', '0')->count_all();
// Total Categories
$this->template->content->categories = ORM::factory('category')->count_all();
// Total Locations
$this->template->content->locations = ORM::factory('location')->count_all();
// Total Incoming Media
$this->template->content->incoming_media = ORM::factory('feed_item')->count_all();
// Total SMS Messages
$this->template->content->message_sms_count = ORM::factory('message')->count_all();
// Total Twitter Messages
$this->template->content->message_twitter_count = ORM::factory('twitter')->where('hide', 0)->count_all();
// Total Message Count
$this->template->content->message_count = $this->template->content->message_twitter_count + $this->template->content->message_sms_count;
// Get reports for display
$incidents = ORM::factory('incident')->limit(3)->orderby('incident_dateadd', 'desc')->find_all();
$this->template->content->incidents = $incidents;
// Get Incoming Media (We'll Use NewsFeeds for now)
$this->template->content->feeds = ORM::factory('feed_item')->limit('3')->orderby('item_date', 'desc')->find_all();
// Javascript Header
$this->template->flot_enabled = TRUE;
$this->template->js = new View('admin/dashboard_js');
// Graph
$this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL', NULL, NULL, 'all');
$this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
}
示例11: add_hash_tweets
/**
* Adds hash tweets in JSON format to the database and saves the sender as a new
* Reporter if they don't already exist
* @param string $data - Twitter JSON results
*/
private function add_hash_tweets($data)
{
if ($this->_lock()) {
return false;
}
$services = new Service_Model();
$service = $services->where('service_name', 'Twitter')->find();
if (!$service) {
$this->_unlock();
return false;
}
$tweets = json_decode($data, false);
if (!$tweets) {
$this->_unlock();
return false;
}
if (isset($tweets->{'error'})) {
$this->_unlock();
return false;
}
$tweet_results = $tweets->{'results'};
foreach ($tweet_results as $tweet) {
$reporter = ORM::factory('reporter')->where('service_id', $service->id)->where('service_account', $tweet->{'from_user'})->find();
if (!$reporter->loaded) {
// get default reporter level (Untrusted)
$level = ORM::factory('level')->where('level_weight', 0)->find();
$reporter->service_id = $service->id;
$reporter->level_id = $level->id;
$reporter->service_account = $tweet->{'from_user'};
$reporter->reporter_first = null;
$reporter->reporter_last = null;
$reporter->reporter_email = null;
$reporter->reporter_phone = null;
$reporter->reporter_ip = null;
$reporter->reporter_date = date('Y-m-d');
$reporter->save();
}
if ($reporter->level_id > 1 && count(ORM::factory("message")->where("service_messageid = '" . $tweet->{'id_str'} . "'")->find_all()) == 0) {
// Grab geo data if it exists from the tweet
$tweet_lat = null;
$tweet_lon = null;
if ($tweet->{'geo'} != null) {
$tweet_lat = $tweet->{'geo'}->coordinates[0];
$tweet_lon = $tweet->{'geo'}->coordinates[1];
}
// Save Tweet as Message
$message = new Message_Model();
$message->parent_id = 0;
$message->incident_id = 0;
$message->user_id = 0;
$message->reporter_id = $reporter->id;
$message->message_from = $tweet->{'from_user'};
$message->message_to = null;
$message->message = $tweet->{'text'};
$message->message_type = 1;
// Inbox
$tweet_date = date("Y-m-d H:i:s", strtotime($tweet->{'created_at'}));
$message->message_date = $tweet_date;
$message->service_messageid = $tweet->{'id_str'};
$message->latitude = $tweet_lat;
$message->longitude = $tweet_lon;
$message->save();
// Action::message_twitter_add - Twitter Message Received!
Event::run('ushahidi_action.message_twitter_add', $message);
// Auto-Create A Report if Reporter is Trusted
$reporter_weight = $reporter->level->level_weight;
$reporter_location = $reporter->location;
if ($reporter_weight > 0 and $reporter_location) {
$incident_title = text::limit_chars($message->message, 50, "...", false);
// Create Incident
$incident = new Incident_Model();
$incident->location_id = $reporter_location->id;
$incident->incident_title = $incident_title;
$incident->incident_description = $message->message;
$incident->incident_date = $tweet_date;
$incident->incident_dateadd = date("Y-m-d H:i:s", time());
$incident->incident_active = 1;
if ($reporter_weight == 2) {
$incident->incident_verified = 1;
}
$incident->save();
// Update Message with Incident ID
$message->incident_id = $incident->id;
$message->save();
// Save Incident Category
$trusted_categories = ORM::factory("category")->where("category_trusted", 1)->find();
if ($trusted_categories->loaded) {
$incident_category = new Incident_Category_Model();
$incident_category->incident_id = $incident->id;
$incident_category->category_id = $trusted_categories->id;
$incident_category->save();
}
}
}
}
//.........這裏部分代碼省略.........
示例12: importreport
function importreport($row, $group)
{
if (!strtotime($row['INCIDENT DATE'])) {
$this->errors[] = 'Could not parse incident date "' . htmlspecialchars($row['INCIDENT DATE']) . '" on line ' . ($this->rownumber + 1);
}
if (isset($row["APPROVED"]) and !in_array($row["APPROVED"], array('NO', 'YES'))) {
$this->errors[] = 'APPROVED must be either YES or NO on line ' . ($this->rownumber + 1);
}
if (isset($row["VERIFIED"]) and !in_array($row["VERIFIED"], array('NO', 'YES'))) {
$this->errors[] = 'VERIFIED must be either YES or NO on line ' . ($this->rownumber + 1);
}
if (count($this->errors)) {
return false;
}
// STEP 1: SAVE LOCATION
if (isset($row['LOCATION'])) {
$location = new Location_Model();
$location->location_name = isset($row['LOCATION']) ? $row['LOCATION'] : '';
$location->latitude = isset($row['LATITUDE']) ? $row['LATITUDE'] : '';
$location->longitude = isset($row['LONGITUDE']) ? $row['LONGITUDE'] : '';
$location->location_date = $this->time;
$location->save();
$this->locations_added[] = $location->id;
}
// STEP 2: SAVE INCIDENT
$incident = new Incident_Model();
$incident->location_id = isset($row['LOCATION']) ? $location->id : 0;
$incident->user_id = 0;
$incident->incident_title = $row['INCIDENT TITLE'];
$incident->incident_description = isset($row['DESCRIPTION']) ? $row['DESCRIPTION'] : '';
$incident->incident_date = date("Y-m-d H:i:s", strtotime($row['INCIDENT DATE']));
$incident->incident_dateadd = $this->time;
$incident->incident_active = (isset($row['APPROVED']) and $row['APPROVED'] == 'YES') ? 1 : 0;
$incident->incident_verified = (isset($row['VERIFIED']) and $row['VERIFIED'] == 'YES') ? 1 : 0;
$incident->save();
$this->incidents_added[] = $incident->id;
//STEP 2.5: SAVE THE GROUP ASSOCIATION
$group_incident = ORM::factory("simplegroups_groups_incident");
$group_incident->incident_id = $incident->id;
$group_incident->simplegroups_groups_id = $group->id;
$group_incident->save();
// STEP 3: SAVE CATEGORIES
if (isset($row['CATEGORY'])) {
$categorynames = explode(',', trim($row['CATEGORY']));
foreach ($categorynames as $categoryname) {
$categoryname = strtoupper(trim($categoryname));
// There seems to be an uppercase convention for categories... Don't know why.
if ($categoryname != '') {
if (!isset($this->category_ids[$categoryname])) {
$this->notices[] = 'There exists no category "' . htmlspecialchars($categoryname) . '" in database yet. This category was skipped.';
continue;
/*
$this->notices[] = 'There exists no category "'.htmlspecialchars($categoryname).'" in database yet. Added to database.';
$category = new Category_Model;
$category->category_title = $categoryname;
$category->category_color = '000000'; // We'll just use black for now. Maybe something random?
$category->category_type = 5; // because all current categories are of type '5'
$category->category_visible = 1;
$category->category_description = $categoryname;
$category->save();
$this->categories_added[] = $category->id;
$this->category_ids[$categoryname] = $category->id; // Now category_id is known: This time, and for the rest of the import.
*/
}
$incident_category = new Incident_Category_Model();
$incident_category->incident_id = $incident->id;
$incident_category->category_id = $this->category_ids[$categoryname];
$incident_category->save();
$this->incident_categories_added[] = $incident_category->id;
}
// empty categoryname not allowed
}
// add categories to incident
}
// if CATEGORIES column exists
// STEP 4: SAVE GROUP CATEGORIES
if (isset($row['GROUP CATEGORY'])) {
$categorynames = explode(',', trim($row['GROUP CATEGORY']));
foreach ($categorynames as $categoryname) {
$categoryname = strtoupper(trim($categoryname));
// There seems to be an uppercase convention for categories... Don't know why.
if ($categoryname != '') {
if (!isset($this->group_category_ids[$categoryname])) {
$this->notices[] = 'There exists no category "' . htmlspecialchars($categoryname) . '" in the group categories yet. Added to database.';
$category = ORM::factory("simplegroups_category");
$category->category_title = $categoryname;
$category->category_color = '000000';
// We'll just use black for now. Maybe something random?
$category->category_type = 5;
// because all current categories are of type '5'
$category->category_visible = 1;
$category->category_description = $categoryname;
$category->simplegroups_groups_id = $group->id;
$category->applies_to_report = 1;
$category->save();
$this->categories_added[] = $category->id;
$this->group_category_ids[$categoryname] = $category->id;
// Now category_id is known: This time, and for the rest of the import.
}
$incident_category = ORM::factory("simplegroups_incident_category");
//.........這裏部分代碼省略.........
示例13: punchcard
function punchcard()
{
$this->template->content = new View('admin/stats/punchcard');
$this->template->content->title = Kohana::lang('ui_admin.statistics');
$incident_dates = Incident_Model::get_incident_dates();
// Initialize the array. Zeroing everything out now to keep us from having to loop it
$data = array('sun' => array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0), 'mon' => array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0), 'tue' => array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0), 'wed' => array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0), 'thu' => array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0), 'fri' => array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0), 'sat' => array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0));
$highest_value = 0;
foreach ($incident_dates as $datetime) {
$t = strtotime($datetime);
$dow = strtolower(date('D', $t));
$hour = date('G', $t);
$data[$dow][$hour] += 1;
if ($data[$dow][$hour] > $highest_value) {
$highest_value = $data[$dow][$hour];
}
}
$this->template->content->chart_url = Kohana::config('core.site_protocol') . '://chart.googleapis.com/chart?chs=905x300&chds=-1,24,-1,7,0,' . $highest_value . '&chf=bg,s,efefef&chd=t:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23|0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7|' . implode(',', $data['sun']) . ',' . implode(',', $data['mon']) . ',' . implode(',', $data['tue']) . ',' . implode(',', $data['wed']) . ',' . implode(',', $data['thu']) . ',' . implode(',', $data['fri']) . ',' . implode(',', $data['sat']) . ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0&chxt=x,y&chm=o,333333,1,1.0,30.0&chxl=0:||12' . Kohana::lang('datetime.am') . '|1|2|3|4|5|6|7|8|9|10|11|12' . Kohana::lang('datetime.pm') . '|1|2|3|4|5|6|7|8|9|10|11||1:||' . Kohana::lang('datetime.sunday.abbv') . '|' . Kohana::lang('datetime.monday.abbv') . '|' . Kohana::lang('datetime.tuesday.abbv') . '|' . Kohana::lang('datetime.wednesday.abbv') . '|' . Kohana::lang('datetime.thursday.abbv') . '|' . Kohana::lang('datetime.friday.abbv') . '|' . Kohana::lang('datetime.saturday.abbv') . '|&cht=s';
}
示例14: index
//.........這裏部分代碼省略.........
foreach ($query as $slider_date) {
$years = $slider_date->incident_date;
$startDate .= "<optgroup label=\"" . $years . "\">";
for ($i = 1; $i <= 12; $i++) {
if ($i < 10) {
$i = "0" . $i;
}
$startDate .= "<option value=\"" . strtotime($years . "-" . $i . "-01") . "\"";
if ($active_month && (int) $i == $active_month - 1) {
$startDate .= " selected=\"selected\" ";
}
$startDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>";
}
$startDate .= "</optgroup>";
$endDate .= "<optgroup label=\"" . $years . "\">";
for ($i = 1; $i <= 12; $i++) {
if ($i < 10) {
$i = "0" . $i;
}
$endDate .= "<option value=\"" . strtotime($years . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59") . "\"";
// Focus on the most active month or set December as month of endDate
if ($active_month && (int) $i == $active_month + 1 || $i == 12 && preg_match('/selected/', $endDate) == 0) {
$endDate .= " selected=\"selected\" ";
}
$endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>";
}
$endDate .= "</optgroup>";
}
$this->template->content->startDate = $startDate;
$this->template->content->endDate = $endDate;
// get graph data
// could not use DB query builder. It does not support parentheses yet
$graph_data = array();
$all_graphs = Incident_Model::get_incidents_by_interval('month');
$daily_graphs = Incident_Model::get_incidents_by_interval('day');
$weekly_graphs = Incident_Model::get_incidents_by_interval('week');
$hourly_graphs = Incident_Model::get_incidents_by_interval('hour');
$this->template->content->all_graphs = $all_graphs;
$this->template->content->daily_graphs = $daily_graphs;
// If we are looking at the standard street map set by user
if (!isset($_GET['3dmap'])) {
//echo 'STREET MAP';
// Javascript Header
$this->template->header->map_enabled = 'streetmap';
$this->template->content->map_enabled = 'streetmap';
$this->template->content->map_container = 'map';
$this->template->header->main_page = TRUE;
$this->template->header->validator_enabled = TRUE;
// Map Settings
$clustering = Kohana::config('settings.allow_clustering');
$marker_radius = Kohana::config('map.marker_radius');
$marker_opacity = Kohana::config('map.marker_opacity');
$marker_stroke_width = Kohana::config('map.marker_stroke_width');
$marker_stroke_opacity = Kohana::config('map.marker_stroke_opacity');
// pdestefanis - allows to restrict the number of zoomlevels available
$numZoomLevels = Kohana::config('map.numZoomLevels');
$minZoomLevel = Kohana::config('map.minZoomLevel');
$maxZoomLevel = Kohana::config('map.maxZoomLevel');
// pdestefanis - allows to limit the extents of the map
$lonFrom = Kohana::config('map.lonFrom');
$latFrom = Kohana::config('map.latFrom');
$lonTo = Kohana::config('map.lonTo');
$latTo = Kohana::config('map.latTo');
$this->template->header->js = $clustering ? new View('main_cluster_js') : new View('main_cluster_js');
if ($clustering == 1) {
//$this->template->header->js->cluster = "true"; // not used??
示例15: edit
//.........這裏部分代碼省略.........
}
// Validate photo uploads
$post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[2M]');
// Validate Personal Information
if (!empty($_POST['person_first'])) {
$post->add_rules('person_first', 'length[3,100]');
}
if (!empty($_POST['person_last'])) {
$post->add_rules('person_last', 'length[3,100]');
}
if (!empty($_POST['person_email'])) {
$post->add_rules('person_email', 'email', 'length[3,100]');
}
// Validate Custom Fields
if (isset($post->custom_field) && !$this->_validate_custom_form_fields($post->custom_field)) {
$post->add_error('custom_field', 'values');
}
$post->add_rules('incident_active', 'required', 'between[0,1]');
$post->add_rules('incident_verified', 'required', 'length[0,1]');
$post->add_rules('incident_source', 'numeric', 'length[1,1]');
$post->add_rules('incident_information', 'numeric', 'length[1,1]');
// Test to see if things passed the rule checks
if ($post->validate()) {
// Yes! everything is valid
$location_id = $post->location_id;
// STEP 1: SAVE LOCATION
$location = new Location_Model($location_id);
$location->location_name = $post->location_name;
$location->latitude = $post->latitude;
$location->longitude = $post->longitude;
$location->location_date = date("Y-m-d H:i:s", time());
$location->save();
// STEP 2: SAVE INCIDENT
$incident = new Incident_Model($id);
$incident->location_id = $location->id;
//$incident->locale = $post->locale;
$incident->form_id = $post->form_id;
$incident->user_id = $_SESSION['auth_user']->id;
$incident->incident_title = $post->incident_title;
$incident->incident_description = $post->incident_description;
$incident_date = explode("/", $post->incident_date);
// where the $_POST['date'] is a value posted by form in mm/dd/yyyy format
$incident_date = $incident_date[2] . "-" . $incident_date[0] . "-" . $incident_date[1];
$incident_time = $post->incident_hour . ":" . $post->incident_minute . ":00 " . $post->incident_ampm;
$incident->incident_date = date("Y-m-d H:i:s", strtotime($incident_date . " " . $incident_time));
// Is this new or edit?
if ($id) {
$incident->incident_datemodify = date("Y-m-d H:i:s", time());
} else {
$incident->incident_dateadd = date("Y-m-d H:i:s", time());
}
// Is this an Email, SMS, Twitter submitted report?
//XXX: We may get rid of incident_mode altogether... ???
//$_POST
if (!empty($service_id)) {
if ($service_id == 1) {
// SMS
$incident->incident_mode = 2;
} elseif ($service_id == 2) {
// Email
$incident->incident_mode = 3;
} elseif ($service_id == 3) {
// Twitter
$incident->incident_mode = 4;
} elseif ($service_id == 4) {
// Laconica