PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / Outlook / OutlookCalendarRepository.php
ameliabooking / src / Infrastructure / Repository / Outlook Last commit date
OutlookCalendarRepository.php 5 years ago
OutlookCalendarRepository.php
116 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\Outlook;
4
5 use AmeliaBooking\Domain\Entity\Outlook\OutlookCalendar;
6 use AmeliaBooking\Domain\Factory\Outlook\OutlookCalendarFactory;
7 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
8 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
9 use AmeliaBooking\Infrastructure\Repository\AbstractRepository;
10 use Exception;
11
12 /**
13 * Class OutlookCalendarRepository
14 *
15 * @package AmeliaBooking\Infrastructure\Repository\Outlook
16 */
17 class OutlookCalendarRepository extends AbstractRepository
18 {
19 const FACTORY = OutlookCalendarFactory::class;
20
21 /**
22 * @param OutlookCalendar $outlookCalendar
23 * @param int $userId
24 *
25 * @return string
26 * @throws QueryExecutionException
27 */
28 public function add($outlookCalendar, $userId)
29 {
30 $data = $outlookCalendar->toArray();
31
32 $params = [
33 ':userId' => $userId,
34 ':token' => $data['token']
35 ];
36
37 try {
38 $statement = $this->connection->prepare(
39 "INSERT INTO {$this->table}
40 (`userId`, `token`)
41 VALUES
42 (:userId, :token)"
43 );
44
45 $res = $statement->execute($params);
46
47 if (!$res) {
48 throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
49 }
50 } catch (Exception $e) {
51 throw new QueryExecutionException('Unable to add data in ' . __CLASS__, $e->getCode(), $e);
52 }
53
54 return $this->connection->lastInsertId();
55 }
56
57 /**
58 * @param OutlookCalendar $outlookCalendar
59 * @param int $id
60 *
61 * @return mixed
62 * @throws QueryExecutionException
63 */
64 public function update($outlookCalendar, $id)
65 {
66 $data = $outlookCalendar->toArray();
67
68 $params = [
69 ':token' => $data['token'],
70 ':calendarId' => $data['calendarId'],
71 ':id' => $id
72 ];
73
74 try {
75 $statement = $this->connection->prepare(
76 "UPDATE {$this->table}
77 SET `token` = :token, `calendarId` = :calendarId WHERE id = :id"
78 );
79
80 $res = $statement->execute($params);
81 if (!$res) {
82 throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
83 }
84
85 return $res;
86 } catch (Exception $e) {
87 throw new QueryExecutionException('Unable to save data in ' . __CLASS__, $e->getCode(), $e);
88 }
89 }
90
91 /**
92 * @param $userId
93 *
94 * @return mixed
95 * @throws NotFoundException
96 * @throws QueryExecutionException
97 */
98 public function getByProviderId($userId)
99 {
100 try {
101 $statement = $this->connection->prepare($this->selectQuery() . " WHERE {$this->table}.userId = :userId");
102 $statement->bindParam(':userId', $userId);
103 $statement->execute();
104 $row = $statement->fetch();
105 } catch (Exception $e) {
106 throw new QueryExecutionException('Unable to find by id in ' . __CLASS__, $e->getCode(), $e);
107 }
108
109 if (!$row) {
110 throw new NotFoundException('Data not found in ' . __CLASS__);
111 }
112
113 return call_user_func([static::FACTORY, 'create'], $row);
114 }
115 }
116