19 declare(strict_types=1);
33 protected \ilLanguage
$lng;
53 $this->title =
"Test";
54 $this->form_action =
"#";
55 $this->
lng = $DIC->language();
59 $this->seed = $seed ?? new \ilDate(time(),
IL_CAL_UNIX);
70 $start = sprintf(
'%02d:00', $i);
71 if ($this->day_start > 0 && $i === $this->day_start) {
72 $start = sprintf(
'%02d:00', 0);
73 $end = sprintf(
'%02d:00', $i + 1);
75 $end = sprintf(
'%02d:00', $i + 1);
77 if ($this->day_end < 23 && $i === $this->day_end) {
78 $end = sprintf(
'%02d:00', 23 + 1);
80 switch ($this->time_format) {
81 case \ilCalendarSettings::TIME_FORMAT_12:
82 if ($this->day_start > 0 && $i === $this->day_start) {
83 $caption = date(
'h a', mktime(0, 0, 0, 1, 1, 2000)) . $sep;
85 $caption .= date(
'h a', mktime($i, 0, 0, 1, 1, 2000));
86 if ($this->day_end < 23 && $i === $this->day_end) {
87 $caption .= $sep . date(
'h a', mktime(23, 0, 0, 1, 1, 2000));
92 if ($this->day_start > 0 && $i === $this->day_start) {
93 $caption = sprintf(
'%02d:00', 0) . $sep;
95 $caption .= sprintf(
'%02d:00', $i);
96 if ($this->day_end < 23 && $i === $this->day_end) {
97 $caption .= $sep . sprintf(
'%02d:00', 23);
102 "caption" => $caption,
115 protected function buildCellData(): array
125 foreach ($hours as $hour =>
$data) {
130 $data[
"entries"] = $this->getEntriesForCell($data[
"start_ts"], $data[
"end_ts"]);
131 $cells[$week][$hour] =
$data;
133 $cells[$week][
"col_span"] = max(count($data[
"entries"]), $cells[$week][
"col_span"] ?? 1);
140 public function render():
string 142 $mytpl = new \ilTemplate(
143 'tpl.week_grid.html',
146 'components/ILIAS/BookingManager/BookingProcess' 149 $cells = $this->buildCellData();
153 $start = current($weekday_list);
154 $end = end($weekday_list);
155 $mytpl->setVariable(
"TXT_OBJECT", $this->
lng->txt(
'week') .
' ' . $this->seed->get(
IL_CAL_FKT_DATE,
'W') .
159 $mytpl->setVariable(
'TXT_TITLE', $this->
lng->txt(
'book_reservation_title'));
160 $mytpl->setVariable(
'TIME', $this->
lng->txt(
'time'));
164 reset($weekday_list);
165 foreach ($weekday_list as $date) {
167 $mytpl->setCurrentBlock(
'weekdays');
169 $mytpl->setVariable(
'COL_SPAN', $cells[$day_of_week][
"col_span"]);
170 $mytpl->setVariable(
'WIDTH',
"12");
172 $mytpl->parseCurrentBlock();
178 foreach ($hours as $hour => $days) {
179 $caption = $days[
"caption"];
182 $data = $cells[$day_of_week][$hour];
183 $total_tds = $cells[$day_of_week][
"col_span"];
184 foreach (
$data[
"entries"] as
$e) {
187 if ($e->getStart() >=
$data[
"start_ts"] && $e->getStart() <
$data[
"end_ts"]) {
188 $mytpl->setCurrentBlock(
'dates');
189 $mytpl->setVariable(
'CONTENT', $e->getHTML());
190 $row_span = max(1, ceil(($e->getEnd() -
$data[
"end_ts"]) / 3600) + 1);
191 $mytpl->setVariable(
'ROW_SPAN', $row_span);
192 $mytpl->parseCurrentBlock();
196 while ($total_tds > 0) {
197 $mytpl->setCurrentBlock(
'dates');
198 $mytpl->setVariable(
'CONTENT',
" ");
199 $mytpl->parseCurrentBlock();
205 $mytpl->setCurrentBlock(
'slots');
206 $mytpl->setVariable(
'TXT_HOUR', $caption);
207 $mytpl->parseCurrentBlock();
210 return $mytpl->get();
217 protected function getEntriesForCell(
int $start_ts,
int $end_ts): array
219 return array_filter($this->entries,
function (
$e) use ($start_ts, $end_ts) {
221 return (
$e->getStart() < $end_ts &&
$e->getEnd() > $start_ts);
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _numericMonthToString(int $a_month, bool $a_long=true, ?ilLanguage $lng=null)
numeric month to string
static _buildWeekDayList(ilDate $a_day, int $a_weekstart)
build week day list public
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _numericDayToString(int $a_day, bool $a_long=true, ?ilLanguage $lng=null)
__construct(array $entries=[], ?\ilDate $seed=null, int $day_start=8, int $day_end=19, int $time_format=\ilCalendarSettings::TIME_FORMAT_24, int $week_start=\ilCalendarSettings::WEEK_START_MONDAY)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)