PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / Booking / Event / EventPeriodsRepository.php
ameliabooking / src / Infrastructure / Repository / Booking / Event Last commit date
CustomerBookingEventPeriodRepository.php 6 years ago CustomerBookingEventTicketRepository.php 1 year ago EventPeriodsRepository.php 4 years ago EventProvidersRepository.php 6 years ago EventRepository.php 1 year ago EventTagsRepository.php 6 years ago EventTicketRepository.php 1 year ago
EventPeriodsRepository.php
104 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Booking\Event;
4
5 use AmeliaBooking\Domain\Entity\Booking\Event\EventPeriod;
6 use AmeliaBooking\Domain\Factory\Booking\Event\EventFactory;
7 use AmeliaBooking\Domain\Factory\Booking\Event\EventPeriodFactory;
8 use AmeliaBooking\Domain\Repository\Booking\Event\EventRepositoryInterface;
9 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
10 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
11 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
12
13 /**
14 * Class EventPeriodsRepository
15 *
16 * @package AmeliaBooking\Infrastructure\Repository\Booking\Event
17 */
18 class EventPeriodsRepository extends AbstractRepository implements EventRepositoryInterface
19 {
20
21 const FACTORY = EventPeriodFactory::class;
22
23 /**
24 * @param EventPeriod $entity
25 *
26 * @return bool
27 * @throws QueryExecutionException
28 */
29 public function add($entity)
30 {
31 $data = $entity->toArray();
32
33 $params = [
34 ':eventId' => $data['eventId'],
35 ':periodStart' => DateTimeService::getCustomDateTimeInUtc($data['periodStart']),
36 ':periodEnd' => DateTimeService::getCustomDateTimeInUtc($data['periodEnd']),
37 ];
38
39 try {
40 $statement = $this->connection->prepare(
41 "INSERT INTO {$this->table}
42 (
43 `eventId`,
44 `periodStart`,
45 `periodEnd`
46 )
47 VALUES (
48 :eventId,
49 :periodStart,
50 :periodEnd
51 )"
52 );
53
54 $res = $statement->execute($params);
55
56 if (!$res) {
57 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
58 }
59
60 return $this->connection->lastInsertId();
61 } catch (\Exception $e) {
62 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
63 }
64 }
65
66 /**
67 * @param int $id
68 * @param EventPeriod $entity
69 *
70 * @return mixed
71 * @throws QueryExecutionException
72 */
73 public function update($id, $entity)
74 {
75 $data = $entity->toArray();
76
77 $params = [
78 ':id' => $id,
79 ':periodStart' => DateTimeService::getCustomDateTimeInUtc($data['periodStart']),
80 ':periodEnd' => DateTimeService::getCustomDateTimeInUtc($data['periodEnd'])
81 ];
82
83 try {
84 $statement = $this->connection->prepare(
85 "UPDATE {$this->table}
86 SET
87 `periodStart` = :periodStart,
88 `periodEnd` = :periodEnd
89 WHERE id = :id"
90 );
91
92 $res = $statement->execute($params);
93
94 if (!$res) {
95 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
96 }
97
98 return $res;
99 } catch (\Exception $e) {
100 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
101 }
102 }
103 }
104