ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 include_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;
51  parent::__construct();
52  $lng->loadLanguageModule('pd');
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  $this->addBlockCommand(
70  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'),
71  $lng->txt('pd_my_offers'),
72  "",
73  "",
74  false,
76  );
77  $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP);
78  $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
79  $this->addBlockCommand(
80  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'),
81  $lng->txt('pd_my_memberships'),
82  "",
83  "",
84  false,
86  );
87 
88  $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', "");
89  $this->addBlockCommand(
90  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'add'),
91  $lng->txt('cal_add_calendar')
92  );
93 
94  $this->calendar_groups = array(
95  self::CAL_GRP_CURRENT_CONT_CONS => $lng->txt("cal_grp_" . self::CAL_GRP_CURRENT_CONT_CONS),
96  self::CAL_GRP_CURRENT_CONT => $lng->txt("cal_grp_" . self::CAL_GRP_CURRENT_CONT),
97  self::CAL_GRP_PERSONAL => $lng->txt("cal_grp_" . self::CAL_GRP_PERSONAL),
98  self::CAL_GRP_OTHERS => $lng->txt("cal_grp_" . self::CAL_GRP_OTHERS)
99  );
100  }
101 
105  protected function isRepositoryObject() : bool
106  {
107  return false;
108  }
109 
113  public function getBlockType() : string
114  {
115  return self::$block_type;
116  }
117 
121  public static function getScreenMode()
122  {
123  global $DIC;
124 
125  $ilCtrl = $DIC['ilCtrl'];
126 
127  return IL_SCREEN_SIDE;
128  }
129 
133  public function executeCommand()
134  {
135  global $DIC;
136 
137  $ilCtrl = $DIC['ilCtrl'];
138 
139  $next_class = $ilCtrl->getNextClass();
140  $cmd = $ilCtrl->getCmd("getHTML");
141 
142  switch ($next_class) {
143  default:
144  return $this->$cmd();
145  }
146  }
147 
151  public function getCalendars()
152  {
153  global $DIC;
154 
155  $ilUser = $DIC['ilUser'];
156  $tree = $DIC['tree'];
157  $access = $DIC->access();
158 
159  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
160  include_once('./Services/Calendar/classes/class.ilCalendarVisibility.php');
161 
163 
164  $hidden = $hidden_obj->getHidden();
165  $visible = $hidden_obj->getVisible();
166 
167  $cats = new ilCalendarCategories($ilUser->getId());
168  if ($this->ref_id > 0) {
169  $cats->initialize(ilCalendarCategories::MODE_REPOSITORY, (int) $this->ref_id, true);
170  } else {
173  } else {
175  }
176  }
177 
178  $all = $cats->getCategoriesInfo();
179  $tmp_title_counter = array();
180  $categories = array();
181  foreach ($all as $category) {
182  //if ($category["obj_id"] == 255)
183  //{var_dump($category); exit;}
184  $tmp_arr['obj_id'] = $category['obj_id'];
185  $tmp_arr['id'] = $category['cat_id'];
186  $tmp_arr['hidden'] = (bool) in_array($category['cat_id'], $hidden);
187  $tmp_arr['visible'] = (bool) in_array($category['cat_id'], $visible);
188  $tmp_arr['title'] = $category['title'];
189  $tmp_arr['type'] = $category['type'];
190  $tmp_arr['source_ref_id'] = $category['source_ref_id'];
191 
192  $tmp_arr['default_selected'] = true;
193  if ($this->category_id) {
194  if ($this->category_id == $category['cat_id']) {
195  $tmp_arr['default_selected'] = true;
196  } else {
197  $tmp_arr['default_selected'] = false;
198  }
199  }
200 
201  // Append object type to make type sortable
202  $tmp_arr['type_sortable'] = ilCalendarCategory::lookupCategorySortIndex($category['type']);
203  if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
204  $tmp_arr['type_sortable'] .= ('_' . ilObject::_lookupType($category['obj_id']));
205  }
206  $tmp_arr['color'] = $category['color'];
207  $tmp_arr['editable'] = $category['editable'];
208 
209  // reference
210  if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
211  foreach (ilObject::_getAllReferences($category['obj_id']) as $ref_id => $tmp_ref) {
212  if ($access->checkAccess('read', '', $ref_id)) {
213  $tmp_arr['ref_id'] = $ref_id;
214  }
215  }
216  }
217 
218  $categories[] = $tmp_arr;
219 
220  // count title for appending the parent container if there is more than one entry.
221  $tmp_title_counter[$category['type'] . '_' . $category['title']]++;
222  }
223 
224  $path_categories = array();
225  foreach ($categories as $cat) {
226  if ($cat['type'] == ilCalendarCategory::TYPE_OBJ) {
227  if ($tmp_title_counter[$cat['type'] . '_' . $cat['title']] > 1) {
228  foreach (ilObject::_getAllReferences($cat['obj_id']) as $ref_id) {
229  $cat['path'] = $this->buildPath($ref_id);
230  break;
231  }
232  }
233  }
234  $path_categories[] = $cat;
235  }
236  $path_categories = ilUtil::sortArray($path_categories, 'title', "asc");
237 
238 
239  $this->calendars[self::CAL_GRP_CURRENT_CONT_CONS] = array();
240  $this->calendars[self::CAL_GRP_CURRENT_CONT] = array();
241  $this->calendars[self::CAL_GRP_PERSONAL] = array();
242  $this->calendars[self::CAL_GRP_OTHERS] = array();
243 
244  foreach ($path_categories as $cal) {
245  if ($cal["type"] == ilCalendarCategory::TYPE_CH && $this->obj_id > 0) {
246  $this->calendars[self::CAL_GRP_CURRENT_CONT_CONS][] = $cal;
247  } elseif ($cal["type"] == ilCalendarCategory::TYPE_OBJ && ($this->obj_id > 0 && ($cal["obj_id"] == $this->obj_id
248  || $this->ref_id == $cal["source_ref_id"]))) {
249  $this->calendars[self::CAL_GRP_CURRENT_CONT][] = $cal;
250  } elseif ($cal["type"] == ilCalendarCategory::TYPE_USR || $cal["type"] == ilCalendarCategory::TYPE_BOOK ||
251  ($cal["type"] == ilCalendarCategory::TYPE_CH && $this->user->getId() == $cal["obj_id"])) {
252  $this->calendars[self::CAL_GRP_PERSONAL][] = $cal;
253  } else {
254  $this->calendars[self::CAL_GRP_OTHERS][] = $cal;
255  }
256  }
257  }
258 
264  protected function buildPath($a_ref_id)
265  {
266  global $DIC;
267 
268  $tree = $DIC['tree'];
269 
270  $path_arr = $tree->getPathFull($a_ref_id, ROOT_FOLDER_ID);
271  $counter = 0;
272  unset($path_arr[count($path_arr) - 1]);
273 
274  foreach ($path_arr as $data) {
275  if ($counter++) {
276  $path .= " -> ";
277  }
278  $path .= $data['title'];
279  }
280  if (strlen($path) > 30) {
281  return '...' . substr($path, -30);
282  }
283  return $path;
284  }
285 
286 
290  public function fillDataSection()
291  {
292  global $DIC;
293 
294  $lng = $DIC['lng'];
295  $ilCtrl = $DIC['ilCtrl'];
296 
297  $tpl = new ilTemplate("tpl.cal_selection_block_content.html", true, true, "Services/Calendar");
298 
299  foreach ($this->calendar_groups as $type => $txt) {
300  foreach ($this->calendars[$type] as $c) {
301  $this->renderItem($c, $tpl);
302  }
303  if (count($this->calendars[$type]) > 0) {
304  if ($type == self::CAL_GRP_CURRENT_CONT) {
305  $txt = $lng->txt("cal_grp_curr_" . ilObject::_lookupType($this->obj_id));
306  }
307  if ($type == self::CAL_GRP_CURRENT_CONT_CONS) {
308  $txt = $lng->txt("cal_grp_curr_crs_cons");
309  }
310  $tpl->setCurrentBlock("item_grp");
311  $tpl->setVariable("GRP_HEAD", $txt);
312  $tpl->parseCurrentBlock();
313  }
314  }
315 
316  $tpl->setVariable("TXT_SHOW", $lng->txt("refresh"));
317  $tpl->setVariable("CMD_SHOW", "saveSelection");
318  $tpl->setVariable("TXT_ACTION", $lng->txt("select"));
319  $tpl->setVariable("SRC_ACTION", ilUtil::getImagePath("arrow_downright.svg"));
320  $tpl->setVariable("FORM_ACTION", $ilCtrl->getFormActionByClass("ilcalendarcategorygui"));
321  $tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
322 
323  $this->setDataSection($tpl->get());
324  }
325 
331  protected function renderItem($a_set, $a_tpl)
332  {
333  global $DIC;
334 
335  $ilCtrl = $DIC->ctrl();
336  $ilUser = $DIC->user();
337 
338  if (strlen($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) {
348  if (!$a_set['hidden'] && $a_set['default_selected']) {
349  $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
350  }
351  } else { // if calendar is shown and repo object id (course group given)
352  if ($a_set["obj_id"] == $this->obj_id) {
353  $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
354  $a_tpl->setVariable('VAL_DISABLED', 'disabled');
355  } elseif ($a_set['visible']) {
356  $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
357  }
358  }
359  $a_tpl->setVariable('BGCOLOR', $a_set['color']);
360 
361 
362  if (
363  ($a_set['type'] == ilCalendarCategory::TYPE_OBJ) &&
364  $a_set['ref_id']
365  ) {
366  # if(
367  # ilCalendarCategories::_getInstance($ilUser->getId())->getMode() == ilCalendarCategories::MODE_PERSONAL_DESKTOP_MEMBERSHIP ||
368  # ilCalendarCategories::_getInstance($ilUser->getId())->getMode() == ilCalendarCategories::MODE_PERSONAL_DESKTOP_ITEMS
369  # )
370  if (!$this->ref_id) {
371  $ilCtrl->setParameterByClass('ilcalendarpresentationgui', 'backpd', 1);
372  }
373  $ilCtrl->setParameterByClass('ilcalendarpresentationgui', 'ref_id', $a_set['ref_id']);
374  switch (ilObject::_lookupType($a_set['obj_id'])) {
375  case 'crs':
376  $link = $ilCtrl->getLinkTargetByClass(
377  [
378  ilRepositoryGUI::class,
379  ilObjCourseGUI::class,
380  ilCalendarPresentationGUI::class
381  ],
382  ''
383  );
384  break;
385 
386  case 'grp':
387  $link = $ilCtrl->getLinkTargetByClass(
388  [
389  ilRepositoryGUI::class,
390  ilObjGroupGUI::class,
391  ilCalendarPresentationGUI::class
392  ],
393  ''
394  );
395  break;
396 
397  default:
398  $link = ilLink::_getLink($a_set['ref_id']);
399  break;
400  }
401 
402  $ilCtrl->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  $ilCtrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $a_set['id']);
411  $a_tpl->setVariable('EDIT_LINK', $ilCtrl->getLinkTargetByClass("ilcalendarpresentationgui", ''));
412  $ilCtrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $_GET["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('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('icon_usr.svg'));
424  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_personal'));
425  break;
426 
428  $type = ilObject::_lookupType($a_set['obj_id']);
429  $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_' . $type . '.svg'));
430  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_' . $type));
431  break;
432 
434  $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_book.svg'));
435  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_' . $type));
436  break;
437 
439  $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('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()
451  {
452  global $DIC;
453 
454  $ilCtrl = $DIC['ilCtrl'];
455  $lng = $DIC['lng'];
456  $ilUser = $DIC['ilUser'];
457  $ilAccess = $DIC['ilAccess'];
458  $ilSetting = $DIC['ilSetting'];
459 
460  $this->getCalendars();
461 
462  return parent::getHTML();
463  }
464 }
class for calendar categories
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static lookupCategorySortIndex($a_type_id)
Lookup sort index of calendar type.
$path
Definition: aliased.php:25
$type
global $DIC
Definition: saml.php:7
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
$_GET["client_id"]
BlockGUI class calendar selection.
user()
Definition: user.php:4
static _getAllReferences($a_id)
get all reference ids of object
global $ilCtrl
Definition: ilias.php:18
static _getInstanceByUserId($a_user_id, $a_ref_id=0)
get instance by user id
setTitle($a_title)
Set Title.
__construct($a_seed, $a_ref_id=0)
Constructor.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static _getInstance()
get instance for logged in user
static _lookupObjId($a_id)
initialize($a_mode, $a_source_ref_id=0, $a_use_cache=false, $a_cat_id=0)
initialize visible categories
special template class to simplify handling of ITX/PEAR
$ilUser
Definition: imgupload.php:18
buildPath($a_ref_id)
Build path for ref id.
$txt
Definition: error.php:11
static _lookupType($a_id, $a_reference=false)
lookup object type
addBlockCommand( $a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
setLimit($a_limit)
Set Limit.
const IL_CAL_DATE
global $ilSetting
Definition: privfeed.php:17
This class represents a block method of a block.
static getScreenMode()
Get Screen Mode for current command.
const IL_SCREEN_SIDE