ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarAgendaListGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30{
31 public const PERIOD_DAY = 1;
32 public const PERIOD_WEEK = 2;
33 public const PERIOD_MONTH = 3;
34 public const PERIOD_HALF_YEAR = 4;
35
36 protected int $period = self::PERIOD_WEEK;
37
38 public function __construct(ilDate $seed)
39 {
41 $this->ctrl->saveParameter($this, "cal_agenda_per");
42 $this->initPeriod();
43 $this->ctrl->setParameterByClass("ilcalendarinboxgui", "seed", $this->seed->get(IL_CAL_DATE));
44 $this->initEndPeriod();
45 }
46
47 protected function initCalendarPeriodFromRequest(): int
48 {
49 if ($this->http->wrapper()->query()->has('cal_agenda_per')) {
50 return $this->http->wrapper()->query()->retrieve(
51 'cal_agenda_per',
52 $this->refinery->kindlyTo()->int()
53 );
54 }
55 return 0;
56 }
57
58 protected function initPeriod(): void
59 {
60 global $DIC;
61
62 $cal_setting = ilCalendarSettings::_getInstance();
63
64 $calendar_period = $this->initCalendarPeriodFromRequest();
65 if ($calendar_period > 0 && $calendar_period <= 4) {
66 $this->period = $calendar_period;
67 } elseif (!empty($this->user->getPref('cal_list_view'))) {
68 $this->period = intval($this->user->getPref('cal_list_view'));
69 } else {
70 $this->period = $cal_setting->getDefaultPeriod();
71 }
72 $this->user->writePref('cal_list_view', (string) $this->period);
73 }
74
78 protected function initEndPeriod(): void
79 {
80 $end_date = clone $this->seed;
81 switch ($this->period) {
83 $end_date->increment(IL_CAL_DAY, 1);
84 break;
85
87 $end_date->increment(IL_CAL_WEEK, 1);
88 break;
89
91 $end_date->increment(IL_CAL_MONTH, 1);
92 break;
93
95 $end_date->increment(IL_CAL_MONTH, 6);
96 break;
97 }
98 $this->period_end_day = $end_date->get(IL_CAL_DATE);
99 }
100
101 public function executeCommand(): ?string
102 {
103 $next_class = $this->ctrl->getNextClass($this);
104 $cmd = $this->ctrl->getCmd("getHTML");
105
106 switch ($next_class) {
107 case "ilcalendarappointmentpresentationgui":
108 $this->ctrl->setReturn($this, "");
110 new ilDate(
111 $this->seed->get(IL_CAL_DATE),
113 ),
114 (array) $this->getCurrentApp()
115 );
116 $this->ctrl->forwardCommand($gui);
117 break;
118
119 default:
120 $this->ctrl->setReturn($this, "");
121 if (in_array($cmd, array("getHTML", "getModalForApp"))) {
122 return $this->$cmd();
123 }
124 }
125 return '';
126 }
127
128 public function getHTML(): string
129 {
130 $navigation = new ilCalendarHeaderNavigationGUI(
131 $this,
132 new ilDate($this->seed->get(IL_CAL_DATE), IL_CAL_DATE),
134 );
135 $navigation->getHTML();
136
137 // set return now (after header navigation) to the list (e.g. for profile links)
138 $this->ctrl->setReturn($this, "");
139
140 // get events
141 $events = $this->getEvents();
142 $events = ilArrayUtil::sortArray($events, "dstart", "asc", true);
143
144 $df = new \ILIAS\Data\Factory();
145 $items = array();
146 $groups = array();
147 $modals = array();
148 $group_date = new ilDate(0, IL_CAL_UNIX);
149 $end_day = new ilDate($this->period_end_day, IL_CAL_DATE);
150 $end_day->increment(ilDateTime::DAY, -1);
151 foreach ($events as $e) {
152 if ($e['event']->isFullDay()) {
153 // begin/end is Date (without timzone)
154 $begin = new ilDate($e['dstart'], IL_CAL_UNIX);
155 $end = new ilDate($e['dend'], IL_CAL_UNIX);
156 } else {
157 // begin/end is DateTime (with timezone conversion)
158 $begin = new ilDateTime($e['dstart'], IL_CAL_UNIX);
159 $end = new ilDateTime($e['dend'], IL_CAL_UNIX);
160 }
161
162 // if the begin is before seed date (due to timezone conversion) => continue
164 $begin,
165 $this->seed,
167 $this->user->getTimeZone()
168 )) {
169 continue;
170 }
171
173 $begin,
174 $end_day,
176 $this->user->getTimeZone()
177 )
178 ) {
179 break;
180 }
181
182 // initialize group date for first iteration
183 if ($group_date->isNull()) {
184 $group_date = new ilDate(
185 $begin->get(IL_CAL_DATE, '', $this->user->getTimeZone()),
187 );
188 }
189
190 if (!ilDateTime::_equals($group_date, $begin, IL_CAL_DAY, $this->user->getTimeZone())) {
191 // create new group
192 $groups[] = $this->ui_factory->item()->group(
193 ilDatePresentation::formatDate($group_date, false, true),
194 $items
195 );
196
197 $group_date = new ilDate(
198 $begin->get(IL_CAL_DATE, '', $GLOBALS['DIC']->user()->getTimezone()),
200 );
201 $items = [];
202 }
203
204 // get calendar
205 $cat_id = ilCalendarCategoryAssignments::_lookupCategory($e["event"]->getEntryId());
206 $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
207
208 /*TODO:
209 * All this code related with the ctrl and shy button can be centralized in
210 * ilCalendarViewGUI refactoring the method getAppointmentShyButton or
211 * if we want extend this class from ilCalendarInboxGUI we can just keep it here.
212 */
213
214 // shy button for title
215 $this->ctrl->setParameter($this, 'app_id', $e["event"]->getEntryId());
216 $this->ctrl->setParameter($this, 'dt', $e['dstart']);
217 $this->ctrl->setParameter($this, 'seed', $this->seed->get(IL_CAL_DATE));
218
219
220 $url = $this->ctrl->getLinkTarget($this, "getModalForApp", "", true, false);
221 $this->ctrl->setParameter($this, "app_id", $this->initAppointmentIdFromQuery());
222 $this->ctrl->setParameter($this, "dt", $this->initInitialDateTimeFromQuery());
223 $this->ctrl->setParameter($this, "idate", (new ilDate(time(), IL_CAL_UNIX))->get(IL_CAL_DATE));
224
225 $modal_title = '';
226 if ($this->http->wrapper()->query()->has('modal_title')) {
227 $modal_title = $this->http->wrapper()->query()->retrieve(
228 'modal_title',
229 $this->refinery->kindlyTo()->string()
230 );
231 }
232 $this->ctrl->setParameter($this, 'modal_title', $modal_title);
233 $modal = $this->ui_factory->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
234 $shy = $this->ui_factory->button()->shy(
235 $e["event"]->getPresentationTitle(false),
236 ""
237 )->withOnClick($modal->getShowSignal());
238
239 $modals[] = $modal;
240 if ($e['event']->isFullDay()) {
241 $lead_text = $this->lng->txt("cal_all_day");
242 } else {
243 $lead_text = ilDatePresentation::formatPeriod($begin, $end, true);
244 }
245 $li = $this->ui_factory->item()->standard($shy)
246 ->withDescription("" . nl2br(strip_tags($e["event"]->getDescription())))
247 ->withLeadText($lead_text)
248 ->withProperties([])
249 ->withColor($df->color('#' . $cat_info["color"]));
250
251 if ($li_edited_by_plugin = $this->getPluginAgendaItem($li, $e['event'])) {
252 $li = $li_edited_by_plugin;
253 }
254
255 // add type specific actions/properties
257 new ilDate(
258 $this->seed->get(IL_CAL_DATE),
260 ),
261 $e
262 );
263 $app_gui->setListItemMode($li);
264 $this->ctrl->getHTML($app_gui);
265 $items[] = $app_gui->getListItem();
266 }
267 // terminate last group
268 if (!$group_date->isNull()) {
269 $groups[] = $this->ui_factory->item()->group(
270 ilDatePresentation::formatDate($group_date, false, true),
271 $items
272 );
273 }
274
275 // list actions
276 $images = array_fill(1, 4, "<span class=\"ilAdvNoImg\"></span>");
277
278 $cal_agenda_per = $this->initCalendarPeriodFromRequest();
279 if ($cal_agenda_per > 0) {
280 $images[$cal_agenda_per] = "<img src='./assets/images/standard/icon_checked.svg' alt='Month'>";
281 } else {
282 $images[$this->period] = "<img src='./assets/images/standard/icon_checked.svg' alt='Month'>";
283 }
284
285 #21479 Set seed if the view does not contain any event.
286 $this->ctrl->setParameter($this, 'seed', $this->seed->get(IL_CAL_DATE));
287
288 $items = [];
289 $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_DAY);
290 $items[] = $this->ui_factory->button()->shy(
291 $images[1] . "1 " . $this->lng->txt("day"),
292 $this->ctrl->getLinkTarget($this, "getHTML")
293 );
294 $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_WEEK);
295 $items[] = $this->ui_factory->button()->shy(
296 $images[2] . "1 " . $this->lng->txt("week"),
297 $this->ctrl->getLinkTarget($this, "getHTML")
298 );
299 $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_MONTH);
300 $items[] = $this->ui_factory->button()->shy(
301 $images[3] . "1 " . $this->lng->txt("month"),
302 $this->ctrl->getLinkTarget($this, "getHTML")
303 );
304 $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_HALF_YEAR);
305 $items[] = $this->ui_factory->button()->shy(
306 $images[4] . "6 " . $this->lng->txt("months"),
307 $this->ctrl->getLinkTarget($this, "getHTML")
308 );
309 $this->ctrl->setParameter($this, "cal_agenda_per", $this->period);
310
311 $actions = $this->ui_factory->dropdown()->standard($items)->withLabel($this->lng->txt("cal_period"));
312
313 $list_title =
314 $this->lng->txt("cal_agenda") . ": " . ilDatePresentation::formatDate(new ilDate(
315 $this->seed->get(IL_CAL_DATE),
317 ));
318 if ($this->period != self::PERIOD_DAY) {
319 $end_day = new ilDate($this->period_end_day, IL_CAL_DATE);
320 $end_day->increment(ilDateTime::DAY, -1);
321 $list_title .= " - " . ilDatePresentation::formatDate($end_day);
322 }
323
324 $list = $this->ui_factory->panel()->listing()->standard($list_title, $groups)
325 ->withActions($actions);
326 $comps = array_merge($modals, array($list));
327 $html = $this->ui_renderer->render($comps);
328 if (count($groups) == 0) {
329 $html .= ilUtil::getSystemMessageHTML($this->lng->txt("cal_no_events_info"));
330 }
331 return $html;
332 }
333
334 public function getPluginAgendaItem(Item $a_item, ilCalendarEntry $appointment): ?Item
335 {
336 //"capg" is the plugin slot id for AppointmentCustomGrid
337 $li = null;
338 foreach ($this->getActivePlugins("capg") as $plugin) {
339 $plugin->setAppointment($appointment, $appointment->getStart());
340 // @todo check if last wins is desired
341 $li = $plugin->editAgendaItem($a_item);
342 }
343 return $li;
344 }
345
350 public static function getPeriod(): int
351 {
352 global $DIC;
353
354 $user = $DIC->user();
355
357
358 $calendar_agenda_period = (int) ($DIC->http()->request()->getQueryParams()['cal_agenda_per'] ?? 0);
359 if ($calendar_agenda_period > 0 && $calendar_agenda_period <= 4) {
360 return $calendar_agenda_period;
361 } elseif ($period = $user->getPref('cal_list_view')) {
362 return (int) $period;
363 } else {
364 return $settings->getDefaultPeriod();
365 }
366 }
367}
const IL_CAL_DATE
const IL_CAL_WEEK
const IL_CAL_UNIX
const IL_CAL_MONTH
const IL_CAL_DAY
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
getPluginAgendaItem(Item $a_item, ilCalendarEntry $appointment)
initEndPeriod()
Initialises end date for calendar list view.
static getPeriod()
needed in CalendarInboxGUI to get events using a proper period.
static _getInstance(ilDate $seed, array $a_app)
get singleton instance
static _getInstance($a_usr_id=0)
get singleton instance
Model for a calendar entry.
getStart()
Get start of date period.
getActivePlugins(string $a_slot_id)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
getPref(string $a_keyword)
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
Common interface to all items.
Definition: Item.php:32
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68
$GLOBALS["DIC"]
Definition: wac.php:54