PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Controllers/Stats/Detailed.php +106 -0 10.2.0 → 11.1.0 View file →
@@ -1,0 +1,106 @@
1 +<?php
2 +
3 +namespace AcyMailing\Controllers\Stats;
4 +
5 +use AcyMailing\Classes\UserStatClass;
6 +use AcyMailing\Helpers\ExportHelper;
7 +use AcyMailing\Helpers\PaginationHelper;
8 +
9 +trait Detailed
10 +{
11 + public function detailedStats(): void
12 + {
13 + acym_setVar('layout', 'detailed_stats');
14 +
15 + $data = [];
16 +
17 + $this->prepareDefaultPageInfo($data);
18 +
19 + $data['anonymousStats'] = !empty($this->config->get('anonymous_stats', 0));
20 +
21 + $this->prepareDetailedListing($data);
22 + if (count($this->selectedMailIds) == 1) {
23 + if ($data['isAbTest']) {
24 + $this->prepareAbTestMails($data);
25 + } elseif (acym_isMultilingual()) {
26 + $this->prepareMultilingualMails($data);
27 + }
28 + }
29 + $this->prepareMailFilter($data);
30 +
31 + parent::display($data);
32 + }
33 +
34 + public function exportDetailed(): void
35 + {
36 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
37 +
38 + $exportHelper = new ExportHelper();
39 + $data = [];
40 + $this->prepareDefaultPageInfo($data);
41 +
42 + $where = '';
43 + if (!empty($this->selectedMailIds)) {
44 + $where = 'WHERE userstat.`mail_id` IN ('.implode(',', $this->selectedMailIds).')';
45 + }
46 +
47 + $groupBy = ' GROUP BY userstat.mail_id, userstat.user_id ';
48 +
49 + $columnsMailStat = acym_getColumns('user_stat');
50 + $columnsToExport = [];
51 +
52 + $columnsToExport['mail.subject'] = acym_translation('ACYM_EMAIL_SUBJECT');
53 + $columnsToExport['user.email'] = acym_translation('ACYM_USER_EMAIL');
54 + $columnsToExport['user.name'] = acym_translation('ACYM_USER_NAME');
55 + foreach ($columnsMailStat as $column) {
56 + if (in_array($column, ['user_id', 'mail_id'])) continue;
57 + $trad = acym_translation('ACYM_'.strtoupper($column).'_COLUMN_STAT');
58 + if ($column === 'send_date') $trad = acym_translation('ACYM_SEND_DATE');
59 + if ($column === 'open') $trad = acym_translation('ACYM_OPEN_TOTAL_COLUMN_STAT');
60 + if ($column === 'bounce') $trad = acym_translation('ACYM_BOUNCE_UNIQUE_COLUMN_STAT');
61 + $columnsToExport['userstat.'.$column] = $trad;
62 + }
63 +
64 + $query = 'SELECT '.implode(', ', array_keys($columnsToExport)).', SUM(urlclick.click) AS click FROM #__acym_user_stat AS userstat
65 + LEFT JOIN #__acym_user AS user ON user.id = userstat.user_id
66 + LEFT JOIN #__acym_mail AS mail ON mail.id = userstat.mail_id
67 + LEFT JOIN #__acym_url_click AS urlclick ON urlclick.user_id = userstat.user_id AND userstat.mail_id = urlclick.mail_id '.$where.$groupBy;
68 + $columnsToExport['urlclick.click'] = acym_translation('ACYM_TOTAL_CLICK');
69 + $exportHelper->exportStatsFullCSV($query, $columnsToExport, 'detailed');
70 + exit;
71 + }
72 +
73 + private function prepareDetailedListing(array &$data): void
74 + {
75 + $data['search'] = $this->getVarFiltersListing('string', 'detailed_stats_search', '');
76 + $data['ordering'] = $this->getVarFiltersListing('cmd', 'detailed_stats_ordering', 'send_date');
77 + $data['orderingSortOrder'] = $this->getVarFiltersListing('cmd', 'detailed_stats_ordering_sort_order', 'desc');
78 +
79 + if (empty($this->selectedMailIds)) {
80 + return;
81 + }
82 +
83 + $userStatClass = new UserStatClass();
84 + $pagination = new PaginationHelper();
85 +
86 + $detailedStatsPerPage = $pagination->getListLimit();
87 + $page = $this->getVarFiltersListing('int', 'detailed_stats_pagination_page', 1);
88 +
89 + $matchingDetailedStats = $userStatClass->getDetailedStats(
90 + [
91 + 'ordering' => $data['ordering'],
92 + 'ordering_sort_order' => $data['orderingSortOrder'],
93 + 'search' => $data['search'],
94 + 'detailedStatsPerPage' => $detailedStatsPerPage,
95 + 'offset' => ($page - 1) * $detailedStatsPerPage,
96 + 'mail_ids' => $this->selectedMailIds,
97 + ]
98 + );
99 +
100 + // Prepare the pagination
101 + $pagination->setStatus((int)$matchingDetailedStats['total']->total, $page, $detailedStatsPerPage);
102 +
103 + $data['pagination'] = $pagination;
104 + $data['detailed_stats'] = $matchingDetailedStats['detailed_stats'];
105 + }
106 +}