ILIAS  eassessment Revision 61809
 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 {
44  public function __construct($a_parent_obj)
45  {
46  global $lng,$ilCtrl,$ilUser;
47 
48  $this->lng = $lng;
49  $this->lng->loadLanguageModule('dateplaner');
50  $this->ctrl = $ilCtrl;
51 
52  parent::__construct($a_parent_obj,'showCategories');
53  $this->setFormName('categories');
54  $this->addColumn('','',"1", true);
55  $this->addColumn($this->lng->txt('type'),'',"1");
56  $this->addColumn($this->lng->txt('title'),'title',"100%");
57 
58  $this->setPrefix('categories');
59  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
60  $this->setRowTemplate("tpl.show_category_row.html","Services/Calendar");
61  $this->disable('sort');
62  if (!$ilUser->prefs["screen_reader_optimization"])
63  {
64  $this->disable('header');
65  }
66  $this->disable('numinfo');
67  $this->enable('select_all');
68  $this->setSelectAllCheckbox('selected_cat_ids');
69  $this->setDisplayAsBlock(true);
70 
71  $this->setDefaultOrderDirection('asc');
72  $this->setDefaultOrderField('title');
73  }
74 
82  protected function fillRow($a_set)
83  {
84  $this->tpl->setVariable('VAL_ID',$a_set['id']);
85  if(!$a_set['hidden'])
86  {
87  $this->tpl->setVariable('VAL_CHECKED','checked="checked"');
88  }
89  $this->tpl->setVariable('VAL_TITLE',$a_set['title']);
90  $this->tpl->setVariable('BGCOLOR',$a_set['color']);
91 
92  if($a_set['editable'] or 1)
93  {
94  #$this->tpl->setCurrentBlock('title_link');
95  $this->ctrl->setParameter($this->getParentObject(),'category_id',$a_set['id']);
96  $this->tpl->setVariable('EDIT_LINK',$this->ctrl->getLinkTarget($this->getParentObject(),'details'));
97  $this->tpl->setVariable('TXT_EDIT',$this->lng->txt('edit'));
98  #$this->tpl->parseCurrentBlock();
99  }
100  switch($a_set['type'])
101  {
103  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_calg_s.gif'));
104  $this->tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_system'));
105  break;
106 
108  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_usr_s.gif'));
109  $this->tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_personal'));
110  break;
111 
113  $type = ilObject::_lookupType($a_set['obj_id']);
114  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_'.$type.'_s.gif'));
115  $this->tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_'.$type));
116  break;
117  }
118  if(strlen($a_set['path']))
119  {
120  $this->tpl->setCurrentBlock('calendar_path');
121  $this->tpl->setVariable('ADD_PATH_INFO',$a_set['path']);
122  $this->tpl->parseCurrentBlock();
123  }
124  }
125 
132  public function parse()
133  {
134  global $ilUser,$tree;
135 
136  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
137  include_once('./Services/Calendar/classes/class.ilCalendarHidden.php');
138 
139  $hidden_obj = ilCalendarHidden::_getInstanceByUserId($ilUser->getId());
140  $hidden = $hidden_obj->getHidden();
141 
142  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
143  $all = $cats->getCategoriesInfo();
144  $tmp_title_counter = array();
145  $categories = array();
146  foreach($all as $category)
147  {
148  $tmp_arr['obj_id'] = $category['obj_id'];
149  $tmp_arr['id'] = $category['cat_id'];
150  $tmp_arr['hidden'] = (bool) in_array($category['cat_id'],$hidden);
151  $tmp_arr['title'] = $category['title'];
152  $tmp_arr['type'] = $category['type'];
153  $tmp_arr['color'] = $category['color'];
154  $tmp_arr['editable'] = $category['editable'];
155 
156  $categories[] = $tmp_arr;
157 
158  // count title for appending the parent container if there is more than one entry.
159  $tmp_title_counter[$category['type'].'_'.$category['title']]++;
160 
161  }
162 
163  $path_categories = array();
164  foreach($categories as $cat)
165  {
166  if($cat['type'] == ilCalendarCategory::TYPE_OBJ)
167  {
168  if($tmp_title_counter[$cat['type'].'_'.$cat['title']] > 1)
169  {
170  foreach(ilObject::_getAllReferences($cat['obj_id']) as $ref_id)
171  {
172  $cat['path'] = $this->buildPath($ref_id);
173  break;
174  }
175  }
176  }
177  $path_categories[] = $cat;
178  }
179  $this->setData($path_categories ? $path_categories : array());
180  }
181 
182  protected function buildPath($a_ref_id)
183  {
184  global $tree;
185 
186  $path_arr = $tree->getPathFull($a_ref_id,ROOT_FOLDER_ID);
187  $counter = 0;
188  unset($path_arr[count($path_arr) - 1]);
189 
190  foreach($path_arr as $data)
191  {
192  if($counter++)
193  {
194  $path .= " -> ";
195  }
196  $path .= $data['title'];
197  }
198  if(strlen($path) > 30)
199  {
200  return '...'.substr($path,-30);
201  }
202  return $path;
203  }
204 
205 }
206 ?>