ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimplePDO.php
Go to the documentation of this file.
1<?php
2
4
6use Sabre\DAV;
7
35
41 protected $pdo;
42
48 function __construct(\PDO $pdo) {
49
50 $this->pdo = $pdo;
51
52 }
53
78 function getCalendarsForUser($principalUri) {
79
80 // Making fields a comma-delimited list
81 $stmt = $this->pdo->prepare("SELECT id, uri FROM simple_calendars WHERE principaluri = ? ORDER BY id ASC");
82 $stmt->execute([$principalUri]);
83
84 $calendars = [];
85 while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
86
87 $calendars[] = [
88 'id' => $row['id'],
89 'uri' => $row['uri'],
90 'principaluri' => $principalUri,
91 ];
92
93 }
94
95 return $calendars;
96
97 }
98
110 function createCalendar($principalUri, $calendarUri, array $properties) {
111
112 $stmt = $this->pdo->prepare("INSERT INTO simple_calendars (principaluri, uri) VALUES (?, ?)");
113 $stmt->execute([$principalUri, $calendarUri]);
114
115 return $this->pdo->lastInsertId();
116
117 }
118
125 function deleteCalendar($calendarId) {
126
127 $stmt = $this->pdo->prepare('DELETE FROM simple_calendarobjects WHERE calendarid = ?');
128 $stmt->execute([$calendarId]);
129
130 $stmt = $this->pdo->prepare('DELETE FROM simple_calendars WHERE id = ?');
131 $stmt->execute([$calendarId]);
132
133 }
134
166 function getCalendarObjects($calendarId) {
167
168 $stmt = $this->pdo->prepare('SELECT id, uri, calendardata FROM simple_calendarobjects WHERE calendarid = ?');
169 $stmt->execute([$calendarId]);
170
171 $result = [];
172 foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
173 $result[] = [
174 'id' => $row['id'],
175 'uri' => $row['uri'],
176 'etag' => '"' . md5($row['calendardata']) . '"',
177 'calendarid' => $calendarId,
178 'size' => strlen($row['calendardata']),
179 'calendardata' => $row['calendardata'],
180 ];
181 }
182
183 return $result;
184
185 }
186
203 function getCalendarObject($calendarId, $objectUri) {
204
205 $stmt = $this->pdo->prepare('SELECT id, uri, calendardata FROM simple_calendarobjects WHERE calendarid = ? AND uri = ?');
206 $stmt->execute([$calendarId, $objectUri]);
207 $row = $stmt->fetch(\PDO::FETCH_ASSOC);
208
209 if (!$row) return null;
210
211 return [
212 'id' => $row['id'],
213 'uri' => $row['uri'],
214 'etag' => '"' . md5($row['calendardata']) . '"',
215 'calendarid' => $calendarId,
216 'size' => strlen($row['calendardata']),
217 'calendardata' => $row['calendardata'],
218 ];
219
220 }
221
240 function createCalendarObject($calendarId, $objectUri, $calendarData) {
241
242 $stmt = $this->pdo->prepare('INSERT INTO simple_calendarobjects (calendarid, uri, calendardata) VALUES (?,?,?)');
243 $stmt->execute([
244 $calendarId,
245 $objectUri,
246 $calendarData
247 ]);
248
249 return '"' . md5($calendarData) . '"';
250
251 }
252
271 function updateCalendarObject($calendarId, $objectUri, $calendarData) {
272
273 $stmt = $this->pdo->prepare('UPDATE simple_calendarobjects SET calendardata = ? WHERE calendarid = ? AND uri = ?');
274 $stmt->execute([$calendarData, $calendarId, $objectUri]);
275
276 return '"' . md5($calendarData) . '"';
277
278 }
279
289 function deleteCalendarObject($calendarId, $objectUri) {
290
291 $stmt = $this->pdo->prepare('DELETE FROM simple_calendarobjects WHERE calendarid = ? AND uri = ?');
292 $stmt->execute([$calendarId, $objectUri]);
293
294 }
295
296}
$result
An exception for terminatinating execution or to throw for unit testing.
Abstract Calendaring backend.
PDO CalDAV backend.
Definition: PDO.php:26
Simple PDO CalDAV backend.
Definition: SimplePDO.php:34
getCalendarObject($calendarId, $objectUri)
Returns information from a single calendar object, based on it's object uri.
Definition: SimplePDO.php:203
getCalendarObjects($calendarId)
Returns all calendar objects within a calendar.
Definition: SimplePDO.php:166
deleteCalendarObject($calendarId, $objectUri)
Deletes an existing calendar object.
Definition: SimplePDO.php:289
createCalendarObject($calendarId, $objectUri, $calendarData)
Creates a new calendar object.
Definition: SimplePDO.php:240
deleteCalendar($calendarId)
Delete a calendar and all it's objects.
Definition: SimplePDO.php:125
__construct(\PDO $pdo)
Creates the backend.
Definition: SimplePDO.php:48
updateCalendarObject($calendarId, $objectUri, $calendarData)
Updates an existing calendarobject, based on it's uri.
Definition: SimplePDO.php:271
createCalendar($principalUri, $calendarUri, array $properties)
Creates a new calendar for a principal.
Definition: SimplePDO.php:110
getCalendarsForUser($principalUri)
Returns a list of calendars for a principal.
Definition: SimplePDO.php:78
$row
$stmt