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