ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  static $block_type = "cal_sel";
18 
22  function ilCalendarSelectionBlockGUI($a_seed)
23  {
24  global $ilCtrl, $lng;
25 
26  $this->lng = $lng;
27  parent::__construct();
28  $lng->loadLanguageModule('pd');
29  $lng->loadLanguageModule('dateplaner');
30 
31  $this->setLimit(5);
32  $this->allow_moving = false;
33  $this->seed = $a_seed;
34 
35  $this->setTitle($lng->txt('cal_table_categories'));
36 
37  include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
38  $sel_type = ilCalendarUserSettings::_getInstance()->getCalendarSelectionType();
39  $ilCtrl->setParameterByClass("ilcalendarcategorygui",'calendar_mode',ilCalendarUserSettings::CAL_SELECTION_ITEMS);
40  $ilCtrl->setParameterByClass("ilcalendarcategorygui",'seed',$this->seed->get(IL_CAL_DATE));
41  $this->addBlockCommand(
42  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui",'switchCalendarMode'),
43  $lng->txt('pd_my_offers'), "", "", false,
45  );
46  $ilCtrl->setParameterByClass("ilcalendarcategorygui",'calendar_mode',ilCalendarUserSettings::CAL_SELECTION_MEMBERSHIP);
47  $ilCtrl->setParameterByClass("ilcalendarcategorygui",'seed',$this->seed->get(IL_CAL_DATE));
48  $this->addBlockCommand(
49  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui",'switchCalendarMode'),
50  $lng->txt('pd_my_memberships'), "", "", false,
52  );
53 
54  $ilCtrl->setParameterByClass("ilcalendarcategorygui",'calendar_mode',"");
55  $this->addBlockCommand(
56  $ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'add'),
57  $lng->txt('cal_add_calendar')
58  );
59  }
60 
66  static function isRepositoryObject()
67  {
68  return false;
69  }
70 
76  static function getBlockType()
77  {
78  return self::$block_type;
79  }
80 
84  static function getScreenMode()
85  {
86  global $ilCtrl;
87 
88  return IL_SCREEN_SIDE;
89  }
90 
94  function &executeCommand()
95  {
96  global $ilCtrl;
97 
98  $next_class = $ilCtrl->getNextClass();
99  $cmd = $ilCtrl->getCmd("getHTML");
100 
101  switch ($next_class)
102  {
103  default:
104  return $this->$cmd();
105  }
106  }
107 
111  public function getCalendars()
112  {
113  global $ilUser,$tree;
114 
115  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
116  include_once('./Services/Calendar/classes/class.ilCalendarHidden.php');
117 
118  $hidden_obj = ilCalendarHidden::_getInstanceByUserId($ilUser->getId());
119  $hidden = $hidden_obj->getHidden();
120 
121  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
122  $all = $cats->getCategoriesInfo();
123  $tmp_title_counter = array();
124  $categories = array();
125  foreach($all as $category)
126  {
127  $tmp_arr['obj_id'] = $category['obj_id'];
128  $tmp_arr['id'] = $category['cat_id'];
129  $tmp_arr['hidden'] = (bool) in_array($category['cat_id'],$hidden);
130  $tmp_arr['title'] = $category['title'];
131  $tmp_arr['type'] = $category['type'];
132 
133  // Append object type to make type sortable
134  $tmp_arr['type_sortable'] = ilCalendarCategory::lookupCategorySortIndex($category['type']);
135  if($category['type'] == ilCalendarCategory::TYPE_OBJ)
136  {
137  $tmp_arr['type_sortable'] .= ('_'.ilObject::_lookupType($category['obj_id']));
138  }
139 
140  $tmp_arr['color'] = $category['color'];
141  $tmp_arr['editable'] = $category['editable'];
142 
143  $categories[] = $tmp_arr;
144 
145  // count title for appending the parent container if there is more than one entry.
146  $tmp_title_counter[$category['type'].'_'.$category['title']]++;
147 
148  }
149 
150  $path_categories = array();
151  foreach($categories as $cat)
152  {
153  if($cat['type'] == ilCalendarCategory::TYPE_OBJ)
154  {
155  if($tmp_title_counter[$cat['type'].'_'.$cat['title']] > 1)
156  {
157  foreach(ilObject::_getAllReferences($cat['obj_id']) as $ref_id)
158  {
159  $cat['path'] = $this->buildPath($ref_id);
160  break;
161  }
162  }
163  }
164  $path_categories[] = $cat;
165  }
166  $path_categories = ilUtil::sortArray($path_categories, 'title', "asc");
167 
168  $this->calendars = $path_categories;
169  }
170 
176  protected function buildPath($a_ref_id)
177  {
178  global $tree;
179 
180  $path_arr = $tree->getPathFull($a_ref_id,ROOT_FOLDER_ID);
181  $counter = 0;
182  unset($path_arr[count($path_arr) - 1]);
183 
184  foreach($path_arr as $data)
185  {
186  if($counter++)
187  {
188  $path .= " -> ";
189  }
190  $path .= $data['title'];
191  }
192  if(strlen($path) > 30)
193  {
194  return '...'.substr($path,-30);
195  }
196  return $path;
197  }
198 
199 
203  function fillDataSection()
204  {
205  global $lng, $ilCtrl;
206 
207  $tpl = new ilTemplate("tpl.cal_selection_block_content.html", true, true, "Services/Calendar");
208 
209  foreach ($this->calendars as $c)
210  {
211  $this->renderItem($c, $tpl);
212  }
213 
214  $tpl->setVariable("TXT_SHOW", $lng->txt("select"));
215  $tpl->setVariable("CMD_SHOW", "saveSelection");
216  $tpl->setVariable("TXT_ACTION", $lng->txt("select"));
217  $tpl->setVariable("SRC_ACTION", ilUtil::getImagePath("arrow_downright.png"));
218  $tpl->setVariable("FORM_ACTION", $ilCtrl->getFormActionByClass("ilcalendarcategorygui"));
219  $tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
220 
221  $this->setDataSection($tpl->get());
222  }
223 
229  protected function renderItem($a_set, $a_tpl)
230  {
231  global $ilCtrl;
232 
233  if(strlen($a_set['path']))
234  {
235  $a_tpl->setCurrentBlock('calendar_path');
236  $a_tpl->setVariable('ADD_PATH_INFO',$a_set['path']);
237  $a_tpl->parseCurrentBlock();
238  }
239 
240  $a_tpl->setCurrentBlock("item");
241 
242  $a_tpl->setVariable('VAL_ID',$a_set['id']);
243  if(!$a_set['hidden'])
244  {
245  $a_tpl->setVariable('VAL_CHECKED','checked="checked"');
246  }
247  $a_tpl->setVariable('VAL_TITLE',$a_set['title']);
248  $a_tpl->setVariable('BGCOLOR',$a_set['color']);
249 
250  $ilCtrl->setParameterByClass("ilcalendarcategorygui",'category_id',$a_set['id']);
251  $a_tpl->setVariable('EDIT_LINK',$ilCtrl->getLinkTargetByClass("ilcalendarcategorygui", 'details'));
252  $a_tpl->setVariable('TXT_EDIT',$this->lng->txt('edit'));
253 
254  switch($a_set['type'])
255  {
257  $a_tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_calg_s.png'));
258  $a_tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_system'));
259  break;
260 
262  $a_tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_usr_s.png'));
263  $a_tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_personal'));
264  break;
265 
267  $type = ilObject::_lookupType($a_set['obj_id']);
268  $a_tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_'.$type.'_s.png'));
269  $a_tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_'.$type));
270  break;
271 
273  $a_tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_book_s.png'));
274  $a_tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_'.$type));
275  break;
276  }
277 
278  $a_tpl->parseCurrentBlock();
279  }
280 
284  function getHTML()
285  {
286  global $ilCtrl, $lng, $ilUser, $ilAccess, $ilSetting;
287 
288  $this->getCalendars();
289 
290  return parent::getHTML();
291  }
292 }
293 
294 ?>