ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarManageTableGUI.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->setId("calmng");
49 
50  $this->lng = $lng;
51  $this->lng->loadLanguageModule('dateplaner');
52  $this->ctrl = $ilCtrl;
53 
54  parent::__construct($a_parent_obj, 'manage');
55  $this->setFormName('categories');
56  $this->addColumn('','','5%', true);
57  $this->addColumn($this->lng->txt('type'), '', '10%');
58  $this->addColumn($this->lng->txt('title'),'title', '50%');
59  $this->addColumn('','','35%');
60 
61  $this->setPrefix('categories');
62  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, "manage"));
63  $this->setRowTemplate("tpl.manage_row.html","Services/Calendar");
64  $this->enable('select_all');
65  $this->setSelectAllCheckbox('selected_cat_ids');
66  // $this->setDisplayAsBlock(true);
67 
68 
69  /*
70  $title = $this->lng->txt('cal_table_categories');
71  $title .= $this->appendCalendarSelection();
72  $table_gui->setTitle($title);
73  */
74 
75  $this->addMultiCommand('confirmDelete',$this->lng->txt('delete'));
76  // $this->addCommandButton('add',$this->lng->txt('add'));
77 
78  $this->setDefaultOrderDirection('asc');
79  $this->setDefaultOrderField('title');
80  }
81 
89  protected function fillRow($a_set)
90  {
91  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
92  $current_selection_list = new ilAdvancedSelectionListGUI();
93  $current_selection_list->setListTitle($this->lng->txt("actions"));
94  $current_selection_list->setId("act_".$a_set['id']);
95 
96  $this->ctrl->setParameter($this->getParentObject(),'category_id',$a_set['id']);
97 
98  // repository calendars cannot be edited
99  if($a_set['editable'] && !in_array($a_set['type'], array(ilCalendarCategory::TYPE_OBJ, ilCalendarCategory::TYPE_CH, ilCalendarCategory::TYPE_BOOK)))
100  {
101  $url = $this->ctrl->getLinkTarget($this->getParentObject(), 'edit');
102  $current_selection_list->addItem($this->lng->txt('edit'), '', $url);
103 
104  $this->tpl->setCurrentBlock("checkbox");
105  $this->tpl->setVariable('VAL_ID',$a_set['id']);
106  $this->tpl->parseCurrentBlock();
107  }
108 
109  if($a_set['accepted'])
110  {
111  $url = $this->ctrl->getLinkTarget($this->getParentObject(), 'unshare');
112  $current_selection_list->addItem($this->lng->txt('cal_unshare'), '', $url);
113  }
114  else if($a_set['type'] == ilCalendarCategory::TYPE_USR)
115  {
116  $url = $this->ctrl->getLinkTarget($this->getParentObject(), 'shareSearch');
117  $current_selection_list->addItem($this->lng->txt('cal_share'), '', $url);
118  }
119 
120  $this->ctrl->setParameter($this->getParentObject(),'category_id','');
121 
122  switch($a_set['type'])
123  {
125  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_calg_s.gif'));
126  $this->tpl->setVariable('IMG_ALT', $this->lng->txt('cal_type_system'));
127  break;
128 
130  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_usr_s.gif'));
131  $this->tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_personal'));
132  break;
133 
135  $type = ilObject::_lookupType($a_set['obj_id']);
136  $this->tpl->setVariable('IMG_SRC',ilUtil::getImagePath('icon_'.$type.'_s.gif'));
137  $this->tpl->setVariable('IMG_ALT',$this->lng->txt('cal_type_'.$type));
138  break;
139  }
140 
141  $this->tpl->setVariable('VAL_TITLE',$a_set['title']);
142  $this->tpl->setVariable('BGCOLOR',$a_set['color']);
143  $this->tpl->setVariable("ACTIONS", $current_selection_list->getHTML());
144 
145  if(strlen($a_set['path']))
146  {
147  $this->tpl->setCurrentBlock('calendar_path');
148  $this->tpl->setVariable('ADD_PATH_INFO',$a_set['path']);
149  $this->tpl->parseCurrentBlock();
150  }
151  }
152 
159  public function parse()
160  {
161  global $ilUser, $tree;
162 
163  include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
164  $cats = ilCalendarCategories::_getInstance($ilUser->getId());
165  $cats->initialize(ilCalendarCategories::MODE_MANAGE);
166 
167  $tmp_title_counter = array();
168  $categories = array();
169  foreach($cats->getCategoriesInfo() as $category)
170  {
171  $tmp_arr['obj_id'] = $category['obj_id'];
172  $tmp_arr['id'] = $category['cat_id'];
173  $tmp_arr['title'] = $category['title'];
174  $tmp_arr['type'] = $category['type'];
175  $tmp_arr['color'] = $category['color'];
176  $tmp_arr['editable'] = $category['editable'];
177  $tmp_arr['accepted'] = $category['accepted'];
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  {
188  if($cat['type'] == ilCalendarCategory::TYPE_OBJ)
189  {
190  if($tmp_title_counter[$cat['type'].'_'.$cat['title']] > 1)
191  {
192  foreach(ilObject::_getAllReferences($cat['obj_id']) as $ref_id)
193  {
194  $cat['path'] = $this->buildPath($ref_id);
195  break;
196  }
197  }
198  }
199  $path_categories[] = $cat;
200  }
201  $this->setData($path_categories ? $path_categories : array());
202  }
203 
204  protected function buildPath($a_ref_id)
205  {
206  global $tree;
207 
208  $path_arr = $tree->getPathFull($a_ref_id,ROOT_FOLDER_ID);
209  $counter = 0;
210  unset($path_arr[count($path_arr) - 1]);
211 
212  foreach($path_arr as $data)
213  {
214  if($counter++)
215  {
216  $path .= " -> ";
217  }
218  $path .= $data['title'];
219  }
220  if(strlen($path) > 30)
221  {
222  return '...'.substr($path,-30);
223  }
224  return $path;
225  }
226 
227 }
228 ?>