ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IliasDBEmployeeTalkRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ilDateTime;
26use ilDate;
27use ilTimeZone;
29
31{
33
35 {
36 $this->database = $database;
37 }
38
42 public function findAll(): array
43 {
44 $result = $this->database->query('SELECT * FROM etal_data');
45 $talks = [];
46 while ($row = $result->fetchObject()) {
47 $talks[] = $this->parseFromStdClass($row);
48 }
49 return $talks;
50 }
51
56 public function findByEmployees(array $employees): array
57 {
58 $result = $this->database->query(
59 'SELECT * FROM etal_data AS talk
60 WHERE ' . $this->database->in('employee', $employees, false, 'integer')
61 );
62 $talks = [];
63 while ($row = $result->fetchObject()) {
64 $talks[] = $this->parseFromStdClass($row);
65 }
66 return $talks;
67 }
68
74 public function findByUserOrTheirEmployees(int $user, array $employees): array
75 {
76 $result = $this->database->query($q = 'SELECT * FROM etal_data AS talk
77 INNER JOIN object_data AS od ON od.obj_id = talk.object_id
78 WHERE (' . $this->database->in('employee', $employees, false, 'integer') .
79 ' AND ' . $this->database->in('od.owner', $employees, false, 'integer') .
80 ') OR od.owner = ' . $this->database->quote($user, 'integer') .
81 ' OR employee = ' . $this->database->quote($user, 'integer'));
82 $talks = [];
83 while ($row = $result->fetchObject()) {
84 $talks[] = $this->parseFromStdClass($row);
85 }
86 return $talks;
87 }
88
94 public function findTalksBetweenEmployeeAndOwner(int $employee, int $owner): array
95 {
96 $result = $this->database->query('SELECT * FROM etal_data AS talk
97 INNER JOIN object_data AS od ON od.obj_id = talk.object_id
98 WHERE talk.employee = ' . $this->database->quote($employee, 'integer') .
99 ' AND od.owner = ' . $this->database->quote($owner, 'integer'));
100 $talks = [];
101 while ($row = $result->fetchObject()) {
102 $talks[] = $this->parseFromStdClass($row);
103 }
104 return $talks;
105 }
106
107 public function findByObjectId(int $objectId): EmployeeTalk
108 {
109 $result = $this->database->query('SELECT * FROM etal_data WHERE object_id = ' .
110 $this->database->quote($objectId, 'integer'));
111 while ($row = $result->fetchObject()) {
112 return $this->parseFromStdClass($row);
113 }
114 throw new \ilEmployeeTalkDBException('No EmployeeTalk found with obj_id ' . $objectId);
115 }
116
117 public function create(EmployeeTalk $talk): EmployeeTalk
118 {
119 $this->database->insert('etal_data', [
120 'object_id' => ['int', $talk->getObjectId()],
121 'series_id' => ['text', $talk->getSeriesId()],
122 'start_date' => ['int', $talk->getStartDate()->getUnixTime()],
123 'end_date' => ['int', $talk->getEndDate()->getUnixTime()],
124 'all_day' => ['int', (int) $talk->isAllDay()],
125 'location' => ['text', $talk->getLocation()],
126 'employee' => ['int', $talk->getEmployee()],
127 'completed' => ['int', (int) $talk->isCompleted()],
128 'standalone_date' => ['int', (int) $talk->isStandalone()],
129 'template_id' => ['int', $talk->getTemplateId()]
130 ]);
131
132 return $talk;
133 }
134
135 public function update(EmployeeTalk $talk): EmployeeTalk
136 {
137 $this->database->update('etal_data', [
138 'series_id' => ['text', $talk->getSeriesId()],
139 'start_date' => ['int', $talk->getStartDate()->getUnixTime()],
140 'end_date' => ['int', $talk->getEndDate()->getUnixTime()],
141 'all_day' => ['int', (int) $talk->isAllDay()],
142 'location' => ['text', $talk->getLocation()],
143 'employee' => ['int', $talk->getEmployee()],
144 'completed' => ['int', (int) $talk->isCompleted()],
145 'standalone_date' => ['int', (int) $talk->isStandalone()],
146 'template_id' => ['int', $talk->getTemplateId()]
147 ], [
148 'object_id' => ['int', $talk->getObjectId()]
149 ]);
150
151 return $talk;
152 }
153
154 public function delete(EmployeeTalk $talk): void
155 {
156 $this->database->manipulate('DELETE FROM etal_data WHERE object_id = ' .
157 $this->database->quote($talk->getObjectId(), 'integer'));
158 }
159
164 public function findByEmployee(int $iliasUserId): array
165 {
166 $result = $this->database->query('SELECT * FROM etal_data WHERE employee = ' .
167 $this->database->quote($iliasUserId, 'integer'));
168 $talks = [];
169 while ($row = $result->fetchObject()) {
170 $talks[] = $this->parseFromStdClass($row);
171 }
172 return $talks;
173 }
174
179 public function findBySeries(string $seriesId): array
180 {
181 $result = $this->database->query('SELECT * FROM etal_data WHERE series_id = ' .
182 $this->database->quote($seriesId, 'text'));
183 $talks = [];
184 while ($row = $result->fetchObject()) {
185 $talks[] = $this->parseFromStdClass($row);
186 }
187 return $talks;
188 }
189
190 private function parseFromStdClass($stdClass): EmployeeTalk
191 {
192 $all_day = boolval($stdClass->all_day);
193 if ($all_day) {
194 $start_date = new ilDate($stdClass->start_date, IL_CAL_UNIX);
195 $end_date = new ilDate($stdClass->end_date, IL_CAL_UNIX);
196 } else {
197 $start_date = new ilDateTime($stdClass->start_date, IL_CAL_UNIX, ilTimeZone::UTC);
198 $end_date = new ilDateTime($stdClass->end_date, IL_CAL_UNIX, ilTimeZone::UTC);
199 }
200
201 return new EmployeeTalk(
202 intval($stdClass->object_id),
203 $start_date,
204 $end_date,
205 $all_day,
206 $stdClass->series_id ?? '',
207 $stdClass->location ?? '',
208 intval($stdClass->employee),
209 boolval($stdClass->completed),
210 boolval($stdClass->standalone_date),
211 intval($stdClass->template_id)
212 );
213 }
214}
const IL_CAL_UNIX
@classDescription Date and time handling
Class for single dates.
This class offers methods for timezone handling.
Interface ilDBInterface.
$q
Definition: shib_logout.php:23