ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilCalendarSelectionBlockGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Block/classes/class.ilBlockGUI.php");
6
16{
17 public static $block_type = "cal_sel";
18
19 const CAL_GRP_CURRENT_CONT_CONS = "curr_cont_cons";
20 const CAL_GRP_CURRENT_CONT = "curr_cont";
21 const CAL_GRP_PERSONAL = "personal";
22 const CAL_GRP_OTHERS = "others";
23
24
25 protected $calendar_groups = array();
26 protected $calendars = array();
27
31 protected $ref_id = 0;
32
36 protected $obj_id = 0;
37
38 protected $category_id = 0;
39
43 public function __construct($a_seed, $a_ref_id = 0)
44 {
45 global $DIC;
46
47 $ilCtrl = $DIC['ilCtrl'];
48 $lng = $DIC['lng'];
49
50 $this->lng = $lng;
52 $lng->loadLanguageModule('dash');
53 $lng->loadLanguageModule('dateplaner');
54 $this->ref_id = $a_ref_id;
55 $this->obj_id = ilObject::_lookupObjId($this->ref_id);
56
57 $this->category_id = $_GET['category_id'];
58
59 $this->setLimit(5);
60 $this->allow_moving = false;
61 $this->seed = $a_seed;
62
63 $this->setTitle($lng->txt('cal_table_categories'));
64
65 include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
66 $sel_type = ilCalendarUserSettings::_getInstance()->getCalendarSelectionType();
67 $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', ilCalendarUserSettings::CAL_SELECTION_ITEMS);
68 $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
69 // @todo: set checked if ($sel_type == ilCalendarUserSettings::CAL_SELECTION_ITEMS)
70 $this->addBlockCommand(
71 $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'),
72 $lng->txt('dash_favourites')
73 );
74 $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP);
75 $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
76
77 // @todo: set checked if ($sel_type == ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP)
78 $this->addBlockCommand(
79 $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'),
80 $lng->txt('dash_memberships')
81 );
82
83 $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', "");
84 $this->addBlockCommand(
85 $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'add'),
86 $lng->txt('cal_add_calendar')
87 );
88
89 $this->calendar_groups = array(
90 self::CAL_GRP_CURRENT_CONT_CONS => $lng->txt("cal_grp_" . self::CAL_GRP_CURRENT_CONT_CONS),
91 self::CAL_GRP_CURRENT_CONT => $lng->txt("cal_grp_" . self::CAL_GRP_CURRENT_CONT),
92 self::CAL_GRP_PERSONAL => $lng->txt("cal_grp_" . self::CAL_GRP_PERSONAL),
93 self::CAL_GRP_OTHERS => $lng->txt("cal_grp_" . self::CAL_GRP_OTHERS)
94 );
95
96 $this->setPresentation(self::PRES_SEC_LEG);
97 }
98
102 protected function isRepositoryObject() : bool
103 {
104 return false;
105 }
106
110 public function getBlockType() : string
111 {
112 return self::$block_type;
113 }
114
118 public static function getScreenMode()
119 {
120 global $DIC;
121
122 $ilCtrl = $DIC['ilCtrl'];
123
124 return IL_SCREEN_SIDE;
125 }
126
130 public function executeCommand()
131 {
132 global $DIC;
133
134 $ilCtrl = $DIC['ilCtrl'];
135
136 $next_class = $ilCtrl->getNextClass();
137 $cmd = $ilCtrl->getCmd("getHTML");
138
139 switch ($next_class) {
140 default:
141 return $this->$cmd();
142 }
143 }
144
148 public function getCalendars()
149 {
150 global $DIC;
151
152 $ilUser = $DIC['ilUser'];
153 $tree = $DIC['tree'];
154 $access = $DIC->access();
155
156 include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
157 include_once('./Services/Calendar/classes/class.ilCalendarVisibility.php');
158
159 $hidden_obj = ilCalendarVisibility::_getInstanceByUserId($ilUser->getId(), $this->ref_id);
160
161 $hidden = $hidden_obj->getHidden();
162 $visible = $hidden_obj->getVisible();
163
164 $cats = new ilCalendarCategories($ilUser->getId());
165 if ($this->ref_id > 0) {
166 $cats->initialize(ilCalendarCategories::MODE_REPOSITORY, (int) $this->ref_id, true);
167 } else {
170 } else {
172 }
173 }
174
175 $all = $cats->getCategoriesInfo();
176 $tmp_title_counter = array();
177 $categories = array();
178 foreach ($all as $category) {
179 //if ($category["obj_id"] == 255)
180 //{var_dump($category); exit;}
181 $tmp_arr['obj_id'] = $category['obj_id'];
182 $tmp_arr['id'] = $category['cat_id'];
183 $tmp_arr['hidden'] = (bool) in_array($category['cat_id'], $hidden);
184 $tmp_arr['visible'] = (bool) in_array($category['cat_id'], $visible);
185 $tmp_arr['title'] = $category['title'];
186 $tmp_arr['type'] = $category['type'];
187 $tmp_arr['source_ref_id'] = $category['source_ref_id'];
188
189 $tmp_arr['default_selected'] = true;
190 if ($this->category_id) {
191 if ($this->category_id == $category['cat_id']) {
192 $tmp_arr['default_selected'] = true;
193 } else {
194 $tmp_arr['default_selected'] = false;
195 }
196 }
197
198 // Append object type to make type sortable
199 $tmp_arr['type_sortable'] = ilCalendarCategory::lookupCategorySortIndex($category['type']);
200 if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
201 $tmp_arr['type_sortable'] .= ('_' . ilObject::_lookupType($category['obj_id']));
202 }
203 $tmp_arr['color'] = $category['color'];
204 $tmp_arr['editable'] = $category['editable'];
205
206 // reference
207 if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
208 foreach (ilObject::_getAllReferences($category['obj_id']) as $ref_id => $tmp_ref) {
209 if ($access->checkAccess('read', '', $ref_id)) {
210 $tmp_arr['ref_id'] = $ref_id;
211 }
212 }
213 }
214
215 $categories[] = $tmp_arr;
216
217 // count title for appending the parent container if there is more than one entry.
218 $tmp_title_counter[$category['type'] . '_' . $category['title']]++;
219 }
220
221 $path_categories = array();
222 foreach ($categories as $cat) {
223 if ($cat['type'] == ilCalendarCategory::TYPE_OBJ) {
224 if ($tmp_title_counter[$cat['type'] . '_' . $cat['title']] > 1) {
225 foreach (ilObject::_getAllReferences($cat['obj_id']) as $ref_id) {
226 $cat['path'] = $this->buildPath($ref_id);
227 break;
228 }
229 }
230 }
231 $path_categories[] = $cat;
232 }
233 $path_categories = ilUtil::sortArray($path_categories, 'title', "asc");
234
235
236 $this->calendars[self::CAL_GRP_CURRENT_CONT_CONS] = array();
237 $this->calendars[self::CAL_GRP_CURRENT_CONT] = array();
238 $this->calendars[self::CAL_GRP_PERSONAL] = array();
239 $this->calendars[self::CAL_GRP_OTHERS] = array();
240
241 foreach ($path_categories as $cal) {
242 if ($cal["type"] == ilCalendarCategory::TYPE_CH && $this->obj_id > 0) {
243 $this->calendars[self::CAL_GRP_CURRENT_CONT_CONS][] = $cal;
244 } elseif ($cal["type"] == ilCalendarCategory::TYPE_OBJ && ($this->obj_id > 0 && ($cal["obj_id"] == $this->obj_id
245 || $this->ref_id == $cal["source_ref_id"]))) {
246 $this->calendars[self::CAL_GRP_CURRENT_CONT][] = $cal;
247 } elseif ($cal["type"] == ilCalendarCategory::TYPE_USR || $cal["type"] == ilCalendarCategory::TYPE_BOOK ||
248 ($cal["type"] == ilCalendarCategory::TYPE_CH && $this->user->getId() == $cal["obj_id"])) {
249 $this->calendars[self::CAL_GRP_PERSONAL][] = $cal;
250 } else {
251 $this->calendars[self::CAL_GRP_OTHERS][] = $cal;
252 }
253 }
254 }
255
261 protected function buildPath($a_ref_id)
262 {
263 global $DIC;
264
265 $tree = $DIC['tree'];
266
267 $path_arr = $tree->getPathFull($a_ref_id, ROOT_FOLDER_ID);
268 $counter = 0;
269 unset($path_arr[count($path_arr) - 1]);
270
271 foreach ($path_arr as $data) {
272 if ($counter++) {
273 $path .= " -> ";
274 }
275 $path .= $data['title'];
276 }
277 if (strlen($path) > 30) {
278 return '...' . substr($path, -30);
279 }
280 return $path;
281 }
282
283
287 public function fillDataSection()
288 {
289 global $DIC;
290
291 $lng = $DIC['lng'];
292 $ilCtrl = $DIC['ilCtrl'];
293
294 $tpl = new ilTemplate("tpl.cal_selection_block_content.html", true, true, "Services/Calendar");
295
296 foreach ($this->calendar_groups as $type => $txt) {
297 foreach ($this->calendars[$type] as $c) {
298 $this->renderItem($c, $tpl);
299 }
300 if (count($this->calendars[$type]) > 0) {
301 if ($type == self::CAL_GRP_CURRENT_CONT) {
302 $txt = $lng->txt("cal_grp_curr_" . ilObject::_lookupType($this->obj_id));
303 }
304 if ($type == self::CAL_GRP_CURRENT_CONT_CONS) {
305 $txt = $lng->txt("cal_grp_curr_crs_cons");
306 }
307 $tpl->setCurrentBlock("item_grp");
308 $tpl->setVariable("GRP_HEAD", $txt);
309 $tpl->parseCurrentBlock();
310 }
311 }
312
313 $tpl->setVariable("TXT_SHOW", $lng->txt("refresh"));
314 $tpl->setVariable("CMD_SHOW", "saveSelection");
315 $tpl->setVariable("TXT_ACTION", $lng->txt("select"));
316 $tpl->setVariable("SRC_ACTION", ilUtil::getImagePath("arrow_downright.svg"));
317 $tpl->setVariable("FORM_ACTION", $ilCtrl->getFormActionByClass("ilcalendarcategorygui"));
318 $tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
319
320 return $tpl->get();
321 }
322
328 protected function renderItem($a_set, $a_tpl)
329 {
330 global $DIC;
331
332 $ilCtrl = $DIC->ctrl();
333 $ilUser = $DIC->user();
334
335 if (strlen($a_set['path'])) {
336 $a_tpl->setCurrentBlock('calendar_path');
337 $a_tpl->setVariable('ADD_PATH_INFO', $a_set['path']);
338 $a_tpl->parseCurrentBlock();
339 }
340
341 $a_tpl->setCurrentBlock("item");
342
343 $a_tpl->setVariable('VAL_ID', $a_set['id']);
344 if ($this->obj_id == 0) {
345 if (!$a_set['hidden'] && $a_set['default_selected']) {
346 $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
347 }
348 } else { // if calendar is shown and repo object id (course group given)
349 if ($a_set["obj_id"] == $this->obj_id) {
350 $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
351 $a_tpl->setVariable('VAL_DISABLED', 'disabled');
352 } elseif ($a_set['visible']) {
353 $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
354 }
355 }
356 $a_tpl->setVariable('BGCOLOR', $a_set['color']);
357
358
359 if (
360 ($a_set['type'] == ilCalendarCategory::TYPE_OBJ) &&
361 $a_set['ref_id']
362 ) {
363 # if(
364 # ilCalendarCategories::_getInstance($ilUser->getId())->getMode() == ilCalendarCategories::MODE_PERSONAL_DESKTOP_MEMBERSHIP ||
365 # ilCalendarCategories::_getInstance($ilUser->getId())->getMode() == ilCalendarCategories::MODE_PERSONAL_DESKTOP_ITEMS
366 # )
367 if (!$this->ref_id) {
368 $ilCtrl->setParameterByClass('ilcalendarpresentationgui', 'backpd', 1);
369 }
370 $ilCtrl->setParameterByClass('ilcalendarpresentationgui', 'ref_id', $a_set['ref_id']);
371 switch (ilObject::_lookupType($a_set['obj_id'])) {
372 case 'crs':
373 $link = $ilCtrl->getLinkTargetByClass(
374 [
375 ilRepositoryGUI::class,
376 ilObjCourseGUI::class,
377 ilCalendarPresentationGUI::class
378 ],
379 ''
380 );
381 break;
382
383 case 'grp':
384 $link = $ilCtrl->getLinkTargetByClass(
385 [
386 ilRepositoryGUI::class,
387 ilObjGroupGUI::class,
388 ilCalendarPresentationGUI::class
389 ],
390 ''
391 );
392 break;
393
394 default:
395 $link = ilLink::_getLink($a_set['ref_id']);
396 break;
397 }
398
399 $ilCtrl->clearParameterByClass(ilCalendarPresentationGUI::class, 'ref_id');
400
401 $a_tpl->setVariable('EDIT_LINK', $link);
402 $a_tpl->setVariable('VAL_TITLE', $a_set['title']);
403 } elseif ($a_set['type'] == ilCalendarCategory::TYPE_OBJ) {
404 $a_tpl->setVariable('PLAIN_TITLE', $a_set['title']);
405 } else {
406 $a_tpl->setVariable('VAL_TITLE', $a_set['title']);
407 $ilCtrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $a_set['id']);
408 $a_tpl->setVariable('EDIT_LINK', $ilCtrl->getLinkTargetByClass("ilcalendarpresentationgui", ''));
409 $ilCtrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $_GET["category_id"]);
410 $a_tpl->setVariable('TXT_EDIT', $this->lng->txt('edit'));
411 }
412
413 switch ($a_set['type']) {
415 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_calg.svg'));
416 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_system'));
417 break;
418
420 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_usr.svg'));
421 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_personal'));
422 break;
423
425 $type = ilObject::_lookupType($a_set['obj_id']);
426 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_' . $type . '.svg'));
427 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_' . $type));
428 break;
429
431 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_book.svg'));
432 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_' . $type));
433 break;
434
436 $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_calch.svg'));
437 $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_ch_ch'));
438 break;
439 }
440
441 $a_tpl->parseCurrentBlock();
442 }
443
447 public function getHTML()
448 {
449 $this->getCalendars();
450 return parent::getHTML();
451 }
452
453 //
454 // New rendering
455 //
456
457 protected $new_rendering = true;
458
462 protected function getLegacyContent() : string
463 {
464 return $this->fillDataSection();
465 }
466
470 protected function getListItemForData(array $data) : \ILIAS\UI\Component\Item\Item
471 {
472 $factory = $this->ui->factory();
473 if (isset($data["shy_button"])) {
474 return $factory->item()->standard($data["shy_button"])->withDescription($data["date"]);
475 } else {
476 return $factory->item()->standard($data["date"]);
477 }
478 }
479}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_SCREEN_SIDE
const IL_CAL_DATE
This class represents a block method of a block.
setLimit($a_limit)
Set Limit.
setPresentation(int $type)
Set presentation.
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
Add Block Command.
setTitle($a_title)
Set Title.
class for calendar categories
static lookupCategorySortIndex($a_type_id)
Lookup sort index of calendar type.
BlockGUI class calendar selection.
static getScreenMode()
Get Screen Mode for current command.
isRepositoryObject()
Returns whether block has a corresponding repository object.bool
buildPath($a_ref_id)
Build path for ref id.
getListItemForData(array $data)
Get list item for data array.null|\ILIAS\UI\Component\Item\Item
__construct($a_seed, $a_ref_id=0)
Constructor.
static _getInstance()
get instance for logged in user
static _getInstanceByUserId($a_user_id, $a_ref_id=0)
get instance by user id
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
special template class to simplify handling of ITX/PEAR
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$txt
Definition: error.php:13
global $ilCtrl
Definition: ilias.php:18
$factory
Definition: metadata.php:58
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$type
$ilUser
Definition: imgupload.php:18
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46