PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 3.65.0
MailPoet – Newsletters, Email Marketing, and Automation v3.65.0
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 / Form / FormsRepository.php

FormsRepository.php in MailPoet – Newsletters, Email Marketing, and Automation 3.65.0, at lib/Form/FormsRepository.php

95 lines 2.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\Form;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use MailPoet\Doctrine\Repository;
9 use MailPoet\Entities\FormEntity;
10
11 /**
12 * @extends Repository<FormEntity>
13 */
14 class FormsRepository extends Repository {
15 protected function getEntityClassName() {
16 return FormEntity::class;
17 }
18
19 /**
20 * @return FormEntity[]
21 */
22 public function findAllNotDeleted(): array {
23 return $this->entityManager
24 ->createQueryBuilder()
25 ->select('f')
26 ->from(FormEntity::class, 'f')
27 ->where('f.deletedAt IS NULL')
28 ->orderBy('f.updatedAt', 'desc')
29 ->getQuery()
30 ->getResult();
31 }
32
33 public function count(): int {
34 return (int)$this->doctrineRepository
35 ->createQueryBuilder('f')
36 ->select('count(f.id)')
37 ->getQuery()
38 ->getSingleScalarResult();
39 }
40
41 public function delete(FormEntity $form) {
42 $this->entityManager->remove($form);
43 $this->flush();
44 }
45
46 public function trash(FormEntity $form) {
47 $this->bulkTrash([$form->getId()]);
48 $this->entityManager->refresh($form);
49 }
50
51 public function restore(FormEntity $form) {
52 $this->bulkRestore([$form->getId()]);
53 $this->entityManager->refresh($form);
54 }
55
56 public function bulkTrash(array $ids): int {
57 if (empty($ids)) {
58 return 0;
59 }
60
61 return $this->entityManager->createQueryBuilder()
62 ->update(FormEntity::class, 'f')
63 ->set('f.deletedAt', 'CURRENT_TIMESTAMP()')
64 ->where('f.id IN (:ids)')
65 ->setParameter('ids', $ids)
66 ->getQuery()->execute();
67 }
68
69 public function bulkRestore(array $ids): int {
70 if (empty($ids)) {
71 return 0;
72 }
73
74 return $this->entityManager->createQueryBuilder()
75 ->update(FormEntity::class, 'f')
76 ->set('f.deletedAt', ':deletedAt')
77 ->where('f.id IN (:ids)')
78 ->setParameter('deletedAt', null)
79 ->setParameter('ids', $ids)
80 ->getQuery()->execute();
81 }
82
83 public function bulkDelete(array $ids): int {
84 if (empty($ids)) {
85 return 0;
86 }
87
88 return $this->entityManager->createQueryBuilder()
89 ->delete(FormEntity::class, 'f')
90 ->where('f.id IN (:ids)')
91 ->setParameter('ids', $ids)
92 ->getQuery()->execute();
93 }
94 }
95