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