PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.32
Booking for Appointments and Events Calendar – Amelia v1.2.32
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 / Coupon / CouponServiceRepository.php
ameliabooking / src / Infrastructure / Repository / Coupon Last commit date
CouponEventRepository.php 1 year ago CouponPackageRepository.php 1 year ago CouponRepository.php 1 year ago CouponServiceRepository.php 1 year ago
CouponServiceRepository.php
83 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Coupon;
4
5 use AmeliaBooking\Domain\Entity\Bookable\Service\Service;
6 use AmeliaBooking\Domain\Entity\Coupon\Coupon;
7 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
8 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
9
10 /**
11 * Class CouponServiceRepository
12 *
13 * @package AmeliaBooking\Infrastructure\Repository\Coupon
14 */
15 class CouponServiceRepository extends AbstractRepository
16 {
17 /**
18 * @param Coupon $coupon
19 * @param Service $service
20 *
21 * @return mixed
22 * @throws QueryExecutionException
23 */
24 public function add($coupon, $service)
25 {
26 $couponData = $coupon->toArray();
27 $serviceData = $service->toArray();
28
29 $params = [
30 ':couponId' => $couponData['id'],
31 ':serviceId' => $serviceData['id'],
32 ];
33
34 try {
35 $statement = $this->connection->prepare(
36 "INSERT INTO {$this->table}
37 (
38 `couponId`,
39 `serviceId`
40 )
41 VALUES (
42 :couponId,
43 :serviceId
44 )"
45 );
46
47 $res = $statement->execute($params);
48 if (!$res) {
49 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
50 }
51
52 return $this->connection->lastInsertId();
53 } catch (\Exception $e) {
54 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
55 }
56 }
57
58 /**
59 * @param int $couponId
60 * @param int $serviceId
61 *
62 * @return mixed
63 * @throws QueryExecutionException
64 */
65 public function deleteForService($couponId, $serviceId)
66 {
67 $params = [
68 ':couponId' => $couponId,
69 ':serviceId' => $serviceId,
70 ];
71
72 try {
73 $statement = $this->connection->prepare(
74 "DELETE FROM {$this->table} WHERE couponId = :couponId AND serviceId = :serviceId"
75 );
76
77 return $statement->execute($params);
78 } catch (\Exception $e) {
79 throw new QueryExecutionException('Unable to delete data from ' . __CLASS__, $e->getCode(), $e);
80 }
81 }
82 }
83