| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.8 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Analytics\QueryBuilders\Views; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class EventsStrategy extends BaseViewsQueryStrategy |
| 20 |
{ |
| 21 |
public function getSelect(): string |
| 22 |
{ |
| 23 |
$filter = ''; |
| 24 |
$filters = $this->metric->getFilters(); |
| 25 |
|
| 26 |
if (array_key_exists('campaign', $filters) && isset($filters['campaign']['value']) && is_array($filters['campaign']['value'])) |
| 27 |
{ |
| 28 |
$filter .= 'AND ll.box IN (' . implode(',', array_map('intval', $filters['campaign']['value'])) . ')'; |
| 29 |
} |
| 30 |
|
| 31 |
$options = $this->metric->getOptions(); |
| 32 |
$start_date = $options['start_date'] ?? ''; |
| 33 |
$end_date = $options['end_date'] ?? ''; |
| 34 |
|
| 35 |
return ' |
| 36 |
IF(ld.event IS NOT NULL, ld.event, \'open\') AS label, |
| 37 |
IF(ld.event IS NOT NULL, COUNT(l.id), ( |
| 38 |
SELECT COUNT(ll.id) |
| 39 |
FROM ' . $this->metric->getTableLogs() . ' AS ll |
| 40 |
WHERE (ll.date >= \'' . esc_sql($start_date) . '\' |
| 41 |
AND ll.date <= \'' . esc_sql($end_date) . '\') |
| 42 |
' . $filter . ' |
| 43 |
)) AS total |
| 44 |
'; |
| 45 |
} |
| 46 |
|
| 47 |
public function getGroupBy(): string |
| 48 |
{ |
| 49 |
return 'GROUP BY ld.event'; |
| 50 |
} |
| 51 |
|
| 52 |
public function getOrderBy(): string |
| 53 |
{ |
| 54 |
return $this->getTotalOrderBy(); |
| 55 |
} |
| 56 |
} |
| 57 |
|