function reports() { $this->template->content = new View('admin/stats_reports'); $this->template->content->title = 'Report Stats'; // Retrieve Current Settings $settings = ORM::factory('settings', 1); $this->template->content->stat_id = $settings->stat_id; // Javascript Header $this->template->protochart_enabled = TRUE; // Report Data $data = Stats_Model::get_report_stats(); $reports_chart = new protochart(); $options = array('pies' => array('show' => 'true'), 'legend' => array('show' => 'true')); // Grab category data $cats = Category_Model::categories(); $report_data = array(); foreach ($data['category_counts'] as $category_id => $count) { $category_name = $cats[$category_id]['category_title']; $report_data[$category_name] = $count; $colors[$category_name] = $cats[$category_id]['category_color']; } $this->template->content->reports_chart = $reports_chart->chart('reports', $report_data, $options, $colors); $report_status_chart = new protochart(); foreach ($data['verified_counts'] as $ver_or_un => $arr) { if (!isset($report_staus_data[$ver_or_un][0])) { $report_staus_data[$ver_or_un][0] = 0; } foreach ($arr as $count) { $report_staus_data[$ver_or_un][0] += $count; } } foreach ($data['approved_counts'] as $app_or_un => $arr) { if (!isset($report_staus_data[$app_or_un][0])) { $report_staus_data[$app_or_un][0] = 0; } foreach ($arr as $count) { $report_staus_data[$app_or_un][0] += $count; } } $this->template->content->report_status_chart = $report_status_chart->chart('report_status', $report_staus_data, $options); }
/** * Displays all reports. */ public function index() { $this->template->header->this_page = 'reports'; $this->template->content = new View('reports'); // Filter By Category $category_filter = isset($_GET['c']) && !empty($_GET['c']) ? "category_id = " . $_GET['c'] : " 1=1 "; // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => ORM::factory('incident')->join('incident_category', 'incident.id', 'incident_category.incident_id')->where('incident_active', '1')->where($category_filter)->count_all())); $incidents = ORM::factory('incident')->select('DISTINCT incident.*')->join('incident_category', 'incident.id', 'incident_category.incident_id')->where('incident_active', '1')->where($category_filter)->groupby('incident.id')->orderby('incident_date', 'desc')->find_all((int) Kohana::config('settings.items_per_page'), $pagination->sql_offset); $this->template->content->incidents = $incidents; //Set default as not showing pagination. Will change below if necessary. $this->template->content->pagination = ''; // Pagination and Total Num of Report Stats if ($pagination->total_items == 1) { $plural = ''; } else { $plural = 's'; } if ($pagination->total_items > 0) { $current_page = $pagination->sql_offset / (int) Kohana::config('settings.items_per_page') + 1; $total_pages = ceil($pagination->total_items / (int) Kohana::config('settings.items_per_page')); if ($total_pages > 1) { // If we want to show pagination $this->template->content->pagination_stats = '(Showing ' . $current_page . ' of ' . $total_pages . ' pages of ' . $pagination->total_items . ' report' . $plural . ')'; $this->template->content->pagination = $pagination; } else { // If we don't want to show pagination $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')'; } } else { $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')'; } $icon_html = array(); $icon_html[1] = "<img src=\"" . url::base() . "media/img/image.png\">"; //image $icon_html[2] = "<img src=\"" . url::base() . "media/img/video.png\">"; //video $icon_html[3] = ""; //audio $icon_html[4] = ""; //news $icon_html[5] = ""; //podcast //Populate media icon array $this->template->content->media_icons = array(); foreach ($incidents as $incident) { $incident_id = $incident->id; if (ORM::factory('media')->where('incident_id', $incident_id)->count_all() > 0) { $medias = ORM::factory('media')->where('incident_id', $incident_id)->find_all(); //Modifying a tmp var prevents Kohona from throwing an error $tmp = $this->template->content->media_icons; $tmp[$incident_id] = ''; foreach ($medias as $media) { $tmp[$incident_id] .= $icon_html[$media->media_type]; $this->template->content->media_icons = $tmp; } } } // Category Title, if Category ID available $category_id = isset($_GET['c']) && !empty($_GET['c']) ? $_GET['c'] : "0"; $category = ORM::factory('category')->find($category_id); $this->template->content->category_title = $category->loaded ? $category->category_title : ""; // BEGIN CHART CREATION // Note: The reason this code block is so long is because protochart // doesn't seem to handle bar charts in time mode so well. The // bars show up as skinny lines because it uses the timestamp // to determine location on the graph, which doesn't give the // bar much wiggle room in just a few hundred pixels. // Create protochart $this->template->header->protochart_enabled = TRUE; $report_chart = new protochart(); // FIXME: Perhaps instead of grabbing the report stats again, we can // get what we need from above so we can cut down on database // calls. It will take playing with the incident model to get // all of the data we need, though. // Report Data $data = Stats_Model::get_report_stats(true); // Grab category data $cats = Category_Model::categories(); $highest_count = 1; $report_data = array(); $tick_string_array = array(); foreach ($data['category_counts'] as $category_id => $count_array) { // Does this category exist locally any more? if (isset($cats[$category_id])) { $category_name = $cats[$category_id]['category_title']; $colors[$category_name] = $cats[$category_id]['category_color']; $i = 1; foreach ($count_array as $time => $count) { $report_data[$category_name][$i] = $count; // The highest count will determine the number of ticks on the y-axis if ($count > $highest_count) { $highest_count = $count; } // This statement sets us up so we can convert the key to a date if (!isset($tick_represents[$i])) { $tick_represents[$i] = $time; // Save name $tick_string_array[$i] = date('M d', $time); } $i++; } } } $highest_count += 1; // This javascript function will take the integer index and convert it to a readable date $tickFormatter = "function (val, axis)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t switch(val){"; foreach ($tick_string_array as $i => $date_string) { $tickFormatter .= "case {$i}:\n\t\t\t\t\t\t \t\treturn '{$date_string}';"; } $tickFormatter .= "default:\n\t\t\t\t\t\t \t\treturn '';\n\t\t\t\t\t\t }\n\t\t\t\t\t\t return 'sup';\n\t\t\t\t\t\t }"; $options = array('bars' => array('show' => 'true'), 'xaxis' => array('min' => 0, 'max' => count($tick_string_array) + 1, 'tickFormatter' => $tickFormatter), 'yaxis' => array('tickSize' => 1, 'max' => $highest_count, 'tickDecimals' => 0), 'legend' => array('show' => 'true', 'noColumns' => 3), 'grid' => array('drawXAxis' => 'false')); if (count($report_data) == 0) { // Don't show a chart if there's no data $this->template->content->report_chart = ''; } else { // Show chart $width = 900; $height = 100; $this->template->content->report_chart = $report_chart->chart('reports', $report_data, $options, $colors, $width, $height); } }
public function impact() { $this->template->content = new View('admin/stats/impact'); $this->template->content->title = Kohana::lang('ui_admin.statistics'); // Javascript Header $this->themes->raphael_enabled = TRUE; $this->themes->js = new View('admin/stats/stats_js'); $this->template->content->failure = ''; // Set the date range (how many days in the past from today?) $range = (isset($_GET['range']) and is_int($_GET['range'])) ? $_GET['range'] : 10000; // Get all reports so go back far into the past $this->template->content->range = $range; // Get an arbitrary date range $dp1 = isset($_GET['dp1']) ? $_GET['dp1'] : null; $dp2 = isset($_GET['dp2']) ? $_GET['dp2'] : null; // Report Data $data = Stats_Model::get_report_stats(false, true, $range, $dp1, $dp2); // If we failed to get hit data, fail. if (!isset($data['category_counts'])) { $this->template->content->num_reports = 0; $this->template->content->num_categories = 0; $this->template->impact_json = ''; $this->template->content->dp1 = $dp1; $this->template->content->dp2 = $dp2; return false; } $json = array(); $use_log = ''; $json['buckets'] = array(); $cat_report_count = array(); $category_counter = array(); foreach ($data['category_counts'] as $timestamp => $count_array) { $line = array(); // If this number is greater than 0, we'll show the line $display_test = 0; foreach ($count_array as $category_id => $count) { $category_counter[$category_id] = 1; // We aren't allowing 0s if ($count > 0) { $line[] = array($category_id, $count); $display_test += $count; // If we see a count over 50 (picked this arbitrarily), then switch to log format if ($count > 50) { $use_log = 1; } // Count the number of reports so we have something useful to show in the legend if (!isset($cat_report_count[$category_id])) { $cat_report_count[$category_id] = 0; } $cat_report_count[$category_id] += $count; } } if ($display_test > 0) { $json['buckets'][] = array('d' => $timestamp, 'i' => $line); } } $this->template->content->num_reports = $data['total_reports']; $this->template->content->num_categories = $data['total_categories']; $json['use_log'] = $use_log; $json['categories'] = array(); // Grab category data $cats = Category_Model::categories(); foreach ($cats as $category_id => $cat_array) { $report_count = 0; if (isset($cat_report_count[$category_id])) { $report_count = $cat_report_count[$category_id]; } $json['categories'][$category_id] = array("name" => $cat_array['category_title'], "fill" => '#' . $cat_array['category_color'], "reports" => $report_count); } $this->themes->impact_json = json_encode($json); // Set the date $this->template->content->dp1 = date('Y-m-d', $data['earliest_report_time']); $this->template->content->dp2 = date('Y-m-d', $data['latest_report_time']); }
function impact() { $this->template->content = new View('admin/stats_impact'); $this->template->content->title = Kohana::lang('ui_admin.statistics'); // Javascript Header $this->template->raphael_enabled = TRUE; $this->template->js = new View('admin/stats_js'); $this->template->content->failure = ''; // Set the date range (how many days in the past from today?) $range = (isset($_GET['range']) and is_int($_GET['range'])) ? $_GET['range'] : 10000; // Get all reports so go back far into the past $this->template->content->range = $range; // Get an arbitrary date range $dp1 = isset($_GET['dp1']) ? $_GET['dp1'] : null; $dp2 = isset($_GET['dp2']) ? $_GET['dp2'] : null; // Report Data $data = Stats_Model::get_report_stats(false, true, $range, $dp1, $dp2); // If we failed to get hit data, fail. if (!isset($data['category_counts'])) { $this->template->content->num_reports = 0; $this->template->content->num_categories = 0; $this->template->impact_json = ''; return false; } $json = ''; $use_log = ''; $json .= '"buckets":[' . "\n"; $cat_report_count = array(); $category_counter = array(); foreach ($data['category_counts'] as $timestamp => $count_array) { $comma_flag = false; $line = ''; // If this number is greater than 0, we'll show the line $display_test = 0; foreach ($count_array as $category_id => $count) { $category_counter[$category_id] = 1; // We aren't allowing 0s if ($count > 0) { if ($comma_flag) { $line .= ','; } $comma_flag = true; $line .= '[' . $category_id . ',' . $count . ']'; $display_test += $count; // If we see a count over 50 (picked this arbitrarily), then switch to log format if ($count > 50) { $use_log = '"use_log":1,' . "\n"; } // Count the number of reports so we have something useful to show in the legend if (!isset($cat_report_count[$category_id])) { $cat_report_count[$category_id] = 0; } $cat_report_count[$category_id] += $count; } } if ($display_test > 0) { $json .= '{"d":' . $timestamp . ',"i":['; $json .= $line; $json .= ']},' . "\n"; } } $this->template->content->num_reports = $data['total_reports']; $this->template->content->num_categories = $data['total_categories']; $json .= '],' . "\n"; $json .= $use_log; $json .= '"categories":' . "\n"; $json .= '{' . "\n"; // Grab category data $cats = Category_Model::categories(); foreach ($cats as $category_id => $cat_array) { $report_count = 0; if (isset($cat_report_count[$category_id])) { $report_count = $cat_report_count[$category_id]; } $json .= $category_id . ':{"name":"' . $cat_array['category_title'] . '","fill":"#' . $cat_array['category_color'] . '","reports":' . $report_count . '},' . "\n"; } $json .= '}' . "\n"; $this->template->impact_json = $json; // Set the date $this->template->content->dp1 = date('Y-m-d', $data['earliest_report_time']); $this->template->content->dp2 = date('Y-m-d', $data['latest_report_time']); }
function index() { $this->template->content = new View('admin/dashboard'); $this->template->content->title = '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'); // Set the date range (how many days in the past from today?) // default to one year $range = 365; if (isset($_GET['range'])) { $range = $_GET['range']; } $this->template->content->range = $range; // Report Data $data = Stats_Model::get_report_stats(false, true, $range, null, null, true); $this->template->content->failure = ''; // If we failed to get hit data, fail. if (!$data) { $now = time() * 1000; $data['all'][$now] = 0; /* $this->template->content->report_chart = ''; $this->template->content->failure = 'No report data for chart.'; return false; */ } $report_chart = new protochart(); $options = array('xaxis' => array('mode' => '"time"'), 'legend' => array('show' => 'true')); $pass_data['Reports'] = $data['all']; $this->template->content->report_chart = $report_chart->chart('report_chart', $pass_data, $options, array('Reports' => 'CC0000'), 410, 310); }
/** * Displays all reports. */ public function index() { $db = new Database(); $this->template->header->this_page = 'reports'; $this->template->content = new View('reports'); $filter = isset($_GET['c']) && !empty($_GET['c']) && $_GET['c'] != 0 ? " AND ( category.id='" . $_GET['c'] . "' OR \n\t\t\t\tcategory.parent_id='" . $_GET['c'] . "' ) " : " AND 1 = 1"; if (isset($_GET['sw']) && !empty($_GET['sw']) && count($southwest = explode(",", $_GET['sw'])) > 1 && isset($_GET['ne']) && !empty($_GET['ne']) && count($northeast = explode(",", $_GET['ne'])) > 1) { list($longitude_min, $latitude_min) = $southwest; list($longitude_max, $latitude_max) = $northeast; $filter .= " AND location.latitude >=" . $latitude_min . " AND location.latitude <=" . $latitude_max; $filter .= " AND location.longitude >=" . $longitude_min . " AND location.longitude <=" . $longitude_max; } // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => $db->query("SELECT DISTINCT `incident`.* FROM `incident` JOIN `incident_category` ON (`incident`.`id` = `incident_category`.`incident_id`) JOIN `category` ON (`category`.`id` = `incident_category`.`category_id`) JOIN `location` ON (`incident`.`location_id` = `location`.`id`) WHERE `incident_active` = '1' {$filter}")->count())); $incidents = $db->query("SELECT DISTINCT `incident`.*, `location`.`location_name` FROM `incident` JOIN `incident_category` ON (`incident`.`id` = `incident_category`.`incident_id`) JOIN `category` ON (`category`.`id` = `incident_category`.`category_id`) JOIN `location` ON (`incident`.`location_id` = `location`.`id`) WHERE `incident_active` = '1' {$filter} ORDER BY incident_date DESC LIMIT " . (int) Kohana::config('settings.items_per_page') . " OFFSET " . $pagination->sql_offset); $this->template->content->incidents = $incidents; //Set default as not showing pagination. Will change below if necessary. $this->template->content->pagination = ''; // Pagination and Total Num of Report Stats if ($pagination->total_items == 1) { $plural = ''; } else { $plural = 's'; } if ($pagination->total_items > 0) { $current_page = $pagination->sql_offset / (int) Kohana::config('settings.items_per_page') + 1; $total_pages = ceil($pagination->total_items / (int) Kohana::config('settings.items_per_page')); if ($total_pages > 1) { // If we want to show pagination $this->template->content->pagination_stats = '(Showing ' . $current_page . ' of ' . $total_pages . ' pages of ' . $pagination->total_items . ' report' . $plural . ')'; $this->template->content->pagination = $pagination; } else { // If we don't want to show pagination $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')'; } } else { $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')'; } //Declare icon_type array $icon_type = array(); $icon_type[1] = "image"; //image $icon_type[2] = "video"; //video $icon_type[3] = "audio"; //audio $icon_type[4] = "news"; //news $icon_type[5] = "podcast"; //podcast // Declare incident mode array $incident_mode = array(); $incident_mode[1] = "Web"; //Web $incident_mode[2] = "Sms"; //Sms $incident_mode[3] = "Email"; //Email $incident_mode[4] = "Twitter"; //Twitter //Populate media icon array $this->template->content->media_icons = array(); $this->template->content->incident_mode = array(); foreach ($incidents as $incident) { $incident_id = $incident->id; //Set the incident mode to SMS if it contians a custom phone. if ($incident->incident_custom_phone !== '') { $this->template->content->incident_mode[$incident->id] = $incident_mode[2]; } else { $this->template->content->incident_mode[$incident->id] = $incident_mode[$incident->incident_mode]; } if (ORM::factory('media')->where('incident_id', $incident_id)->count_all() > 0) { $medias = ORM::factory('media')->where('incident_id', $incident_id)->find_all(); //Modifying a tmp var prevents Kohona from throwing an error $tmp = $this->template->content->media_icons; $tmp[$incident_id] = ''; //Build the media_icons array also adding anchor to link to media_link //If the media type is an image. Append the /media/uploads/ path. foreach ($medias as $media) { $tmp[$incident_id] .= "<li class='" . $icon_type[$media->media_type] . "'>\n\t\t\t\t\t<a href='" . ($icon_type[$media->media_type] === 'image' ? '/media/uploads/' : '') . $media->media_link . "' title='" . $icon_type[$media->media_type] . "' target='_blank'></a>\n\t\t\t\t\t</li>"; $this->template->content->media_icons = $tmp; } } } // Category Title, if Category ID available $category_id = isset($_GET['c']) && !empty($_GET['c']) ? $_GET['c'] : "0"; $category = ORM::factory('category')->find($category_id); $this->template->content->category_title = $category->loaded ? $category->category_title : ""; // BEGIN CHART CREATION // Note: The reason this code block is so long is because protochart // doesn't seem to handle bar charts in time mode so well. The // bars show up as skinny lines because it uses the timestamp // to determine location on the graph, which doesn't give the // bar much wiggle room in just a few hundred pixels. // Create protochart $this->template->header->protochart_enabled = TRUE; $report_chart = new protochart(); // FIXME: Perhaps instead of grabbing the report stats again, we can // get what we need from above so we can cut down on database // calls. It will take playing with the incident model to get // all of the data we need, though. // Report Data $data = Stats_Model::get_report_stats(true); // Grab category data $cats = Category_Model::categories(); $highest_count = 1; $report_data = array(); $tick_string_array = array(); foreach ($data['category_counts'] as $category_id => $count_array) { // Does this category exist locally any more? if (isset($cats[$category_id])) { $category_name = $cats[$category_id]['category_title']; $colors[$category_name] = $cats[$category_id]['category_color']; $i = 1; foreach ($count_array as $time => $count) { $report_data[$category_name][$i] = $count; // The highest count will determine the number of ticks on the y-axis if ($count > $highest_count) { $highest_count = $count; } // This statement sets us up so we can convert the key to a date if (!isset($tick_represents[$i])) { $tick_represents[$i] = $time; // Save name $tick_string_array[$i] = date('M d', $time); } $i++; } } } $highest_count += 1; // This javascript function will take the integer index and convert it to a readable date $tickFormatter = "function (val, axis)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t switch(val){"; foreach ($tick_string_array as $i => $date_string) { $tickFormatter .= "case {$i}:\n\t\t\t\t\t\t \t\treturn '{$date_string}';"; } $tickFormatter .= "default:\n\t\t\t\t\t\t \t\treturn '';\n\t\t\t\t\t\t }\n\t\t\t\t\t\t return 'sup';\n\t\t\t\t\t\t }"; $options = array('bars' => array('show' => 'true'), 'xaxis' => array('min' => 0, 'max' => count($tick_string_array) + 1, 'tickFormatter' => $tickFormatter), 'yaxis' => array('tickSize' => 1, 'max' => $highest_count, 'tickDecimals' => 0), 'legend' => array('show' => 'true', 'noColumns' => 3), 'grid' => array('drawXAxis' => 'false')); if (count($report_data) == 0) { // Don't show a chart if there's no data $this->template->content->report_chart = ''; } else { // Show chart $width = 900; $height = 100; $this->template->content->report_chart = $report_chart->chart('reports', $report_data, $options, $colors, $width, $height); } }