ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
41  public function __construct($a_seed, $a_ref_id = 0)
42  {
43  global $ilCtrl, $lng;
44 
45  $this->lng = $lng;
46  parent::__construct();
47  $lng->loadLanguageModule('pd');
48  $lng->loadLanguageModule('dateplaner');
49  $this->ref_id = $a_ref_id;
50  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
51 
52  $this->setLimit(5);
53  $this->allow_moving = false;
54  $this->seed = $a_seed;
55 
56  $this->setTitle($lng->txt('cal_table_categories'));
57 
58  include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
59  $sel_type = ilCalendarUserSettings::_getInstance()->getCalendarSelectionType();
60  $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', ilCalendarUserSettings::CAL_SELECTION_ITEMS);
61  $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
62  $this->addBlockCommand(
63  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'),
64  $lng->txt('pd_my_offers'),
65  "",
66  "",
67  false,
69  );
70  $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP);
71  $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'seed', $this->seed->get(IL_CAL_DATE));
72  $this->addBlockCommand(
73  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'switchCalendarMode'),
74  $lng->txt('pd_my_memberships'),
75  "",
76  "",
77  false,
79  );
80 
81  $ilCtrl->setParameterByClass("ilcalendarcategorygui", 'calendar_mode', "");
82  $this->addBlockCommand(
83  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'add'),
84  $lng->txt('cal_add_calendar')
85  );
86 
87  $this->calendar_groups = array(
88  self::CAL_GRP_CURRENT_CONT_CONS => $lng->txt("cal_grp_" . self::CAL_GRP_CURRENT_CONT_CONS),
89  self::CAL_GRP_CURRENT_CONT => $lng->txt("cal_grp_" . self::CAL_GRP_CURRENT_CONT),
90  self::CAL_GRP_PERSONAL => $lng->txt("cal_grp_" . self::CAL_GRP_PERSONAL),
91  self::CAL_GRP_OTHERS => $lng->txt("cal_grp_" . self::CAL_GRP_OTHERS)
92  );
93  }
94 
100  public static function isRepositoryObject()
101  {
102  return false;
103  }
104 
110  public static function getBlockType()
111  {
112  return self::$block_type;
113  }
114 
118  public static function getScreenMode()
119  {
120  global $ilCtrl;
121 
122  return IL_SCREEN_SIDE;
123  }
124 
128  public function executeCommand()
129  {
130  global $ilCtrl;
131 
132  $next_class = $ilCtrl->getNextClass();
133  $cmd = $ilCtrl->getCmd("getHTML");
134 
135  switch ($next_class) {
136  default:
137  return $this->$cmd();
138  }
139  }
140 
144  public function getCalendars()
145  {
146  global $ilUser,$tree;
147 
148  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
149  include_once('./Services/Calendar/classes/class.ilCalendarVisibility.php');
150 
151  $hidden_obj = ilCalendarVisibility::_getInstanceByUserId($ilUser->getId(), $this->ref_id);
152  $hidden = $hidden_obj->getHidden();
153  $visible = $hidden_obj->getVisible();
154 
155  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
156  $all = $cats->getCategoriesInfo();
157  $tmp_title_counter = array();
158  $categories = array();
159  foreach ($all as $category) {
160  //if ($category["obj_id"] == 255)
161  //{var_dump($category); exit;}
162  $tmp_arr['obj_id'] = $category['obj_id'];
163  $tmp_arr['id'] = $category['cat_id'];
164  $tmp_arr['hidden'] = (bool) in_array($category['cat_id'], $hidden);
165  $tmp_arr['visible'] = (bool) in_array($category['cat_id'], $visible);
166  $tmp_arr['title'] = $category['title'];
167  $tmp_arr['type'] = $category['type'];
168  $tmp_arr['source_ref_id'] = $category['source_ref_id'];
169 
170  // Append object type to make type sortable
171  $tmp_arr['type_sortable'] = ilCalendarCategory::lookupCategorySortIndex($category['type']);
172  if ($category['type'] == ilCalendarCategory::TYPE_OBJ) {
173  $tmp_arr['type_sortable'] .= ('_' . ilObject::_lookupType($category['obj_id']));
174  }
175 
176  $tmp_arr['color'] = $category['color'];
177  $tmp_arr['editable'] = $category['editable'];
178 
179  $categories[] = $tmp_arr;
180 
181  // count title for appending the parent container if there is more than one entry.
182  $tmp_title_counter[$category['type'] . '_' . $category['title']]++;
183  }
184 
185  $path_categories = array();
186  foreach ($categories as $cat) {
187  if ($cat['type'] == ilCalendarCategory::TYPE_OBJ) {
188  if ($tmp_title_counter[$cat['type'] . '_' . $cat['title']] > 1) {
189  foreach (ilObject::_getAllReferences($cat['obj_id']) as $ref_id) {
190  $cat['path'] = $this->buildPath($ref_id);
191  break;
192  }
193  }
194  }
195  $path_categories[] = $cat;
196  }
197  $path_categories = ilUtil::sortArray($path_categories, 'title', "asc");
198 
199 
200  $this->calendars[self::CAL_GRP_CURRENT_CONT_CONS] = array();
201  $this->calendars[self::CAL_GRP_CURRENT_CONT] = array();
202  $this->calendars[self::CAL_GRP_PERSONAL] = array();
203  $this->calendars[self::CAL_GRP_OTHERS] = array();
204 
205  foreach ($path_categories as $cal) {
206  if ($cal["type"] == ilCalendarCategory::TYPE_CH && $this->obj_id > 0) {
207  $this->calendars[self::CAL_GRP_CURRENT_CONT_CONS][] = $cal;
208  } elseif ($cal["type"] == ilCalendarCategory::TYPE_OBJ && ($this->obj_id > 0 && ($cal["obj_id"] == $this->obj_id
209  || $this->ref_id == $cal["source_ref_id"]))) {
210  $this->calendars[self::CAL_GRP_CURRENT_CONT][] = $cal;
211  } elseif ($cal["type"] == ilCalendarCategory::TYPE_USR || $cal["type"] == ilCalendarCategory::TYPE_BOOK ||
212  ($cal["type"] == ilCalendarCategory::TYPE_CH && $this->user->getId() == $cal["obj_id"])) {
213  $this->calendars[self::CAL_GRP_PERSONAL][] = $cal;
214  } else {
215  $this->calendars[self::CAL_GRP_OTHERS][] = $cal;
216  }
217  }
218  }
219 
225  protected function buildPath($a_ref_id)
226  {
227  global $tree;
228 
229  $path_arr = $tree->getPathFull($a_ref_id, ROOT_FOLDER_ID);
230  $counter = 0;
231  unset($path_arr[count($path_arr) - 1]);
232 
233  foreach ($path_arr as $data) {
234  if ($counter++) {
235  $path .= " -> ";
236  }
237  $path .= $data['title'];
238  }
239  if (strlen($path) > 30) {
240  return '...' . substr($path, -30);
241  }
242  return $path;
243  }
244 
245 
249  public function fillDataSection()
250  {
251  global $lng, $ilCtrl;
252 
253  $tpl = new ilTemplate("tpl.cal_selection_block_content.html", true, true, "Services/Calendar");
254 
255  foreach ($this->calendar_groups as $type => $txt) {
256  foreach ($this->calendars[$type] as $c) {
257  $this->renderItem($c, $tpl);
258  }
259  if (count($this->calendars[$type]) > 0) {
260  if ($type == self::CAL_GRP_CURRENT_CONT) {
261  $txt = $lng->txt("cal_grp_curr_" . ilObject::_lookupType($this->obj_id));
262  }
263  if ($type == self::CAL_GRP_CURRENT_CONT_CONS) {
264  $txt = $lng->txt("cal_grp_curr_crs_cons");
265  }
266  $tpl->setCurrentBlock("item_grp");
267  $tpl->setVariable("GRP_HEAD", $txt);
268  $tpl->parseCurrentBlock();
269  }
270  }
271 
272  $tpl->setVariable("TXT_SHOW", $lng->txt("refresh"));
273  $tpl->setVariable("CMD_SHOW", "saveSelection");
274  $tpl->setVariable("TXT_ACTION", $lng->txt("select"));
275  $tpl->setVariable("SRC_ACTION", ilUtil::getImagePath("arrow_downright.svg"));
276  $tpl->setVariable("FORM_ACTION", $ilCtrl->getFormActionByClass("ilcalendarcategorygui"));
277  $tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
278 
279  $this->setDataSection($tpl->get());
280  }
281 
287  protected function renderItem($a_set, $a_tpl)
288  {
289  global $ilCtrl;
290 
291  if (strlen($a_set['path'])) {
292  $a_tpl->setCurrentBlock('calendar_path');
293  $a_tpl->setVariable('ADD_PATH_INFO', $a_set['path']);
294  $a_tpl->parseCurrentBlock();
295  }
296 
297  $a_tpl->setCurrentBlock("item");
298 
299  $a_tpl->setVariable('VAL_ID', $a_set['id']);
300  if ($this->obj_id == 0) {
301  if (!$a_set['hidden']) {
302  $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
303  }
304  } else { // if calendar is shown and repo object id (course group given)
305  if ($a_set["obj_id"] == $this->obj_id) {
306  $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
307  $a_tpl->setVariable('VAL_DISABLED', 'disabled');
308  } elseif ($a_set['visible']) {
309  $a_tpl->setVariable('VAL_CHECKED', 'checked="checked"');
310  }
311  }
312  $a_tpl->setVariable('VAL_TITLE', $a_set['title']);
313  $a_tpl->setVariable('BGCOLOR', $a_set['color']);
314 
315  $ilCtrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $a_set['id']);
316  $a_tpl->setVariable('EDIT_LINK', $ilCtrl->getLinkTargetByClass("ilcalendarpresentationgui", ''));
317  $ilCtrl->setParameterByClass("ilcalendarpresentationgui", 'category_id', $_GET["category_id"]);
318  $a_tpl->setVariable('TXT_EDIT', $this->lng->txt('edit'));
319 
320  switch ($a_set['type']) {
322  $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_calg.svg'));
323  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_system'));
324  break;
325 
327  $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_usr.svg'));
328  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_personal'));
329  break;
330 
332  $type = ilObject::_lookupType($a_set['obj_id']);
333  $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_' . $type . '.svg'));
334  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_' . $type));
335  break;
336 
338  $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_book.svg'));
339  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_' . $type));
340  break;
341 
343  $a_tpl->setVariable('IMG_SRC', ilUtil::getImagePath('icon_calch.svg'));
344  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_ch_ch'));
345  break;
346  }
347 
348  $a_tpl->parseCurrentBlock();
349  }
350 
354  public function getHTML()
355  {
356  global $ilCtrl, $lng, $ilUser, $ilAccess, $ilSetting;
357 
358  $this->getCalendars();
359 
360  return parent::getHTML();
361  }
362 }
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.
$type
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
$counter
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)
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 _getInstance($a_usr_id=0)
get singleton instance
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static isRepositoryObject()
Is this a repository object.
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