Track
5 days ago
GATracking.php
6 months ago
StatisticsBouncesRepository.php
3 years ago
StatisticsClicksRepository.php
2 years ago
StatisticsFormsRepository.php
3 years ago
StatisticsNewslettersRepository.php
1 year ago
StatisticsOpensRepository.php
3 days ago
StatisticsUnsubscribesRepository.php
2 months ago
StatisticsWooCommercePurchasesRepository.php
1 year ago
UnsubscribeReasonTracker.php
2 months ago
UserAgentsRepository.php
1 year ago
index.php
3 years ago
StatisticsFormsRepository.php
41 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Statistics; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Doctrine\Repository; |
| 9 | use MailPoet\Entities\FormEntity; |
| 10 | use MailPoet\Entities\StatisticsFormEntity; |
| 11 | use MailPoet\Entities\SubscriberEntity; |
| 12 | |
| 13 | /** |
| 14 | * @extends Repository<StatisticsFormEntity> |
| 15 | */ |
| 16 | class StatisticsFormsRepository extends Repository { |
| 17 | protected function getEntityClassName() { |
| 18 | return StatisticsFormEntity::class; |
| 19 | } |
| 20 | |
| 21 | public function getTotalSignups(int $formId): int { |
| 22 | return $this->countBy(['form' => $formId]); |
| 23 | } |
| 24 | |
| 25 | public function record(FormEntity $form, SubscriberEntity $subscriber): ?StatisticsFormEntity { |
| 26 | if ($form->getId() > 0 && $subscriber->getId() > 0) { |
| 27 | // check if we already have a record for today |
| 28 | $statisticsForm = $this->findOneBy(['form' => $form, 'subscriber' => $subscriber]); |
| 29 | |
| 30 | if (!$statisticsForm) { |
| 31 | // create a new entry |
| 32 | $statisticsForm = new StatisticsFormEntity($form, $subscriber); |
| 33 | $this->persist($statisticsForm); |
| 34 | $this->flush(); |
| 35 | } |
| 36 | return $statisticsForm; |
| 37 | } |
| 38 | return null; |
| 39 | } |
| 40 | } |
| 41 |