PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.1
Booking for Appointments and Events Calendar – Amelia v2.0.1
2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / Repository / Notification / NotificationsToEntitiesRepository.php
ameliabooking / src / Infrastructure / Repository / Notification Last commit date
NotificationLogRepository.php 1 year ago NotificationRepository.php 6 months ago NotificationSMSHistoryRepository.php 6 months ago NotificationsToEntitiesRepository.php 1 year ago
NotificationsToEntitiesRepository.php
134 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Notification;
4
5 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
6 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
7 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
8 use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Notification\NotificationsTable;
9 use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Notification\NotificationsToEntitiesTable;
10
11 class NotificationsToEntitiesRepository extends AbstractRepository
12 {
13 /**
14 * @param $notificationId
15 *
16 * @return array
17 * @throws QueryExecutionException
18 * @throws InvalidArgumentException
19 */
20 public function getEntities($notificationId)
21 {
22 try {
23 $statement = $this->connection->prepare(
24 "SELECT entityId FROM {$this->table} WHERE notificationId = :id"
25 );
26
27 $params = [
28 ':id' => $notificationId
29 ];
30
31 $statement->execute($params);
32
33 $entityRows = $statement->fetchAll();
34 } catch (\Exception $e) {
35 throw new QueryExecutionException('Unable to get entities in ' . __CLASS__, $e->getCode(), $e);
36 }
37
38 return array_column($entityRows, 'entityId');
39 }
40
41 /**
42 * @param int $notificationId
43 * @param int $entityId
44 * @param string $entity
45 *
46 * @return bool
47 * @throws QueryExecutionException
48 * @throws InvalidArgumentException
49 */
50 public function removeEntity($notificationId, $entityId, $entity)
51 {
52 $params = [
53 ':notificationId' => $notificationId,
54 ':entity' => $entity,
55 ':entityId' => $entityId
56 ];
57
58 try {
59 $statement = $this->connection->prepare(
60 "DELETE FROM {$this->table} WHERE notificationId = :notificationId AND entity = :entity AND entityId = :entityId"
61 );
62
63 return $statement->execute($params);
64 } catch (\Exception $e) {
65 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e);
66 }
67 }
68
69
70 /**
71 * @param $entityId
72 *
73 * @return bool
74 * @throws QueryExecutionException
75 * @throws InvalidArgumentException
76 */
77 public function removeIfOnly($entityId)
78 {
79 $notificationsTable = NotificationsTable::getTableName();
80 try {
81 $statement = $this->connection->prepare(
82 "DELETE n FROM {$notificationsTable} n
83 INNER JOIN {$this->table} ne ON n.id = ne.notificationId
84 WHERE ne.entityId = :id
85 AND NOT EXISTS (SELECT * FROM {$this->table} ne2 WHERE ne2.entityId <> ne.entityId AND ne2.notificationId = n.id)"
86 );
87
88 $params = [
89 ':id' => $entityId
90 ];
91
92 $success1 = $statement->execute($params);
93
94 $statement = $this->connection->prepare(
95 "DELETE FROM {$this->table} WHERE entityId = :id"
96 );
97
98 $success2 = $statement->execute($params);
99
100 return $success1 && $success2;
101 } catch (\Exception $e) {
102 throw new QueryExecutionException('Unable to get entities in ' . __CLASS__, $e->getCode(), $e);
103 }
104 }
105
106 /**
107 * @param int $notificationId
108 * @param int $entityId
109 * @param string $entity
110 *
111 * @return bool
112 * @throws QueryExecutionException
113 * @throws InvalidArgumentException
114 */
115 public function addEntity($notificationId, $entityId, $entity)
116 {
117 $params = [
118 ':notificationId' => $notificationId,
119 ':entity' => $entity,
120 ':entityId' => $entityId
121 ];
122
123 try {
124 $statement = $this->connection->prepare(
125 "INSERT INTO {$this->table} (`notificationId`, `entity`, `entityId`) VALUES (:notificationId, :entity, :entityId)"
126 );
127
128 return $statement->execute($params);
129 } catch (\Exception $e) {
130 throw new QueryExecutionException('Unable to add data from ' . __CLASS__, $e->getCode(), $e);
131 }
132 }
133 }
134