function popup_onload_statistics_get_stats in Popup On Load 7
Same name and namespace in other branches
- 8 modules/popup_onload_statistics/popup_onload_statistics.module \popup_onload_statistics_get_stats()
Fetch statistics from the database.
1 call to popup_onload_statistics_get_stats()
- popup_onload_statistics_admin_form in popup_onload_statistics/
popup_onload_statistics.admin.inc - Callback for the admin report table.
File
- popup_onload_statistics/
popup_onload_statistics.module, line 98 - Main popup on loadvertisement statistics functions.
Code
function popup_onload_statistics_get_stats($date_from = NULL, $date_to = NULL) {
$params = [];
$date_sql = '';
if (!is_null($date_from)) {
$date_sql .= "AND sps.atime >= :date_from ";
$params[':date_from'] = $date_from;
}
if (!is_null($date_to)) {
$date_sql .= "AND sps.atime <= :date_to ";
$params[':date_to'] = $date_to;
}
$query = db_select('popup_onload', 'p');
$query
->leftJoin('popup_onload_statistics', 'sps', 'sps.popup_id = p.popup_id ' . $date_sql, $params);
$query
->addExpression('COUNT(sps.type)', 'action_count');
$query
->fields('p', [
'name',
'popup_id',
])
->fields('sps', [
'atime',
'type',
'aid',
])
->groupBy('popup_id')
->groupBy('type')
->orderBy('name');
$result = $query
->execute()
->fetchAll();
$stats = [];
$group_id = 0;
foreach ($result as $row) {
if ($row->popup_id != $group_id) {
$group_id = $row->popup_id;
}
$stats[$group_id]['popup_id'] = $row->popup_id;
$stats[$group_id]['name'] = $row->name;
if ($row->type) {
$stats[$group_id][$row->type] = $row->action_count;
}
else {
$stats[$group_id]['view'] = 0;
$stats[$group_id]['click'] = 0;
}
}
return $stats;
}