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