PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 3.89.3
MailPoet – Newsletters, Email Marketing, and Automation v3.89.3
5.38.0 5.37.0 5.36.1 5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 All 542 releases
mailpoet / lib / Statistics / StatisticsFormsRepository.php

StatisticsFormsRepository.php in MailPoet – Newsletters, Email Marketing, and Automation 3.89.3, at lib/Statistics/StatisticsFormsRepository.php

41 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
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