Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 25 additions & 39 deletions components/ILIAS/BookingManager/BookingProcess/class.SlotGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,44 @@

namespace ILIAS\BookingManager\BookingProcess;

use ILIAS\BookingManager\getObjectSettingsCommand;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer;
use ilTemplate;

/**
* @author Alexander Killing <killing@leifos.de>
*/
class SlotGUI
{
protected int $color_nr;
protected $from;
protected string $to;
protected int $from_ts;
protected int $to_ts;
protected string $title;
protected int $available;
protected string $link;
protected UIFactory $ui_factory;
protected Renderer $ui_renderer;

public function __construct(
string $link,
string $from,
string $to,
int $from_ts,
int $to_ts,
string $title,
int $available,
int $color_nr
protected string $link,
protected string $from,
protected string $to,
protected int $from_ts,
protected int $to_ts,
protected string $title,
protected int $available,
protected int $color_nr
) {
$this->from = $from;
$this->to = $to;
$this->from_ts = $from_ts;
$this->to_ts = $to_ts;
$this->title = $title;
$this->available = $available;
$this->link = $link;
$this->color_nr = $color_nr;

global $DIC;
$this->ui_factory = $DIC->ui()->factory();
$this->ui_renderer = $DIC->ui()->renderer();
}

public function render(): string
{
global $DIC;
$ui = $DIC->ui();
$tpl = new \ilTemplate("tpl.slot.html", true, true, "components/ILIAS/BookingManager/BookingProcess");
$tpl = new ilTemplate('tpl.slot.html', true, true, 'components/ILIAS/BookingManager/BookingProcess');

$modal = $ui->factory()->modal()->roundtrip("", $ui->factory()->legacy()->content(""));
$url = $this->link . '&replaceSignal=' . $modal->getReplaceSignal()->getId();
$modal = $this->ui_factory->modal()->roundtrip('', $this->ui_factory->legacy()->content(''));
$url = "{$this->link}&replaceSignal={$modal->getReplaceSignal()->getId()}";
$modal = $modal->withAsyncRenderUrl($url);
$button = $ui->factory()->button()->shy($this->title, "#")
->withOnClick($modal->getShowSignal());
$button = $this->ui_factory->button()->shy($this->title, '#')->withOnClick($modal->getShowSignal());

$tpl->setVariable("OBJECT_LINK", $ui->renderer()->render([$button, $modal]));
$tpl->setVariable("TIME", $this->from . "-" . $this->to);
$tpl->setVariable("COLOR_NR", $this->color_nr);
$tpl->setVariable("AVAILABILITY", "(" . $this->available . ") ");
$tpl->setVariable('OBJECT_LINK', $this->ui_renderer->render([$button, $modal]));
$tpl->setVariable('TIME', ($this->to_ts - $this->from_ts) !== 86400 ? "{$this->from}-{$this->to}" : '');
$tpl->setVariable('COLOR_NR', $this->color_nr);
$tpl->setVariable('AVAILABILITY', "({$this->available}) ");

return $tpl->get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,13 @@

namespace ILIAS\BookingManager\BookingProcess;

/**
*
* @author Alexander Killing <killing@leifos.de>
*/
class WeekGridEntry
{
protected int $start;
protected int $end;
protected string $html;

public function __construct(
int $start,
int $end,
string $html
protected int $start,
protected int $end,
protected string $html
) {
$this->start = $start;
$this->end = $end;
$this->html = $html;
}

public function getStart(): int
Expand All @@ -54,4 +43,9 @@ public function getHTML(): string
{
return $this->html;
}

public function isAllDay(): bool
{
return ($this->getEnd() - $this->getStart()) === 86400;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(

protected function getHoursOfDay(): array
{
$hours = array();
$hours = [0 => ['caption' => $this->lng->txt('book_all_day'), 'start' => '00:00', 'end' => '24:00']];
$sep = "<br>-<br>";
for ($i = $this->day_start;$i <= $this->day_end;$i++) {
$caption = "";
Expand Down Expand Up @@ -178,7 +178,7 @@ public function render(): string
foreach ($hours as $hour => $days) {
$caption = $days["caption"];
$day_of_week = 0;
foreach (\ilCalendarUtil::_buildWeekDayList($this->seed, $this->week_start)->get() as $date) {
foreach ($weekday_list as $date) {
$data = $cells[$day_of_week][$hour];
$total_tds = $cells[$day_of_week]["col_span"];
foreach ($data["entries"] as $e) {
Expand Down Expand Up @@ -216,10 +216,13 @@ public function render(): string
*/
protected function getEntriesForCell(int $start_ts, int $end_ts): array
{
return array_filter($this->entries, function ($e) use ($start_ts, $end_ts) {
/** @var WeekGridEntry $e */
return ($e->getStart() < $end_ts && $e->getEnd() > $start_ts);
});
$all_day_cell = ($end_ts - $start_ts) === 86400;
return array_filter(
$this->entries,
static fn(WeekGridEntry $e) =>
($all_day_cell && $e->isAllDay() && $e->getStart() === $start_ts && $e->getEnd() === $end_ts)
|| (!$all_day_cell && !$e->isAllDay() && $e->getStart() < $end_ts && $e->getEnd() > $start_ts)
);
}

protected function renderCell(array $data)
Expand Down
3 changes: 2 additions & 1 deletion components/ILIAS/BookingManager/FORMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ This is an overview of forms that need to be migrated to the KS and missing inpu
1. Reservation, cancel aggregation
- none
1. Schedule
- ilScheduleInputGUI
- ilScheduleInputGUI
- ilScheduleDaysInputGUI (weekday checkboxes only)
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,11 @@ public function initFilter(
$day_caption = ilCalendarUtil::_numericDayToString((int) $map[$day], false);

foreach ($slots as $slot) {
$idx = $map[$day] . "_" . $slot;
$options[$idx] = $day_caption . ", " . $slot;
$slot = $slot === ilBookingSchedule::ALL_DAY_SLOT
? $this->lng->txt('book_all_day')
: $slot;

$options["{$map[$day]}_{$slot}"] = "{$day_caption}, {$slot}";
}
}
}
Expand Down Expand Up @@ -644,7 +647,12 @@ protected function fillRow(array $a_set): void
ilCalendarUtil::_numericDayToString((int) $a_set["weekday"], false)
);
}
$this->tpl->setVariable("VALUE_SLOT", $a_set["slot"]);
$this->tpl->setVariable(
"VALUE_SLOT",
in_array($a_set["slot"], [ilBookingSchedule::ALL_DAY_SLOT, "00:00 - 00:00"], true)
? $this->lng->txt('book_all_day')
: $a_set["slot"]
);
$this->tpl->setVariable("VALUE_COUNTER", $a_set["counter"]);
} elseif (in_array(
$a_set['status'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
*/
class ilBookingSchedule
{
public const SCHEDULE_TYPE_TIME_PERIOD = 'time_period';
public const SCHEDULE_TYPE_ALL_DAY = 'all_day';
public const ALL_DAY_SLOT = '00:00-24:00';

protected ilDBInterface $db;
protected int $id = 0;
protected string $title = "";
Expand All @@ -34,6 +38,7 @@ class ilBookingSchedule
protected array $definition;
protected ?ilDateTime $av_from = null;
protected ?ilDateTime $av_to = null;
protected string $schedule_type = self::SCHEDULE_TYPE_TIME_PERIOD;

public function __construct(
?int $a_id = null
Expand Down Expand Up @@ -169,13 +174,23 @@ public function getAvailabilityTo(): ?ilDateTime
return $this->av_to;
}

public function getScheduleType(): string
{
return $this->schedule_type;
}

public function setScheduleType(string $a_schedule_type): void
{
$this->schedule_type = $a_schedule_type;
}

protected function read(): void
{
$ilDB = $this->db;

if ($this->id) {
$set = $ilDB->query('SELECT title,raster,rent_min,rent_max,auto_break,' .
'deadline,av_from,av_to' .
'deadline,av_from,av_to,schedule_type' .
' FROM booking_schedule' .
' WHERE booking_schedule_id = ' . $ilDB->quote($this->id, 'integer'));
$row = $ilDB->fetchAssoc($set);
Expand All @@ -189,6 +204,7 @@ protected function read(): void
$this->setMaxRental($row['rent_max']);
$this->setAutoBreak($row['auto_break']);
}
$this->setScheduleType($row['schedule_type'] ?? self::SCHEDULE_TYPE_TIME_PERIOD);

// load definition
$definition = array();
Expand Down Expand Up @@ -221,12 +237,13 @@ public function save(): ?int

$ilDB->manipulate('INSERT INTO booking_schedule' .
' (booking_schedule_id,title,pool_id,raster,rent_min,rent_max,auto_break,' .
'deadline,av_from,av_to)' .
'deadline,av_from,av_to,schedule_type)' .
' VALUES (' . $ilDB->quote($this->id, 'integer') . ',' . $ilDB->quote($this->getTitle(), 'text') .
',' . $ilDB->quote($this->getPoolId(), 'integer') . ',' . $ilDB->quote($this->getRaster(), 'integer') .
',' . $ilDB->quote($this->getMinRental(), 'integer') . ',' . $ilDB->quote($this->getMaxRental(), 'integer') .
',' . $ilDB->quote($this->getAutoBreak(), 'integer') . ',' . $ilDB->quote($this->getDeadline(), 'integer') .
',' . $ilDB->quote($av_from, 'integer') . ',' . $ilDB->quote($av_to, 'integer') . ')');
',' . $ilDB->quote($av_from, 'integer') . ',' . $ilDB->quote($av_to, 'integer') .
',' . $ilDB->quote($this->getScheduleType(), 'text') . ')');

$this->saveDefinition();

Expand Down Expand Up @@ -258,6 +275,7 @@ public function update(): bool
', deadline = ' . $ilDB->quote($this->getDeadline(), 'integer') .
', av_from = ' . $ilDB->quote($av_from, 'integer') .
', av_to = ' . $ilDB->quote($av_to, 'integer') .
', schedule_type = ' . $ilDB->quote($this->getScheduleType(), 'text') .
' WHERE booking_schedule_id = ' . $ilDB->quote($this->id, 'integer'));

$this->saveDefinition();
Expand All @@ -277,6 +295,7 @@ public function doClone(int $a_pool_id): int
$new_obj->setDefinition($this->getDefinition());
$new_obj->setAvailabilityFrom($this->getAvailabilityFrom());
$new_obj->setAvailabilityTo($this->getAvailabilityTo());
$new_obj->setScheduleType($this->getScheduleType());
return $new_obj->save();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,27 @@ public function initForm(
$title->setMaxLength(120);
$form_gui->addItem($title);

$definition = new ilScheduleInputGUI($lng->txt("book_schedule_days"), "days");
$definition->setInfo($lng->txt("book_schedule_days_info"));
$definition->setRequired(true);
$form_gui->addItem($definition);
$schedule = $a_mode === "edit" && $id !== null ? new ilBookingSchedule($id) : null;
$schedule_type = $schedule?->getScheduleType() ?? ilBookingSchedule::SCHEDULE_TYPE_TIME_PERIOD;

$radio = new ilRadioGroupInputGUI($lng->txt("schedule_type"), "schedule_type");
$radio->setValue($schedule_type);
$radio->setRequired(true);

$opt_time_period = new ilRadioOption($lng->txt("book_schedule_days"), ilBookingSchedule::SCHEDULE_TYPE_TIME_PERIOD);
$definition_slots = new ilScheduleInputGUI('', "days");
$definition_slots->setInfo($lng->txt("book_schedule_days_info"));
$definition_slots->setRequired(true);
$opt_time_period->addSubItem($definition_slots);
$radio->addOption($opt_time_period);

$opt_all_days = new ilRadioOption($lng->txt("book_schedule_all_day"), ilBookingSchedule::SCHEDULE_TYPE_ALL_DAY);
$definition_all_day = new ilScheduleDaysInputGUI('', "days_all_day");
$definition_all_day->setRequired(true);
$opt_all_days->addSubItem($definition_all_day);
$radio->addOption($opt_all_days);

$form_gui->addItem($radio);

$deadline_opts = new ilRadioGroupInputGUI($lng->txt("book_deadline_options"), "deadline_opts");
$deadline_opts->setRequired(true);
Expand All @@ -193,10 +210,6 @@ public function initForm(
$deadline_slot = new ilRadioOption($lng->txt("book_deadline_slot_end"), "slot_end");
$deadline_opts->addOption($deadline_slot);

if ($a_mode === "edit") {
$schedule = new ilBookingSchedule($id);
}

$av = new ilFormSectionHeaderGUI();
$av->setTitle($lng->txt("obj_activation_list_gui"));
$form_gui->addItem($av);
Expand All @@ -212,14 +225,13 @@ public function initForm(
$to->setShowTime(true);
$form_gui->addItem($to);

if ($a_mode === "edit") {
if ($schedule instanceof ilBookingSchedule) {
$form_gui->setTitle($lng->txt("book_edit_schedule"));

$item = new ilHiddenInputGUI('schedule_id');
$item->setValue($id);
$form_gui->addItem($item);

$schedule = new ilBookingSchedule($id);
$title->setValue($schedule->getTitle());
$from->setDate($schedule->getAvailabilityFrom());
$to->setDate($schedule->getAvailabilityTo());
Expand All @@ -234,7 +246,12 @@ public function initForm(
$deadline_opts->setValue("slot_end");
}

$definition->setValue($schedule->getDefinitionBySlots());
match ($schedule_type) {
ilBookingSchedule::SCHEDULE_TYPE_ALL_DAY => $definition_all_day->setValue(
$schedule->getDefinitionBySlots()[ilBookingSchedule::ALL_DAY_SLOT]
),
default => $definition_slots->setValue($schedule->getDefinitionBySlots()),
};

$form_gui->addCommandButton("update", $lng->txt("save"));
} else {
Expand Down Expand Up @@ -296,6 +313,7 @@ protected function formToObject(

$schedule->setTitle($form->getInput("title"));
$schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
$schedule->setScheduleType($form->getInput("schedule_type"));

$from = $form->getItemByPostVar("from");
if ($from !== null) {
Expand Down Expand Up @@ -338,7 +356,10 @@ protected function formToObject(
}
*/

$days = $form->getInput("days");
$days = match ($schedule->getScheduleType()) {
ilBookingSchedule::SCHEDULE_TYPE_TIME_PERIOD => $form->getInput("days"),
ilBookingSchedule::SCHEDULE_TYPE_ALL_DAY => [ilBookingSchedule::ALL_DAY_SLOT => $form->getInput("days_all_day")],
};
$schedule->setDefinitionBySlots($days);
}

Expand Down
Loading
Loading