| @@ -1,0 +1,97 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace AcyMailing\Controllers\Stats; | |
| 4 | + | |
| 5 | +use AcyMailing\Classes\UrlClickClass; | |
| 6 | +use AcyMailing\Helpers\ExportHelper; | |
| 7 | +use AcyMailing\Helpers\PaginationHelper; | |
| 8 | + | |
| 9 | +trait UserLinksDetails | |
| 10 | +{ | |
| 11 | + public function exportUserLinksDetails(): void | |
| 12 | + { | |
| 13 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 14 | + | |
| 15 | + $data = []; | |
| 16 | + if (!$this->prepareDefaultPageInfo($data, true)) { | |
| 17 | + return; | |
| 18 | + } | |
| 19 | + | |
| 20 | + $this->prepareUserLinksDetailsListing($data); | |
| 21 | + $exportHelper = new ExportHelper(); | |
| 22 | + | |
| 23 | + $columnsToExport['user.email'] = acym_translation('ACYM_SUBSCRIBER'); | |
| 24 | + $columnsToExport['user_name'] = acym_translation('ACYM_USER_NAME'); | |
| 25 | + $columnsToExport['url_name'] = acym_translation('ACYM_URL'); | |
| 26 | + $columnsToExport['date_click'] = acym_translation('ACYM_CLICK_DATE'); | |
| 27 | + $columnsToExport['click'] = acym_translation('ACYM_TOTAL_CLICKS'); | |
| 28 | + | |
| 29 | + $exportHelper->exportStatsFullCSV($data['query'], $columnsToExport, 'user_links_details'); | |
| 30 | + exit; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public function userClickDetails(): void | |
| 34 | + { | |
| 35 | + acym_setVar('layout', 'user_links_details'); | |
| 36 | + | |
| 37 | + $data = []; | |
| 38 | + | |
| 39 | + if (!$this->prepareDefaultPageInfo($data, true)) { | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + $data['anonymousStats'] = !empty($this->config->get('anonymous_stats', 0)); | |
| 43 | + | |
| 44 | + $this->prepareUserLinksDetailsListing($data); | |
| 45 | + if (count($this->selectedMailIds) == 1) { | |
| 46 | + if ($data['isAbTest']) { | |
| 47 | + $this->prepareAbTestMails($data); | |
| 48 | + } elseif (acym_isMultilingual()) { | |
| 49 | + $this->prepareMultilingualMails($data); | |
| 50 | + } | |
| 51 | + } | |
| 52 | + $this->prepareMailFilter($data); | |
| 53 | + | |
| 54 | + parent::display($data); | |
| 55 | + } | |
| 56 | + | |
| 57 | + private function prepareUserLinksDetailsListing(array &$data): void | |
| 58 | + { | |
| 59 | + $data['search'] = $this->getVarFiltersListing('string', 'user_links_details_search', ''); | |
| 60 | + $data['ordering'] = $this->getVarFiltersListing('cmd', 'user_links_details_ordering', 'user_id'); | |
| 61 | + $data['orderingSortOrder'] = $this->getVarFiltersListing('cmd', 'user_links_details_ordering_sort_order', 'desc'); | |
| 62 | + | |
| 63 | + if (base64_encode(base64_decode($data['search'])) === $data['search']) { | |
| 64 | + $data['search'] = base64_decode($data['search']); | |
| 65 | + } | |
| 66 | + | |
| 67 | + if (empty($this->selectedMailIds)) { | |
| 68 | + return; | |
| 69 | + } | |
| 70 | + | |
| 71 | + $pagination = new PaginationHelper(); | |
| 72 | + $urlClickClass = new UrlClickClass(); | |
| 73 | + | |
| 74 | + $detailedStatsPerPage = $pagination->getListLimit(); | |
| 75 | + $page = $this->getVarFiltersListing('int', 'user_links_details_pagination_page', 1); | |
| 76 | + | |
| 77 | + $userClicks = $urlClickClass->getUserUrlClicksStats( | |
| 78 | + [ | |
| 79 | + 'ordering' => $data['ordering'], | |
| 80 | + 'search' => $data['search'], | |
| 81 | + 'detailedStatsPerPage' => $detailedStatsPerPage, | |
| 82 | + 'offset' => ($page - 1) * $detailedStatsPerPage, | |
| 83 | + 'ordering_sort_order' => $data['orderingSortOrder'], | |
| 84 | + 'mail_ids' => $this->selectedMailIds, | |
| 85 | + ] | |
| 86 | + ); | |
| 87 | + | |
| 88 | + $this->decode($userClicks['user_links_details']); | |
| 89 | + | |
| 90 | + // Prepare the pagination | |
| 91 | + $pagination->setStatus((int)$userClicks['total']->total, $page, $detailedStatsPerPage); | |
| 92 | + | |
| 93 | + $data['pagination'] = $pagination; | |
| 94 | + $data['user_links_details'] = $userClicks['user_links_details']; | |
| 95 | + $data['query'] = $userClicks['query']; | |
| 96 | + } | |
| 97 | +} | |