ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarCategoryTableGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('./Services/Table/classes/class.ilTable2GUI.php');
25 
36 {
37  private $seed = null;
38 
46  public function __construct($a_parent_obj, ilDateTime $seed = null)
47  {
48  global $lng,$ilCtrl,$ilUser;
49 
50  $this->lng = $lng;
51  $this->lng->loadLanguageModule('dateplaner');
52  $this->ctrl = $ilCtrl;
53 
54  $this->seed = $seed;
55 
56  $this->setId('calmng');
57 
58  parent::__construct($a_parent_obj,'showCategories');
59  $this->setFormName('categories');
60  $this->addColumn('','',"1", true);
61  $this->addColumn($this->lng->txt('type'),'type_sortable',"1");
62  $this->addColumn($this->lng->txt('title'),'title',"100%");
63  $this->addColumn('','subscription','');
64 
65  $this->ctrl->setParameterByClass(get_class($this->getParentObject()),'seed',$this->seed->get(IL_CAL_DATE));
66  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
67  $this->setRowTemplate("tpl.show_category_row.html","Services/Calendar");
68  $this->disable('sort');
69  if (!$ilUser->prefs["screen_reader_optimization"])
70  {
71  $this->disable('header');
72  }
73 
74  //$this->setShowRowsSelector(true);
75  $this->disable('numinfo');
76  $this->enable('select_all');
77  $this->setSelectAllCheckbox('selected_cat_ids');
78  $this->setDisplayAsBlock(true);
79 
80  $this->setDefaultOrderDirection('asc');
81  $this->setDefaultOrderField('type_sortable');
82 
83  // Show add calendar button
84  $this->addCommandButton('add',$this->lng->txt('cal_add_calendar'));
85  }
86 
94  protected function fillRow($a_set)
95  {
96  $this->tpl->setVariable('VAL_ID',$a_set['id']);
97  if(!$a_set['hidden'])
98  {
99  $this->tpl->setVariable('VAL_CHECKED','checked="checked"');
100  }
101  $this->tpl->setVariable('VAL_TITLE',$a_set['title']);
102  $this->tpl->setVariable('BGCOLOR',$a_set['color']);
103 
104  $this->ctrl->setParameter($this->getParentObject(),'category_id',$a_set['id']);
105  $this->tpl->setVariable('EDIT_LINK',$this->ctrl->getLinkTarget($this->getParentObject(),'details'));
106  $this->tpl->setVariable('TXT_EDIT',$this->lng->txt('edit'));
107 
108  switch($a_set['type'])
109  {
111  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_calg_s.png'));
112  $this->tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_system'));
113  break;
114 
116  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_usr_s.png'));
117  $this->tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_personal'));
118  break;
119 
121  $type = ilObject::_lookupType($a_set['obj_id']);
122  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_'.$type.'_s.png'));
123  $this->tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_'.$type));
124  break;
125  }
126  if(strlen($a_set['path']))
127  {
128  $this->tpl->setCurrentBlock('calendar_path');
129  $this->tpl->setVariable('ADD_PATH_INFO',$a_set['path']);
130  $this->tpl->parseCurrentBlock();
131  }
132 
133  // Subscription link
134  $this->tpl->setVariable('SUB_SRC',ilUtil::getImagePath('ical.png','Services/Calendar'));
135  $this->ctrl->setParameterByClass('ilcalendarsubscriptiongui','seed',$this->seed->get(IL_CAL_DATE));
136  $this->ctrl->setParameterByClass('ilcalendarsubscriptiongui','cal_id',$a_set['id']);
137  $this->tpl->setVariable('SUB_LINK',$this->ctrl->getLinkTargetByClass(array('ilcalendarpresentationgui','ilcalendarsubscriptiongui')));
138  $this->tpl->setVariable('SUB_ALT',$this->lng->txt('ical_export'));
139 
140  }
141 
148  public function parse()
149  {
150  global $ilUser,$tree;
151 
152  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
153  include_once('./Services/Calendar/classes/class.ilCalendarHidden.php');
154 
155  $hidden_obj = ilCalendarHidden::_getInstanceByUserId($ilUser->getId());
156  $hidden = $hidden_obj->getHidden();
157 
158  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
159  $all = $cats->getCategoriesInfo();
160  $tmp_title_counter = array();
161  $categories = array();
162  foreach($all as $category)
163  {
164  $tmp_arr['obj_id'] = $category['obj_id'];
165  $tmp_arr['id'] = $category['cat_id'];
166  $tmp_arr['hidden'] = (bool) in_array($category['cat_id'],$hidden);
167  $tmp_arr['title'] = $category['title'];
168  $tmp_arr['type'] = $category['type'];
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  {
174  $tmp_arr['type_sortable'] .= ('_'.ilObject::_lookupType($category['obj_id']));
175  }
176 
177  $tmp_arr['color'] = $category['color'];
178  $tmp_arr['editable'] = $category['editable'];
179 
180  $categories[] = $tmp_arr;
181 
182  // count title for appending the parent container if there is more than one entry.
183  $tmp_title_counter[$category['type'].'_'.$category['title']]++;
184 
185  }
186 
187  $path_categories = array();
188  foreach($categories as $cat)
189  {
190  if($cat['type'] == ilCalendarCategory::TYPE_OBJ)
191  {
192  if($tmp_title_counter[$cat['type'].'_'.$cat['title']] > 1)
193  {
194  foreach(ilObject::_getAllReferences($cat['obj_id']) as $ref_id)
195  {
196  $cat['path'] = $this->buildPath($ref_id);
197  break;
198  }
199  }
200  }
201  $path_categories[] = $cat;
202  }
203  $this->setData($path_categories);
204  }
205 
206  protected function buildPath($a_ref_id)
207  {
208  global $tree;
209 
210  $path_arr = $tree->getPathFull($a_ref_id,ROOT_FOLDER_ID);
211  $counter = 0;
212  unset($path_arr[count($path_arr) - 1]);
213 
214  foreach($path_arr as $data)
215  {
216  if($counter++)
217  {
218  $path .= " -> ";
219  }
220  $path .= $data['title'];
221  }
222  if(strlen($path) > 30)
223  {
224  return '...'.substr($path,-30);
225  }
226  return $path;
227  }
228 
229 }
230 ?>