ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.WeekGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
28 protected const PROCESS_CLASS = \ilBookingProcessWithScheduleGUI::class;
29 protected \ILIAS\BookingManager\Objects\ObjectsManager $object_manager;
30 protected \ilCtrlInterface $ctrl;
31 protected string $parent_cmd;
32 protected object $parent_gui;
36 protected array $obj_ids = [];
37 protected int $week_start;
38 protected \ilDate $seed;
39 protected string $seed_str;
40 protected int $time_format;
41 protected int $day_end;
42 protected int $day_start;
43
44 public function __construct(
45 object $parent_gui,
46 string $parent_cmd,
47 array $obj_ids,
48 int $pool_id,
49 string $seed_str = "",
51 ) {
52 global $DIC;
53
54 $this->ctrl = $DIC->ctrl();
55 $this->parent_gui = $parent_gui;
56 $this->parent_cmd = $parent_cmd;
57 $this->obj_ids = $obj_ids;
58 $this->day_start = 8;
59 $this->day_end = 19;
60 $this->time_format = \ilCalendarSettings::TIME_FORMAT_24;
61 $this->seed_str = $seed_str;
62 $this->seed = ($this->seed_str !== "")
63 ? new \ilDate($this->seed_str, IL_CAL_DATE)
64 : new \ilDate(time(), IL_CAL_UNIX);
65 $this->week_start = $week_start;
66 $this->object_manager = $DIC->bookingManager()->internal()
67 ->domain()->objects($pool_id);
68 }
69
70 public function getHTML(): string
71 {
72 $navigation = new \ilCalendarHeaderNavigationGUI(
73 $this->parent_gui,
74 $this->seed,
76 $this->parent_cmd
77 );
78 $navigation->getHTML();
79
80
81 /*
82 $start1 = new \ilDateTime("2022-08-17 10:00:00", IL_CAL_DATETIME);
83 $end1 = new \ilDateTime("2022-08-17 11:00:00", IL_CAL_DATETIME);
84
85 $entry1 = new WeekGridEntry(
86 $start1->get(IL_CAL_UNIX),
87 $end1->get(IL_CAL_UNIX),
88 "Moin 1"
89 );
90
91 $start2 = new \ilDateTime("2022-08-19 12:00:00", IL_CAL_DATETIME);
92 $end2 = new \ilDateTime("2022-08-19 13:00:00", IL_CAL_DATETIME);
93
94 $entry2 = new WeekGridEntry(
95 $start2->get(IL_CAL_UNIX),
96 $end2->get(IL_CAL_UNIX),
97 "Moin 2"
98 );*/
99
100 $week_widget = new WeekGridGUI(
101 $this->getWeekGridEntries($this->obj_ids),
102 $this->seed,
103 $this->day_start,
104 $this->day_end,
105 $this->time_format,
106 $this->week_start
107 );
108 return $week_widget->render();
109 }
110
111 protected function getWeekGridEntries(
112 array $object_ids
113 ): array {
114 $week_grid_entries = [];
115
116 foreach ($object_ids as $object_id) {
117 $obj = new \ilBookingObject($object_id);
118 $schedule = new \ilBookingSchedule($obj->getScheduleId());
119 $map = array('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su');
120 $definition = $schedule->getDefinition();
121 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
122 ? $schedule->getAvailabilityFrom()->get(IL_CAL_DATE)
123 : null;
124 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
125 ? $schedule->getAvailabilityTo()->get(IL_CAL_DATE)
126 : null;
127
128 $has_open_slot = false;
130 foreach (\ilCalendarUtil::_buildWeekDayList($this->seed, $this->week_start)->get() as $date) {
131 $date_info = $date->get(IL_CAL_FKT_GETDATE, '', 'UTC');
132
133 #24045 and #24936
134 if ($av_from || $av_to) {
135 $today = $date->get(IL_CAL_DATE);
136
137 if ($av_from && $av_from > $today) {
138 continue;
139 }
140
141 if ($av_to && $av_to < $today) {
142 continue;
143 }
144 }
145
146 $slots = [];
147 if (isset($definition[$map[$date_info['isoday'] - 1]])) {
148 foreach ($definition[$map[$date_info['isoday'] - 1]] as $slot) {
149 $slot = explode('-', $slot);
150 $slots[] = array('from' => str_replace(':', '', $slot[0]),
151 'to' => str_replace(':', '', $slot[1])
152 );
153 }
154 }
155
156 foreach ($slots as $slot) {
157 $slot_from = mktime(
158 (int) substr($slot['from'], 0, 2),
159 (int) substr($slot['from'], 2, 2),
160 0,
161 $date_info["mon"],
162 $date_info["mday"],
163 $date_info["year"]
164 );
165 $slot_to = mktime(
166 (int) substr($slot['to'], 0, 2),
167 (int) substr($slot['to'], 2, 2),
168 0,
169 $date_info["mon"],
170 $date_info["mday"],
171 $date_info["year"]
172 );
173
174 // always single object, we can sum up
176 [$object_id],
177 $slot_from,
178 $slot_to - 1,
179 false,
180 true
181 );
182
183 // any objects available?
184 if (!array_sum($nr_available)) {
185 continue;
186 }
187
188 // check deadline
189 if ($schedule->getDeadline() >= 0) {
190 // 0-n hours before slots begins
191 if ($slot_from < (time() + $schedule->getDeadline() * 60 * 60)) {
192 continue;
193 }
194 } elseif ($slot_to < time()) {
195 continue;
196 }
197
198 $from = \ilDatePresentation::formatDate(new \ilDateTime($slot_from, IL_CAL_UNIX));
199 $from_a = explode(' ', $from);
200 $from = array_pop($from_a);
202 $to_a = explode(' ', $to);
203 $to = array_pop($to_a);
204
205 $this->ctrl->setParameterByClass(self::PROCESS_CLASS, "slot", $slot_from . "_" . $slot_to);
206 $this->ctrl->setParameterByClass(self::PROCESS_CLASS, "object_id", $obj->getId());
207 $this->ctrl->setParameterByClass(self::PROCESS_CLASS, "seed", $this->seed_str);
208 $link = $this->ctrl->getLinkTargetByClass(self::PROCESS_CLASS, "showNumberForm", "", true);
209 $this->ctrl->setParameterByClass(self::PROCESS_CLASS, "slot", null);
210 $this->ctrl->setParameterByClass(self::PROCESS_CLASS, "object_id", null);
211 $slot_gui = new SlotGUI(
212 $link,
213 $from,
214 $to,
215 $slot_from,
216 $slot_to,
217 $obj->getTitle(),
218 array_sum($nr_available),
219 $this->object_manager->getColorNrForObject($obj->getId())
220 );
221 $week_grid_entries[] = new WeekGridEntry(
222 $slot_from,
223 $slot_to,
224 $slot_gui->render()
225 );
226 }
227 }
228 }
229 return $week_grid_entries;
230 }
231}
__construct(object $parent_gui, string $parent_cmd, array $obj_ids, int $pool_id, string $seed_str="", int $week_start=\ilCalendarSettings::WEEK_START_MONDAY)
ILIAS BookingManager Objects ObjectsManager $object_manager
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_UNIX
static getAvailableObject(array $a_ids, int $a_from, int $a_to, bool $a_return_single=true, bool $a_return_counter=false)
Check if any of given objects are bookable.
static _buildWeekDayList(ilDate $a_day, int $a_weekstart)
build week day list @access public
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
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