Analytics.php
2 years ago
Reporter.php
1 year ago
ReporterCampaignData.php
2 years ago
UnsubscribeReporter.php
3 years ago
index.php
3 years ago
UnsubscribeReporter.php
49 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Analytics; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\StatisticsUnsubscribeEntity; |
| 9 | use MailPoet\Statistics\StatisticsUnsubscribesRepository; |
| 10 | |
| 11 | class UnsubscribeReporter { |
| 12 | |
| 13 | public const TOTAL = 'Unsubscribe > Total in last 6 months'; |
| 14 | public const COUNT_PER_METHOD_PATTERN = 'Unsubscribe > Count in last 6 months with method: %s'; |
| 15 | |
| 16 | /*** @var StatisticsUnsubscribesRepository */ |
| 17 | private $statisticsUnsubscribesRepository; |
| 18 | |
| 19 | public function __construct( |
| 20 | StatisticsUnsubscribesRepository $statisticsUnsubscribesRepository |
| 21 | ) { |
| 22 | $this->statisticsUnsubscribesRepository = $statisticsUnsubscribesRepository; |
| 23 | } |
| 24 | |
| 25 | public function getProperties(): array { |
| 26 | $properties = [ |
| 27 | self::TOTAL => $this->statisticsUnsubscribesRepository->getTotalForMonths(6), |
| 28 | ]; |
| 29 | |
| 30 | foreach ($this->statisticsUnsubscribesRepository->getCountPerMethodForMonths(6) as $methodStats) { |
| 31 | $properties[sprintf(self::COUNT_PER_METHOD_PATTERN, $this->getMethodName($methodStats['method']))] = $methodStats['count']; |
| 32 | } |
| 33 | |
| 34 | return $properties; |
| 35 | } |
| 36 | |
| 37 | private function getMethodName(?string $methodKey): string { |
| 38 | if ($methodKey === StatisticsUnsubscribeEntity::METHOD_ONE_CLICK) { |
| 39 | return '1 Click'; |
| 40 | } |
| 41 | |
| 42 | if ($methodKey === StatisticsUnsubscribeEntity::METHOD_LINK) { |
| 43 | return 'Link'; |
| 44 | } |
| 45 | |
| 46 | return 'Unknown'; |
| 47 | } |
| 48 | } |
| 49 |