26 protected int $id = 0;
43 $this->db =
$DIC->database();
44 $this->
id = (
int) $a_id;
51 $this->title = $a_title;
62 $this->pool_id = $a_pool_id;
67 return $this->pool_id;
76 $this->raster = $a_raster;
90 $this->rent_min = $a_min;
95 return $this->rent_min;
104 $this->rent_max = $a_max;
109 return $this->rent_max;
115 $this->auto_break = $a_break;
120 return $this->auto_break;
128 $this->deadline = $a_deadline;
133 return $this->deadline;
142 $this->definition = $a_definition;
147 return $this->definition;
153 $this->av_from = $a_date;
158 return $this->av_from;
164 $this->av_to = $a_date;
172 protected function read(): void
177 $set =
$ilDB->query(
'SELECT title,raster,rent_min,rent_max,auto_break,' .
178 'deadline,av_from,av_to' .
179 ' FROM booking_schedule' .
180 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->id,
'integer'));
181 $row =
$ilDB->fetchAssoc($set);
182 $this->setTitle($row[
'title'] ??
"");
183 $this->setDeadline($row[
'deadline'] ?? 0);
186 if ($row[
'raster']) {
187 $this->setRaster($row[
'raster']);
188 $this->setMinRental($row[
'rent_min']);
189 $this->setMaxRental($row[
'rent_max']);
190 $this->setAutoBreak($row[
'auto_break']);
194 $definition = array();
195 $set =
$ilDB->query(
'SELECT day_id,slot_id,times' .
196 ' FROM booking_schedule_slot' .
197 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->id,
'integer'));
198 while ($row =
$ilDB->fetchAssoc($set)) {
199 $definition[$row[
"day_id"]][$row[
"slot_id"]] = $row[
"times"];
201 $this->setDefinition($definition);
213 $this->
id =
$ilDB->nextId(
'booking_schedule');
215 $av_from = ($this->getAvailabilityFrom() && !$this->getAvailabilityFrom()->isNull())
218 $av_to = ($this->getAvailabilityTo() && !$this->getAvailabilityTo()->isNull())
222 $ilDB->manipulate(
'INSERT INTO booking_schedule' .
223 ' (booking_schedule_id,title,pool_id,raster,rent_min,rent_max,auto_break,' .
224 'deadline,av_from,av_to)' .
225 ' VALUES (' .
$ilDB->quote($this->id,
'integer') .
',' .
$ilDB->quote($this->
getTitle(),
'text') .
226 ',' .
$ilDB->quote($this->getPoolId(),
'integer') .
',' .
$ilDB->quote($this->getRaster(),
'integer') .
227 ',' .
$ilDB->quote($this->getMinRental(),
'integer') .
',' .
$ilDB->quote($this->getMaxRental(),
'integer') .
228 ',' .
$ilDB->quote($this->getAutoBreak(),
'integer') .
',' .
$ilDB->quote($this->getDeadline(),
'integer') .
229 ',' .
$ilDB->quote($av_from,
'integer') .
',' .
$ilDB->quote($av_to,
'integer') .
')');
231 $this->saveDefinition();
244 $av_from = ($this->getAvailabilityFrom() && !$this->getAvailabilityFrom()->isNull())
247 $av_to = ($this->getAvailabilityTo() && !$this->getAvailabilityTo()->isNull())
251 $ilDB->manipulate(
'UPDATE booking_schedule' .
252 ' SET title = ' .
$ilDB->quote($this->getTitle(),
'text') .
253 ', pool_id = ' .
$ilDB->quote($this->getPoolId(),
'integer') .
254 ', raster = ' .
$ilDB->quote($this->getRaster(),
'integer') .
255 ', rent_min = ' .
$ilDB->quote($this->getMinRental(),
'integer') .
256 ', rent_max = ' .
$ilDB->quote($this->getMaxRental(),
'integer') .
257 ', auto_break = ' .
$ilDB->quote($this->getAutoBreak(),
'integer') .
258 ', deadline = ' .
$ilDB->quote($this->getDeadline(),
'integer') .
259 ', av_from = ' .
$ilDB->quote($av_from,
'integer') .
260 ', av_to = ' .
$ilDB->quote($av_to,
'integer') .
261 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->
id,
'integer'));
263 $this->saveDefinition();
269 $new_obj =
new self();
270 $new_obj->setPoolId($a_pool_id);
271 $new_obj->setTitle($this->
getTitle());
272 $new_obj->setRaster($this->getRaster());
273 $new_obj->setMinRental($this->getMinRental());
274 $new_obj->setMaxRental($this->getMaxRental());
275 $new_obj->setAutoBreak($this->getAutoBreak());
276 $new_obj->setDeadline($this->getDeadline());
277 $new_obj->setDefinition($this->getDefinition());
278 $new_obj->setAvailabilityFrom($this->getAvailabilityFrom());
279 $new_obj->setAvailabilityTo($this->getAvailabilityTo());
280 return $new_obj->save();
294 $ilDB->manipulate(
'DELETE FROM booking_schedule_slot' .
295 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->id,
'integer'));
297 $definition = $this->getDefinition();
299 foreach ($definition as $day_id => $slots) {
300 foreach ($slots as $slot_id => $times) {
302 "booking_schedule_id" => array(
'integer', $this->
id),
303 "day_id" => array(
'text', $day_id),
304 "slot_id" => array(
'integer', $slot_id),
305 "times" => array(
'text', $times)
307 $ilDB->insert(
'booking_schedule_slot', $fields);
323 $set =
$ilDB->query(
"SELECT booking_schedule_id" .
324 " FROM booking_schedule" .
325 " WHERE pool_id = " .
$ilDB->quote($a_pool_id,
'integer'));
326 return (
bool)
$ilDB->numRows($set);
332 public static function getList(
int $a_pool_id): array
338 $set =
$ilDB->query(
'SELECT s.booking_schedule_id,s.title,' .
339 'MAX(o.schedule_id) AS object_has_schedule' .
340 ' FROM booking_schedule s' .
341 ' LEFT JOIN booking_object o ON (s.booking_schedule_id = o.schedule_id)' .
342 ' WHERE s.pool_id = ' .
$ilDB->quote($a_pool_id,
'integer') .
343 ' GROUP BY s.booking_schedule_id,s.title' .
344 ' ORDER BY s.title');
346 while ($row =
$ilDB->fetchAssoc($set)) {
347 if (!$row[
'object_has_schedule']) {
348 $row[
'is_used'] =
false;
350 $row[
'is_used'] =
true;
357 public function delete():
int
362 return $ilDB->manipulate(
'DELETE FROM booking_schedule' .
363 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->id,
'integer'));
373 $def = $this->getDefinition();
375 foreach ($def as $day => $times) {
376 foreach ($times as $time) {
377 $slots[$time][] = $day;
380 foreach ($slots as $time => $days) {
381 $slots[$time] = array_unique($days);
390 foreach ($a_def as $time => $days) {
391 foreach ($days as $day) {
392 $slots[$day][] = $time;
395 $this->setDefinition($slots);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setAvailabilityFrom(?ilDateTime $a_date=null)
setPoolId(int $a_pool_id)
static hasExistingSchedules(int $a_pool_id)
Check if given pool has any defined schedules.
setTitle(string $a_title)
setRaster(int $a_raster)
Set booking raster (in minutes)
setDefinitionBySlots(array $a_def)
setMinRental(int $a_min)
Set minimum rental time.
static getList(int $a_pool_id)
Get list of booking objects for given pool.
setMaxRental(int $a_max)
Set maximum rental time.
setAutoBreak(int $a_break)
saveDefinition()
Save current definition (slots)
getDefinitionBySlots()
Return definition grouped by slots (not days)
setDeadline(int $a_deadline)
Set deadline.
setAvailabilityTo(?ilDateTime $a_date=null)
setDefinition(array $a_definition)
Set definition.
__construct(?int $a_id=null)
@classDescription Date and time handling
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date