Replace usages of StatisticsForms with Doctrine
[MAILPOET-3032]
This commit is contained in:
@ -3,7 +3,9 @@
|
||||
namespace MailPoet\Statistics;
|
||||
|
||||
use MailPoet\Doctrine\Repository;
|
||||
use MailPoet\Entities\FormEntity;
|
||||
use MailPoet\Entities\StatisticsFormEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
|
||||
/**
|
||||
* @extends Repository<StatisticsFormEntity>
|
||||
@ -12,4 +14,24 @@ class StatisticsFormsRepository extends Repository {
|
||||
protected function getEntityClassName() {
|
||||
return StatisticsFormEntity::class;
|
||||
}
|
||||
|
||||
public function getTotalSignups(int $formId): int {
|
||||
return $this->countBy(['form' => $formId]);
|
||||
}
|
||||
|
||||
public function record(FormEntity $form, SubscriberEntity $subscriber): ?StatisticsFormEntity {
|
||||
if ($form->getId() > 0 && $subscriber->getId() > 0) {
|
||||
// check if we already have a record for today
|
||||
$statisticsForm = $this->findOneBy(['form' => $form, 'subscriber' => $subscriber]);
|
||||
|
||||
if (!$statisticsForm) {
|
||||
// create a new entry
|
||||
$statisticsForm = new StatisticsFormEntity($form, $subscriber);
|
||||
$this->persist($statisticsForm);
|
||||
$this->flush();
|
||||
}
|
||||
return $statisticsForm;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user