30 protected int $id = 0;
48 $this->db =
$DIC->database();
49 $this->
id = (
int) $a_id;
56 $this->title = $a_title;
67 $this->pool_id = $a_pool_id;
72 return $this->pool_id;
81 $this->raster = $a_raster;
95 $this->rent_min = $a_min;
100 return $this->rent_min;
109 $this->rent_max = $a_max;
114 return $this->rent_max;
120 $this->auto_break = $a_break;
125 return $this->auto_break;
133 $this->deadline = $a_deadline;
138 return $this->deadline;
147 $this->definition = $a_definition;
152 return $this->definition;
158 $this->av_from = $a_date;
163 return $this->av_from;
169 $this->av_to = $a_date;
179 return $this->schedule_type;
184 $this->schedule_type = $a_schedule_type;
187 protected function read(): void
192 $set =
$ilDB->query(
'SELECT title,raster,rent_min,rent_max,auto_break,' .
193 'deadline,av_from,av_to,schedule_type' .
194 ' FROM booking_schedule' .
195 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->id,
'integer'));
196 $row =
$ilDB->fetchAssoc($set);
197 $this->setTitle($row[
'title'] ??
"");
198 $this->setDeadline($row[
'deadline'] ?? 0);
201 if ($row[
'raster']) {
202 $this->setRaster($row[
'raster']);
203 $this->setMinRental($row[
'rent_min']);
204 $this->setMaxRental($row[
'rent_max']);
205 $this->setAutoBreak($row[
'auto_break']);
207 $this->setScheduleType($row[
'schedule_type'] ?? self::SCHEDULE_TYPE_TIME_PERIOD);
210 $definition = array();
211 $set =
$ilDB->query(
'SELECT day_id,slot_id,times' .
212 ' FROM booking_schedule_slot' .
213 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->id,
'integer'));
214 while ($row =
$ilDB->fetchAssoc($set)) {
215 $definition[$row[
"day_id"]][$row[
"slot_id"]] = $row[
"times"];
217 $this->setDefinition($definition);
229 $this->
id =
$ilDB->nextId(
'booking_schedule');
231 $av_from = ($this->getAvailabilityFrom() && !$this->getAvailabilityFrom()->isNull())
234 $av_to = ($this->getAvailabilityTo() && !$this->getAvailabilityTo()->isNull())
238 $ilDB->manipulate(
'INSERT INTO booking_schedule' .
239 ' (booking_schedule_id,title,pool_id,raster,rent_min,rent_max,auto_break,' .
240 'deadline,av_from,av_to,schedule_type)' .
241 ' VALUES (' .
$ilDB->quote($this->id,
'integer') .
',' .
$ilDB->quote($this->
getTitle(),
'text') .
242 ',' .
$ilDB->quote($this->getPoolId(),
'integer') .
',' .
$ilDB->quote($this->getRaster(),
'integer') .
243 ',' .
$ilDB->quote($this->getMinRental(),
'integer') .
',' .
$ilDB->quote($this->getMaxRental(),
'integer') .
244 ',' .
$ilDB->quote($this->getAutoBreak(),
'integer') .
',' .
$ilDB->quote($this->getDeadline(),
'integer') .
245 ',' .
$ilDB->quote($av_from,
'integer') .
',' .
$ilDB->quote($av_to,
'integer') .
246 ',' .
$ilDB->quote($this->getScheduleType(),
'text') .
')');
248 $this->saveDefinition();
261 $av_from = ($this->getAvailabilityFrom() && !$this->getAvailabilityFrom()->isNull())
264 $av_to = ($this->getAvailabilityTo() && !$this->getAvailabilityTo()->isNull())
268 $ilDB->manipulate(
'UPDATE booking_schedule' .
269 ' SET title = ' .
$ilDB->quote($this->getTitle(),
'text') .
270 ', pool_id = ' .
$ilDB->quote($this->getPoolId(),
'integer') .
271 ', raster = ' .
$ilDB->quote($this->getRaster(),
'integer') .
272 ', rent_min = ' .
$ilDB->quote($this->getMinRental(),
'integer') .
273 ', rent_max = ' .
$ilDB->quote($this->getMaxRental(),
'integer') .
274 ', auto_break = ' .
$ilDB->quote($this->getAutoBreak(),
'integer') .
275 ', deadline = ' .
$ilDB->quote($this->getDeadline(),
'integer') .
276 ', av_from = ' .
$ilDB->quote($av_from,
'integer') .
277 ', av_to = ' .
$ilDB->quote($av_to,
'integer') .
278 ', schedule_type = ' .
$ilDB->quote($this->getScheduleType(),
'text') .
279 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->
id,
'integer'));
281 $this->saveDefinition();
287 $new_obj =
new self();
288 $new_obj->setPoolId($a_pool_id);
289 $new_obj->setTitle($this->
getTitle());
290 $new_obj->setRaster($this->getRaster());
291 $new_obj->setMinRental($this->getMinRental());
292 $new_obj->setMaxRental($this->getMaxRental());
293 $new_obj->setAutoBreak($this->getAutoBreak());
294 $new_obj->setDeadline($this->getDeadline());
295 $new_obj->setDefinition($this->getDefinition());
296 $new_obj->setAvailabilityFrom($this->getAvailabilityFrom());
297 $new_obj->setAvailabilityTo($this->getAvailabilityTo());
298 $new_obj->setScheduleType($this->getScheduleType());
299 return $new_obj->save();
313 $ilDB->manipulate(
'DELETE FROM booking_schedule_slot' .
314 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->id,
'integer'));
316 $definition = $this->getDefinition();
318 foreach ($definition as $day_id => $slots) {
319 foreach ($slots as $slot_id => $times) {
321 "booking_schedule_id" => array(
'integer', $this->
id),
322 "day_id" => array(
'text', $day_id),
323 "slot_id" => array(
'integer', $slot_id),
324 "times" => array(
'text', $times)
326 $ilDB->insert(
'booking_schedule_slot', $fields);
342 $set =
$ilDB->query(
"SELECT booking_schedule_id" .
343 " FROM booking_schedule" .
344 " WHERE pool_id = " .
$ilDB->quote($a_pool_id,
'integer'));
345 return (
bool)
$ilDB->numRows($set);
351 public static function getList(
int $a_pool_id): array
357 $set =
$ilDB->query(
'SELECT s.booking_schedule_id,s.title,' .
358 'MAX(o.schedule_id) AS object_has_schedule' .
359 ' FROM booking_schedule s' .
360 ' LEFT JOIN booking_object o ON (s.booking_schedule_id = o.schedule_id)' .
361 ' WHERE s.pool_id = ' .
$ilDB->quote($a_pool_id,
'integer') .
362 ' GROUP BY s.booking_schedule_id,s.title' .
363 ' ORDER BY s.title');
365 while ($row =
$ilDB->fetchAssoc($set)) {
366 if (!$row[
'object_has_schedule']) {
367 $row[
'is_used'] =
false;
369 $row[
'is_used'] =
true;
376 public function delete():
int
381 return $ilDB->manipulate(
'DELETE FROM booking_schedule' .
382 ' WHERE booking_schedule_id = ' .
$ilDB->quote($this->id,
'integer'));
392 $def = $this->getDefinition();
394 foreach ($def as $day => $times) {
395 foreach ($times as $time) {
396 $slots[$time][] = $day;
399 foreach ($slots as $time => $days) {
400 $slots[$time] = array_unique($days);
409 foreach ($a_def as $time => $days) {
410 foreach ($days as $day) {
411 $slots[$day][] = $time;
414 $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.
const SCHEDULE_TYPE_TIME_PERIOD
setTitle(string $a_title)
setScheduleType(string $a_schedule_type)
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)
const SCHEDULE_TYPE_ALL_DAY
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
foreach($_POST as $key=> $value) $res