ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarAppointmentsTableGUI.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/Calendar/classes/class.ilCalendarCategories.php');
33 {
34  private $cat_id = 0;
35  private $categories = null;
36  private $is_editable = false;
37 
45  public function __construct($a_parent_obj,$a_parent_cmd,$a_category_id)
46  {
47  global $lng,$ilCtrl;
48 
49 
50  $this->categories = ilCalendarCategories::_getInstance();
51  $this->cat_id = $a_category_id;
52  $this->is_editable = $this->categories->isEditable($this->cat_id);
53 
54  $this->lng = $lng;
55  $this->lng->loadLanguageModule('dateplaner');
56  $this->ctrl = $ilCtrl;
57 
58  $this->setId('calcalapps');
59 
60  parent::__construct($a_parent_obj,$a_parent_cmd);
61  $this->setFormName('appointments');
62  $this->addColumn('','f',"1");
63  $this->addColumn($this->lng->txt('cal_start'),'dt_sort',"30%");
64  $this->addColumn($this->lng->txt('title'),'title',"60%");
65  $this->addColumn($this->lng->txt('cal_duration'),'duration',"20%");
66  $this->addColumn($this->lng->txt('cal_recurrences'),'frequence',"10%");
67 
68  if($this->is_editable)
69  {
70  $this->addMultiCommand('askDeleteAppointments',$this->lng->txt('delete'));
71  $this->enable('select_all');
72  }
73  else
74  {
75  $this->disable('select_all');
76  }
77 
78  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
79  $this->setRowTemplate("tpl.show_appointment_row.html","Services/Calendar");
80 
81  $this->setShowRowsSelector(true);
82  $this->enable('sort');
83  $this->enable('header');
84  $this->enable('numinfo');
85 
86  $this->setDefaultOrderField('dt_sort');
87  $this->setSelectAllCheckbox('appointments');
88  }
89 
90 
98  protected function fillRow($a_set)
99  {
100  if($a_set['deletable'])
101  {
102  $this->tpl->setVariable('VAL_ID',$a_set['id']);
103  }
104 
105  $this->tpl->setVariable('VAL_DESCRIPTION',$a_set['description']);
106 
107  $this->tpl->setVariable('VAL_TITLE_LINK',$a_set['title']);
108  $this->ctrl->setParameterByClass('ilcalendarappointmentgui','app_id',$a_set['id']);
109  $this->tpl->setVariable('VAL_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','edit'));
110 
111  switch($a_set['frequence'])
112  {
113  case IL_CAL_FREQ_DAILY:
114  $this->tpl->setVariable('VAL_FREQUENCE',$this->lng->txt('cal_daily'));
115  break;
116 
117  case IL_CAL_FREQ_WEEKLY:
118  $this->tpl->setVariable('VAL_FREQUENCE',$this->lng->txt('cal_weekly'));
119  break;
120 
121  case IL_CAL_FREQ_MONTHLY:
122  $this->tpl->setVariable('VAL_FREQUENCE',$this->lng->txt('cal_monthly'));
123  break;
124 
125  case IL_CAL_FREQ_YEARLY:
126  $this->tpl->setVariable('VAL_FREQUENCE',$this->lng->txt('cal_yearly'));
127  break;
128 
129  default:
130  //$this->tpl->setVariable('VAL_FREQUENCE',$this->lng->txt('cal_no_recurrence'));
131  $this->tpl->setVariable('VAL_FREQUENCE','');
132  break;
133  }
134  $this->tpl->setVariable('VAL_BEGIN',$a_set['dt']);
135  if($a_set['duration'])
136  {
137  $this->tpl->setVariable('VAL_DURATION',ilFormat::_secondsToString($a_set['duration']));
138  }
139  else
140  {
141  $this->tpl->setVariable('VAL_DURATION','');
142  }
143  }
144 
149  protected static function getToday()
150  {
151  return $this->today;
152  }
153 
160  public function setAppointments($a_apps)
161  {
162  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
163  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
164  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
165 
166  $cat = new ilCalendarCategory($this->cat_id);
167 
168  foreach($a_apps as $cal_entry_id)
169  {
170  $entry = new ilCalendarEntry($cal_entry_id);
171  $rec = ilCalendarRecurrences::_getFirstRecurrence($entry->getEntryId());
172 
173  // booking
174  if($cat->getType() == ilCalendarCategory::TYPE_CH)
175  {
176  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
177  $book = new ilBookingEntry($entry->getContextId());
178  if($book)
179  {
180  $title = $entry->getTitle();
181  if($book->isOwner())
182  {
183  $max = (int)$book->getNumberOfBookings();
184  $current = (int)$book->getCurrentNumberOfBookings($entry->getEntryId());
185  if($max > 1)
186  {
187  $title .= ' ('.$current.'/'.$max.')';
188  }
189  else if($current == $max)
190  {
191  $title .= ' ('.$this->lng->txt('cal_booked_out').')';
192  }
193  else
194  {
195  $title .= ' ('.$this->lng->txt('cal_book_free').')';
196  }
197  }
198  else if($book->hasBooked($entry->getEntryId()))
199  {
200  $title .= ' ('.$this->lng->txt('cal_date_booked').')';
201  }
202  }
203  }
204  else
205  {
206  $title = $entry->getPresentationTitle();
207  }
208 
209  $tmp_arr['id'] = $entry->getEntryId();
210  $tmp_arr['title'] = $title;
211  $tmp_arr['description'] = $entry->getDescription();
212  $tmp_arr['fullday'] = $entry->isFullday();
213  $tmp_arr['begin'] = $entry->getStart()->get(IL_CAL_UNIX);
214  $tmp_arr['end'] = $entry->getEnd()->get(IL_CAL_UNIX);
215 
216  $tmp_arr['dt_sort'] = $entry->getStart()->get(IL_CAL_UNIX);
217  $tmp_arr['dt'] = ilDatePresentation::formatPeriod(
218  $entry->getStart(),
219  $entry->getEnd()
220  );
221 
222  #$tmp_arr['duration'] = ($dur = $tmp_arr['end'] - $tmp_arr['begin']) ? $dur : 60 * 60 * 24;
223  $tmp_arr['duration'] = $tmp_arr['end'] - $tmp_arr['begin'];
224  if($tmp_arr['fullday'])
225  {
226  $tmp_arr['duration'] += (60 * 60 * 24);
227  }
228 
229  if(!$tmp_arr['fullday'] and $tmp_arr['end'] == $tmp_arr['begin'])
230  {
231  $tmp_arr['duration'] = '';
232  }
233  $tmp_arr['frequence'] = $rec->getFrequenceType();
234  $tmp_arr['deletable'] = (!$entry->isAutoGenerated() and $this->is_editable);
235 
236  $appointments[] = $tmp_arr;
237  }
238  $this->setData($appointments ? $appointments : array());
239  }
240 
241 }
242 ?>