ILIAS  release_8 Revision v8.24
class.ilCalendarSelectionBlockGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22use ILIAS\Refinery\Factory as RefineryFactory;
23use ILIAS\HTTP\Services as HttpServices;
24
32{
33 public static string $block_type = "cal_sel";
34
35 protected const CAL_GRP_CURRENT_CONT_CONS = "curr_cont_cons";
36 protected const CAL_GRP_CURRENT_CONT = "curr_cont";
37 protected const CAL_GRP_PERSONAL = "personal";
38 protected const CAL_GRP_OTHERS = "others";
39
43 protected bool $new_rendering = true;
44
45 protected ilTree $tree;
46 protected RefineryFactory $refinery;
47 protected HttpServices $http;
48
49
50 protected ilDate $seed;
51 protected array $calendar_groups = array();
52 protected array $calendars = array();
53
57 protected int $ref_id = 0;
58
62 protected int $obj_id = 0;
63 protected int $category_id = 0;
64
68 public function __construct(ilDate $a_seed, int $a_ref_id = 0)
69 {
70 global $DIC;
71
73 $this->tree = $DIC->repositoryTree();
74 $this->lng->loadLanguageModule('dash');
75 $this->lng->loadLanguageModule('dateplaner');
76 $this->http = $DIC->http();
77 $this->refinery = $DIC->refinery();
78
79 $this->ref_id = $a_ref_id;
80 $this->obj_id = ilObject::_lookupObjId($this->ref_id);
81 $this->category_id = 0;
82 if ($this->http->wrapper()->query()->has('category_id')) {
83 $this->category_id = $this->http->wrapper()->query()->retrieve(
84 'category_id',
85 $this->refinery->kindlyTo()->int()
86 );
87 }
88
89 $this->setLimit(5);
90 $this->allow_moving = false;
91 $this->seed = $a_seed;
92 $this->setTitle($this->lng->txt('cal_table_categories'));
93
94 $sel_type = ilCalendarUserSettings::_getInstance()->getCalendarSelectionType();
95 $this->ctrl->setParameterByClass(
96 "ilcalendarcategorygui",
97 'calendar_mode',
99 );
100 $this->ctrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
101 // @todo: set checked if ($sel_type == ilCalendarUserSettings::CAL_SELECTION_ITEMS)
102 $this->addBlockCommand(
103 $this->ctrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'),
104 $this->lng->txt('dash_favourites')
105 );
106 $this->ctrl->setParameterByClass(
107 "ilcalendarcategorygui",
108 'calendar_mode',
110 );
111 $this->ctrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
112
113 // @todo: set checked if ($sel_type == ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP)
114 $this->addBlockCommand(
115 $this->ctrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'),
116 $this->lng->txt('dash_memberships')
117 );
118
119 $this->ctrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', "");
120 $this->addBlockCommand(
121 $this->ctrl->getLinkTargetByClass("ilcalendarcategorygui", 'add'),
122 $this->lng->txt('cal_add_calendar')
123 );
124
125 $this->calendar_groups = array(
126 self::CAL_GRP_CURRENT_CONT_CONS => $this->lng->txt("cal_grp_" . self::CAL_GRP_CURRENT_CONT_CONS),
127 self::CAL_GRP_CURRENT_CONT => $this->lng->txt("cal_grp_" . self::CAL_GRP_CURRENT_CONT),
128 self::CAL_GRP_PERSONAL => $this->lng->txt("cal_grp_" . self::CAL_GRP_PERSONAL),
129 self::CAL_GRP_OTHERS => $this->lng->txt("cal_grp_" . self::CAL_GRP_OTHERS)
130 );
131
132 $this->setPresentation(self::PRES_SEC_LEG);
133 }
134
138 protected function isRepositoryObject(): bool
139 {
140 return false;
141 }
142
146 public function getBlockType(): string
147 {
148 return self::$block_type;
149 }
150
154 public static function getScreenMode(): string
155 {
156 global $DIC;
157
158 $ilCtrl = $DIC['ilCtrl'];
159
160 return IL_SCREEN_SIDE;
161 }
162
163 public function executeCommand(): string
164 {
165 $next_class = $this->ctrl->getNextClass();
166 $cmd = $this->ctrl->getCmd("getHTML");
167 switch ($next_class) {
168 default:
169 return $this->$cmd();
170 }
171 }
172
176 public function getCalendars(): void
177 {
178 $hidden_obj = ilCalendarVisibility::_getInstanceByUserId($this->user->getId(), $this->ref_id);
179 $hidden = $hidden_obj->getHidden();
180 $visible = $hidden_obj->getVisible();
181
182 $cats = new ilCalendarCategories($this->user->getId());
183 if ($this->ref_id > 0) {
184 $cats->initialize(ilCalendarCategories::MODE_REPOSITORY, $this->ref_id, true);
187 } else {
189 }
190
191 $all = $cats->getCategoriesInfo();
192 $tmp_title_counter = [];
193 $categories = array();
194 foreach ($all as $category) {
195 //if ($category["obj_id"] == 255)
196 //{var_dump($category); exit;}
197 $tmp_arr['obj_id'] = (int) $category['obj_id'];
198 $tmp_arr['id'] = (int) $category['cat_id'];
199 $tmp_arr['hidden'] = in_array($category['cat_id'], $hidden);
200 $tmp_arr['visible'] = in_array($category['cat_id'], $visible);
201 $tmp_arr['title'] = (string) $category['title'];
202 $tmp_arr['type'] = (string) $category['type'];
203 $tmp_arr['source_ref_id'] = (int) ($category['source_ref_id'] ?? 0);
204 $tmp_arr['default_selected'] = true;
205 if ($this->category_id) {
206 if ($this->category_id == $category['cat_id']) {
207 $tmp_arr['default_selected'] = true;
208 } else {
209 $tmp_arr['default_selected'] = false;
210 }
211 }
212
213 // Append object type to make type sortable
214 $tmp_arr['type_sortable'] = (string) ilCalendarCategory::lookupCategorySortIndex($category['type']);
215 if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
216 $tmp_arr['type_sortable'] .= ('_' . ilObject::_lookupType($category['obj_id']));
217 }
218 $tmp_arr['color'] = (string) $category['color'];
219 $tmp_arr['editable'] = (bool) ($category['editable'] ?? false);
220
221 // reference
222 if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
223 foreach (ilObject::_getAllReferences($category['obj_id']) as $ref_id => $tmp_ref) {
224 if ($this->access->checkAccess('read', '', $ref_id)) {
225 $tmp_arr['ref_id'] = (int) $ref_id;
226 }
227 }
228 }
229
230 $categories[] = $tmp_arr;
231
232 // count title for appending the parent container if there is more than one entry.
233 if (isset($tmp_title_counter[$category['type'] . '_' . $category['title']])) {
234 $tmp_title_counter[$category['type'] . '_' . $category['title']]++;
235 } else {
236 $tmp_title_counter[$category['type'] . '_' . $category['title']] = 1;
237 }
238 }
239
240 $path_categories = array();
241 foreach ($categories as $cat) {
242 $cat['path'] = '';
243 if ($cat['type'] == ilCalendarCategory::TYPE_OBJ) {
244 if (
245 isset($tmp_title_counter[$category['type'] . '_' . $category['title']]) &&
246 $tmp_title_counter[$cat['type'] . '_' . $cat['title']] > 1
247 ) {
248 foreach (ilObject::_getAllReferences($cat['obj_id']) as $ref_id) {
249 $cat['path'] = $this->buildPath($ref_id);
250 break;
251 }
252 }
253 }
254 $path_categories[] = $cat;
255 }
256 $path_categories = ilArrayUtil::sortArray($path_categories, 'title', "asc");
257
258 $this->calendars[self::CAL_GRP_CURRENT_CONT_CONS] = array();
259 $this->calendars[self::CAL_GRP_CURRENT_CONT] = array();
260 $this->calendars[self::CAL_GRP_PERSONAL] = array();
261 $this->calendars[self::CAL_GRP_OTHERS] = array();
262
263 foreach ($path_categories as $cal) {
264 if ($cal["type"] == ilCalendarCategory::TYPE_CH && $this->obj_id > 0) {
265 $this->calendars[self::CAL_GRP_CURRENT_CONT_CONS][] = $cal;
266 } elseif ($cal["type"] == ilCalendarCategory::TYPE_OBJ && ($this->obj_id > 0 && ($cal["obj_id"] == $this->obj_id
267 || $this->ref_id == $cal["source_ref_id"]))) {
268 $this->calendars[self::CAL_GRP_CURRENT_CONT][] = $cal;
269 } elseif ($cal["type"] == ilCalendarCategory::TYPE_USR || $cal["type"] == ilCalendarCategory::TYPE_BOOK ||
270 ($cal["type"] == ilCalendarCategory::TYPE_CH && $this->user->getId() == $cal["obj_id"])) {
271 $this->calendars[self::CAL_GRP_PERSONAL][] = $cal;
272 } else {
273 $this->calendars[self::CAL_GRP_OTHERS][] = $cal;
274 }
275 }
276 }
277
281 protected function buildPath($a_ref_id): string
282 {
283 $obj_type = ilObject::_lookupType($a_ref_id, true);
284 if (!$this->obj_def->isAllowedInRepository($obj_type)) {
285 return '';
286 }
287
288 $path_arr = $this->tree->getPathFull($a_ref_id, ROOT_FOLDER_ID);
289 $counter = 0;
290 unset($path_arr[count($path_arr) - 1]);
291
292 $path = '';
293 foreach ($path_arr as $data) {
294 if ($counter++) {
295 $path .= " -> ";
296 }
297 $path .= $data['title'];
298 }
299 if (strlen($path) > 30) {
300 return '...' . substr($path, -30);
301 }
302 return $path;
303 }
304
305 protected function getLegacyContent(): string
306 {
307 $tpl = new ilTemplate("tpl.cal_selection_block_content.html", true, true, "Services/Calendar");
308
309 foreach ($this->calendar_groups as $type => $txt) {
310 foreach ($this->calendars[$type] as $c) {
311 $this->renderItem($c, $tpl);
312 }
313 if (count($this->calendars[$type]) > 0) {
314 if ($type == self::CAL_GRP_CURRENT_CONT) {
315 $txt = $this->lng->txt("cal_grp_curr_" . ilObject::_lookupType($this->obj_id));
316 }
317 if ($type == self::CAL_GRP_CURRENT_CONT_CONS) {
318 $txt = $this->lng->txt("cal_grp_curr_crs_cons");
319 }
320 $tpl->setCurrentBlock("item_grp");
321 $tpl->setVariable("GRP_HEAD", $txt);
323 }
324 }
325
326 $tpl->setVariable("TXT_SHOW", $this->lng->txt("refresh"));
327 $tpl->setVariable("CMD_SHOW", "saveSelection");
328 $tpl->setVariable("TXT_ACTION", $this->lng->txt("select"));
329 $tpl->setVariable("SRC_ACTION", ilUtil::getImagePath("arrow_downright.svg"));
330 $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormActionByClass("ilcalendarcategorygui"));
331 $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
332
333 return $tpl->get();
334 }
335
336 protected function renderItem(array $a_set, ilTemplate $a_tpl): void
337 {
338 if (strlen((string) $a_set['path'])) {
339 $a_tpl->setCurrentBlock('calendar_path');
340 $a_tpl->setVariable('ADD_PATH_INFO', $a_set['path']);
341 $a_tpl->parseCurrentBlock();
342 }
343
344 $a_tpl->setCurrentBlock("item");
345
346 $a_tpl->setVariable('VAL_ID', $a_set['id']);
347 if ($this->obj_id === 0 && $this->category_id === 0) {
348 if (!$a_set['hidden'] && $a_set['default_selected']) {
349 $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
350 }
351 } elseif ($this->obj_id === 0 && $this->category_id > 0) {
352 if (!$a_set['hidden'] && $a_set['default_selected']) {
353 $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
354 }
355 $a_tpl->setVariable('VAL_DISABLED', 'disabled');
356 } elseif ($a_set["obj_id"] == $this->obj_id) {
357 // if calendar is shown and repo object id (course group given)
358 $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
359 $a_tpl->setVariable('VAL_DISABLED', 'disabled');
360 } elseif ($a_set['visible']) {
361 $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
362 }
363 $a_tpl->setVariable('BGCOLOR', $a_set['color']);
364
365 $obj_type = ilObject::_lookupType($a_set['obj_id']);
366 if (
367 ($a_set['type'] == ilCalendarCategory::TYPE_OBJ) &&
368 ($a_set['ref_id'] ?? false)
369 ) {
370 if (!$this->ref_id) {
371 $this->ctrl->setParameterByClass('ilcalendarpresentationgui', 'backpd', 1);
372 }
373 $this->ctrl->setParameterByClass('ilcalendarpresentationgui', 'ref_id', $a_set['ref_id']);
374 switch ($obj_type) {
375 case 'crs':
376 $link = $this->ctrl->getLinkTargetByClass(
377 [
378 ilRepositoryGUI::class,
379 ilObjCourseGUI::class,
380 ilCalendarPresentationGUI::class
381 ],
382 ''
383 );
384 break;
385
386 case 'grp':
387 $link = $this->ctrl->getLinkTargetByClass(
388 [
389 ilRepositoryGUI::class,
390 ilObjGroupGUI::class,
391 ilCalendarPresentationGUI::class
392 ],
393 ''
394 );
395 break;
396
397 case 'tals':
398 $this->ctrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $a_set['id']);
399 $link = $this->ctrl->getLinkTargetByClass("ilcalendarpresentationgui", '');
400 $this->ctrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $this->category_id);
401 break;
402
403 default:
404 $link = ilLink::_getLink($a_set['ref_id']);
405 break;
406 }
407
408 $this->ctrl->clearParameterByClass(ilCalendarPresentationGUI::class, 'ref_id');
409
410 $a_tpl->setVariable('EDIT_LINK', $link);
411 $a_tpl->setVariable('VAL_TITLE', $a_set['title']);
412 } elseif ($a_set['type'] == ilCalendarCategory::TYPE_OBJ) {
413 $a_tpl->setVariable('PLAIN_TITLE', $a_set['title']);
414 } else {
415 $a_tpl->setVariable('VAL_TITLE', $a_set['title']);
416 $this->ctrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $a_set['id']);
417 $a_tpl->setVariable('EDIT_LINK', $this->ctrl->getLinkTargetByClass("ilcalendarpresentationgui", ''));
418 $this->ctrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $this->category_id);
419 $a_tpl->setVariable('TXT_EDIT', $this->lng->txt('edit'));
420 }
421
422 switch ($a_set['type']) {
424 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_calg.svg'));
425 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_system'));
426 break;
427
429 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_usr.svg'));
430 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_personal'));
431 break;
432
434 $img_type = $obj_type === 'tals' ? 'etal' : $obj_type;
435 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_' . $img_type . '.svg'));
436 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_' . $obj_type));
437 break;
438
440 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_book.svg'));
441 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_' . $obj_type));
442 break;
443
445 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_calch.svg'));
446 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_ch_ch'));
447 break;
448 }
449
450 $a_tpl->parseCurrentBlock();
451 }
452
456 public function getHTML(): string
457 {
458 $this->getCalendars();
459 return parent::getHTML();
460 }
461
465 protected function getListItemForData(array $data): ?\ILIAS\UI\Component\Item\Item
466 {
467 $factory = $this->ui->factory();
468 if (isset($data["shy_button"])) {
469 return $factory->item()->standard($data["shy_button"])->withDescription($data["date"]);
470 } else {
471 return $factory->item()->standard($data["date"]);
472 }
473 }
474}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
const IL_SCREEN_SIDE
const IL_CAL_DATE
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
This class represents a block method of a block.
setTitle(string $a_title)
setPresentation(int $type)
ilTemplate $tpl
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
setLimit(int $a_limit)
class for calendar categories
static lookupCategorySortIndex(int $a_type_id)
Lookup sort index of calendar type.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilDate $a_seed, int $a_ref_id=0)
Constructor.
renderItem(array $a_set, ilTemplate $a_tpl)
buildPath($a_ref_id)
Build path for ref id.
getListItemForData(array $data)
Get list item for data array.null|\ILIAS\UI\Component\Item\Item
static _getInstanceByUserId(int $a_user_id, int $a_ref_id=0)
Class for single dates.
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
get(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
Returns a block with all replacements done.
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$c
Definition: cli.php:38
const ROOT_FOLDER_ID
Definition: constants.php:32
$txt
Definition: error.php:13
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
$factory
Definition: metadata.php:75
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$type