ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.WeekGridGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
28 protected string $form_action;
29 protected int $week_start;
30 protected \ilDate $seed;
31 protected string $seed_str;
32 protected int $time_format;
33 protected \ilLanguage $lng;
34 protected int $day_end;
35 protected int $day_start;
36 protected string $title;
37 protected array $entries;
38
43 public function __construct(
44 array $entries = [],
45 ?\ilDate $seed = null,
46 int $day_start = 8,
47 int $day_end = 19,
50 ) {
51 global $DIC;
52
53 $this->title = "Test";
54 $this->form_action = "#";
55 $this->lng = $DIC->language();
56 $this->day_start = $day_start;
57 $this->day_end = $day_end;
58 $this->time_format = $time_format;
59 $this->seed = $seed ?? new \ilDate(time(), IL_CAL_UNIX);
60 $this->week_start = $week_start;
61 $this->entries = $entries;
62 }
63
64 protected function getHoursOfDay(): array
65 {
66 $hours = array();
67 $sep = "<br>-<br>";
68 for ($i = $this->day_start;$i <= $this->day_end;$i++) {
69 $caption = "";
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);
74 } else {
75 $end = sprintf('%02d:00', $i + 1);
76 }
77 if ($this->day_end < 23 && $i === $this->day_end) {
78 $end = sprintf('%02d:00', 23 + 1);
79 }
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;
84 }
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));
88 }
89 break;
90
91 default:
92 if ($this->day_start > 0 && $i === $this->day_start) {
93 $caption = sprintf('%02d:00', 0) . $sep;
94 }
95 $caption .= sprintf('%02d:00', $i);
96 if ($this->day_end < 23 && $i === $this->day_end) {
97 $caption .= $sep . sprintf('%02d:00', 23);
98 }
99 break;
100 }
101 $hours[$i] = [
102 "caption" => $caption,
103 "start" => $start,
104 "end" => $end
105 ];
106 }
107 return $hours;
108 }
109
115 protected function buildCellData(): array
116 {
117 $morning_aggr = $this->day_start;
118 $evening_aggr = $this->day_end;
119 $hours = $this->getHoursOfDay();
120 $week_start = $this->week_start;
122 $cells = [];
123 $week = 0;
124 foreach (\ilCalendarUtil::_buildWeekDayList($this->seed, $week_start)->get() as $date) {
125 foreach ($hours as $hour => $data) {
126 $start = new \ilDateTime($date->get(IL_CAL_DATE) . " " . $data["start"] . ":00", IL_CAL_DATETIME);
127 $end = new \ilDateTime($date->get(IL_CAL_DATE) . " " . $data["end"] . ":00", IL_CAL_DATETIME);
128 $data["start_ts"] = $start->get(IL_CAL_UNIX);
129 $data["end_ts"] = $end->get(IL_CAL_UNIX);
130 $data["entries"] = $this->getEntriesForCell($data["start_ts"], $data["end_ts"]);
131 $cells[$week][$hour] = $data;
132 // store how much slots are max. to be displayed in parallel per day
133 $cells[$week]["col_span"] = max(count($data["entries"]), $cells[$week]["col_span"] ?? 1);
134 }
135 $week++;
136 }
137 return $cells;
138 }
139
140 public function render(): string
141 {
142 $mytpl = new \ilTemplate(
143 'tpl.week_grid.html',
144 true,
145 true,
146 'components/ILIAS/BookingManager/BookingProcess'
147 );
148
149 $cells = $this->buildCellData();
150
151
152 $weekday_list = \ilCalendarUtil::_buildWeekDayList($this->seed, $this->week_start)->get();
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') .
156 ", " . \ilDatePresentation::formatDate($start) . " - " .
158
159 $mytpl->setVariable('TXT_TITLE', $this->lng->txt('book_reservation_title'));
160 $mytpl->setVariable('TIME', $this->lng->txt('time'));
161
162
163 $day_of_week = 0;
164 reset($weekday_list);
165 foreach ($weekday_list as $date) {
166 $date_info = $date->get(IL_CAL_FKT_GETDATE, '', 'UTC');
167 $mytpl->setCurrentBlock('weekdays');
168 $mytpl->setVariable('TXT_WEEKDAY', \ilCalendarUtil::_numericDayToString((int) $date_info['wday']));
169 $mytpl->setVariable('COL_SPAN', $cells[$day_of_week]["col_span"]);
170 $mytpl->setVariable('WIDTH', "12");
171 $mytpl->setVariable('TXT_DATE', $date_info['mday'] . ' ' . \ilCalendarUtil::_numericMonthToString($date_info['mon']));
172 $mytpl->parseCurrentBlock();
173 $day_of_week++;
174 }
175
176 $hours = $this->getHoursOfDay();
177
178 foreach ($hours as $hour => $days) {
179 $caption = $days["caption"];
180 $day_of_week = 0;
181 foreach (\ilCalendarUtil::_buildWeekDayList($this->seed, $this->week_start)->get() as $date) {
182 $data = $cells[$day_of_week][$hour];
183 $total_tds = $cells[$day_of_week]["col_span"];
184 foreach ($data["entries"] as $e) {
185 // starting in cell? show it
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();
193 }
194 $total_tds--;
195 }
196 while ($total_tds > 0) {
197 $mytpl->setCurrentBlock('dates');
198 $mytpl->setVariable('CONTENT', "&nbsp;");
199 $mytpl->parseCurrentBlock();
200 $total_tds--;
201 }
202 $day_of_week++;
203 }
204
205 $mytpl->setCurrentBlock('slots');
206 $mytpl->setVariable('TXT_HOUR', $caption);
207 $mytpl->parseCurrentBlock();
208 }
209 //\ilPropertyFormGUI::initJavascript();
210 return $mytpl->get();
211 }
212
217 protected function getEntriesForCell(int $start_ts, int $end_ts): array
218 {
219 return array_filter($this->entries, function ($e) use ($start_ts, $end_ts) {
221 return ($e->getStart() < $end_ts && $e->getEnd() > $start_ts);
222 });
223 }
224
225 protected function renderCell(array $data)
226 {
227 return "&nbsp;";
228 }
229}
__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)
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_FKT_DATE
static _numericDayToString(int $a_day, bool $a_long=true, ?ilLanguage $lng=null)
static _buildWeekDayList(ilDate $a_day, int $a_weekstart)
build week day list @access public
static _numericMonthToString(int $a_month, bool $a_long=true, ?ilLanguage $lng=null)
numeric month to string
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
Class for single dates.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26