3 declare(strict_types=1);
30 protected \ilLanguage
$lng;
50 $this->title =
"Test";
51 $this->form_action =
"#";
52 $this->
lng = $DIC->language();
56 $this->seed = $seed ?? new \ilDate(time(),
IL_CAL_UNIX);
67 $start = sprintf(
'%02d:00', $i);
68 if ($this->day_start > 0 && $i === $this->day_start) {
69 $start = sprintf(
'%02d:00', 0);
70 $end = sprintf(
'%02d:00', $i + 1);
72 $end = sprintf(
'%02d:00', $i + 1);
74 if ($this->day_end < 23 && $i === $this->day_end) {
75 $end = sprintf(
'%02d:00', 23 + 1);
77 switch ($this->time_format) {
78 case \ilCalendarSettings::TIME_FORMAT_12:
79 if ($this->day_start > 0 && $i === $this->day_start) {
80 $caption = date(
'h a', mktime(0, 0, 0, 1, 1, 2000)) . $sep;
82 $caption .= date(
'h a', mktime($i, 0, 0, 1, 1, 2000));
83 if ($this->day_end < 23 && $i === $this->day_end) {
84 $caption .= $sep . date(
'h a', mktime(23, 0, 0, 1, 1, 2000));
89 if ($this->day_start > 0 && $i === $this->day_start) {
90 $caption = sprintf(
'%02d:00', 0) . $sep;
92 $caption .= sprintf(
'%02d:00', $i);
93 if ($this->day_end < 23 && $i === $this->day_end) {
94 $caption .= $sep . sprintf(
'%02d:00', 23);
99 "caption" => $caption,
112 protected function buildCellData(): array
122 foreach ($hours as $hour =>
$data) {
127 $data[
"entries"] = $this->getEntriesForCell($data[
"start_ts"], $data[
"end_ts"]);
128 $cells[$week][$hour] =
$data;
130 $cells[$week][
"col_span"] = max(count($data[
"entries"]), $cells[$week][
"col_span"] ?? 1);
137 public function render():
string 139 $mytpl = new \ilTemplate(
140 'tpl.week_grid.html',
143 'Modules/BookingManager/BookingProcess' 146 $cells = $this->buildCellData();
150 $start = current($weekday_list);
151 $end = end($weekday_list);
152 $mytpl->setVariable(
"TXT_OBJECT", $this->
lng->txt(
'week') .
' ' . $this->seed->get(
IL_CAL_FKT_DATE,
'W') .
156 $mytpl->setVariable(
'TXT_TITLE', $this->
lng->txt(
'book_reservation_title'));
157 $mytpl->setVariable(
'TIME', $this->
lng->txt(
'time'));
161 reset($weekday_list);
162 foreach ($weekday_list as $date) {
164 $mytpl->setCurrentBlock(
'weekdays');
166 $mytpl->setVariable(
'COL_SPAN', $cells[$day_of_week][
"col_span"]);
167 $mytpl->setVariable(
'WIDTH',
"12");
169 $mytpl->parseCurrentBlock();
175 foreach ($hours as $hour => $days) {
176 $caption = $days[
"caption"];
179 $data = $cells[$day_of_week][$hour];
180 $total_tds = $cells[$day_of_week][
"col_span"];
181 foreach (
$data[
"entries"] as
$e) {
184 if ($e->getStart() >=
$data[
"start_ts"] && $e->getStart() <
$data[
"end_ts"]) {
185 $mytpl->setCurrentBlock(
'dates');
186 $mytpl->setVariable(
'CONTENT', $e->getHTML());
187 $row_span = max(1, ceil(($e->getEnd() -
$data[
"end_ts"]) / 3600) + 1);
188 $mytpl->setVariable(
'ROW_SPAN', $row_span);
189 $mytpl->parseCurrentBlock();
193 while ($total_tds > 0) {
194 $mytpl->setCurrentBlock(
'dates');
195 $mytpl->setVariable(
'CONTENT',
" ");
196 $mytpl->parseCurrentBlock();
202 $mytpl->setCurrentBlock(
'slots');
203 $mytpl->setVariable(
'TXT_HOUR', $caption);
204 $mytpl->parseCurrentBlock();
207 return $mytpl->get();
214 protected function getEntriesForCell(
int $start_ts,
int $end_ts): array
216 return array_filter($this->entries,
function (
$e) use ($start_ts, $end_ts) {
218 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)
numeric month to string
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _buildWeekDayList(ilDate $a_day, int $a_weekstart)
build week day list public
__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 _numericDayToString(int $a_day, bool $a_long=true)