function opigno_statistics_app_query_total_number_of_page_view in Opigno Statistics App 7
Query total number of page view (cached for 1 day)
Parameters
int $month_year:
boolean $filter_month:
Return value
array
1 call to opigno_statistics_app_query_total_number_of_page_view()
- opigno_statistics_app_present_total_number_of_page_view in includes/
dashboard/ presenters.inc - Present total number of page view
File
- includes/
dashboard/ queries.inc, line 240
Code
function opigno_statistics_app_query_total_number_of_page_view($month_year, $filter_month) {
$cache_key = __FUNCTION__ . ':' . $month_year . ':' . $filter_month;
$cached_object = cache_get($cache_key);
if ($cached_object) {
$total_number_of_page_view = $cached_object->data;
}
else {
$total_number_of_page_view = array();
// The accesslog table is flushed every month. So if the user want the data for the current month, use the accesslog
// Else, use the statistics_group table
if ($filter_month && date('Y-m') == date('Y-m', $month_year)) {
$result = db_query("\n SELECT DATE_FORMAT(FROM_UNIXTIME(timestamp), '%Y-%m-%d') as day, COUNT(*) as value\n FROM {accesslog}\n WHERE DATE_FORMAT(FROM_UNIXTIME(timestamp), '%m-%Y') = DATE_FORMAT(FROM_UNIXTIME(:timestamp), '%m-%Y')\n GROUP BY day\n ", array(
':timestamp' => $month_year,
));
}
else {
$filter_month_year = $filter_month ? '%m-%Y' : '%Y';
$result = db_query("\n SELECT DATE_FORMAT(FROM_UNIXTIME(month_year), '%Y-%m-%d') as day, SUM(page_views) as value\n FROM {opigno_statistics_group}\n WHERE DATE_FORMAT(FROM_UNIXTIME(month_year), '" . $filter_month_year . "') = DATE_FORMAT(FROM_UNIXTIME(:month_year), '" . $filter_month_year . "')\n GROUP BY day\n ", array(
':month_year' => $month_year,
));
}
while ($record = $result
->fetchAssoc()) {
$total_number_of_page_view[] = $record;
}
cache_set($cache_key, $total_number_of_page_view, 'cache', time() + 7200);
// 7200s = 2h cache
}
return $total_number_of_page_view;
}