本文整理汇总了PHP中Category_Model::categories方法的典型用法代码示例。如果您正苦于以下问题:PHP Category_Model::categories方法的具体用法?PHP Category_Model::categories怎么用?PHP Category_Model::categories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category_Model
的用法示例。
在下文中一共展示了Category_Model::categories方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAll
/**
* Returns an array with all categories
*
* @return array
*/
public function getAll()
{
if (isset(self::$categories)) {
return self::$categories;
}
if ($categories = Cache::read('categories')) {
return $categories;
}
self::$categories = $this->createQuery()->fields('id', 'name', 'url_name')->order(array('order', 'ASC'))->select();
Cache::write('categories', self::$categories, 3600);
return self::$categories;
}
示例2: reports
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);
}
示例3: categories
/**
* Gets the list of categories from the database as an array
*
* @param int $category_id Database id of the category
* @param string $local Localization to use
* @return array
*/
public static function categories($category_id = NULL)
{
if (!isset(self::$categories)) {
$categories = ORM::factory('category')->find_all();
self::$categories = array();
foreach ($categories as $category) {
self::$categories[$category->id]['category_id'] = $category->id;
self::$categories[$category->id]['category_title'] = $category->category_title;
self::$categories[$category->id]['category_description'] = $category->category_description;
self::$categories[$category->id]['category_color'] = $category->category_color;
self::$categories[$category->id]['category_image'] = $category->category_image;
self::$categories[$category->id]['category_image_thumb'] = $category->category_image_thumb;
}
}
if ($category_id) {
return isset(self::$categories[$category_id]) ? array($category_id => self::$categories[$category_id]) : FALSE;
}
return self::$categories;
}
示例4: index
/**
* 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;
//.........这里部分代码省略.........
示例5: impact
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']);
}
示例6: impact
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']);
}
示例7: _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/list');
// Fetch all incidents
$incidents = reports::fetch_incidents(TRUE);
// Pagination
$pagination = reports::$pagination;
// For compatibility with older custom themes:
// Generate array of category titles with their proper localizations using an array
// DO NOT use this in new code, call Category_Lang_Model::category_title() directly
foreach (Category_Model::categories() as $category) {
$localized_categories[$category['category_title']] = Category_Lang_Model::category_title($category['category_id']);
}
// 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;
}
示例8: index
//.........这里部分代码省略.........
$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);
}
}
示例9: category_description
/**
* Return category description in specified language
* If not locale specified return default
* @param int category id
* @param string Locale string
*/
static function category_description($category_id, $locale = FALSE)
{
// Use default locale from settings if not specified
if (!$locale) {
$locale = Kohana::config('locale.language.0');
}
// Use self::category_langs() to grab all category_lang entries
// This function is often in a loop so only query once
$cat_langs = self::category_langs();
// Return translated title if its not blank
if (isset($cat_langs[$category_id][$locale]) and !empty($cat_langs[$category_id][$locale]['category_description'])) {
return $cat_langs[$category_id][$locale]['category_description'];
}
// If we didn't find one, grab the default title
$categories = Category_Model::categories();
if (isset($categories[$category_id]['category_description'])) {
return $categories[$category_id]['category_description'];
}
return FALSE;
}