function opigno_statistics_app_query_user_total_number_of_page_view in Opigno Statistics App 7
Query total number of page view for a user (cached for 1 day)
Parameters
int $uid:
int $month_year:
boolean $filter_month:
Return value
array
1 call to opigno_statistics_app_query_user_total_number_of_page_view()
- opigno_statistics_app_present_user_total_number_of_page_view in includes/
user/ presenters.inc - Present user total number of page view
File
- includes/
user/ queries.inc, line 97
Code
function opigno_statistics_app_query_user_total_number_of_page_view($uid, $month_year, $filter_month) {
$cache_key = __FUNCTION__ . ':' . $uid . ':' . $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();
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 uid = :uid\n AND DATE_FORMAT(FROM_UNIXTIME(timestamp),'%m-%Y') = DATE_FORMAT(FROM_UNIXTIME(:timestamp),'%m-%Y')\n GROUP BY day\n ", array(
':uid' => $uid,
':timestamp' => $month_year,
));
}
else {
$filter_timestamp_format = $filter_month ? '%m-%Y' : '%Y';
$result = db_query("\n SELECT DATE_FORMAT(FROM_UNIXTIME(month_year),'%Y-%m-%d') as day, page_views as value\n FROM {opigno_statistics_user}\n WHERE uid = :uid\n AND DATE_FORMAT(FROM_UNIXTIME(month_year), '" . $filter_timestamp_format . "') = DATE_FORMAT(FROM_UNIXTIME(:month_year), '" . $filter_timestamp_format . "')\n ", array(
':uid' => $uid,
':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;
}