ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
48 
49  $lng = $DIC['lng'];
50  $ilCtrl = $DIC['ilCtrl'];
51 
52 
53  $this->categories = ilCalendarCategories::_getInstance();
54  $this->cat_id = $a_category_id;
55  $this->is_editable = $this->categories->isEditable($this->cat_id);
56 
57  $this->lng = $lng;
58  $this->lng->loadLanguageModule('dateplaner');
59  $this->ctrl = $ilCtrl;
60 
61  $this->setId('calcalapps');
62 
63  parent::__construct($a_parent_obj, $a_parent_cmd);
64  $this->setFormName('appointments');
65  $this->addColumn('', 'f', "1");
66  $this->addColumn($this->lng->txt('cal_start'), 'dt_sort', "30%");
67  $this->addColumn($this->lng->txt('title'), 'title', "60%");
68  $this->addColumn($this->lng->txt('cal_duration'), 'duration', "20%");
69  $this->addColumn($this->lng->txt('cal_recurrences'), 'frequence', "10%");
70 
71  if ($this->is_editable) {
72  $this->addMultiCommand('askDeleteAppointments', $this->lng->txt('delete'));
73  $this->enable('select_all');
74  } else {
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  $this->tpl->setVariable('VAL_ID', $a_set['id']);
102  }
103 
104  $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
105 
106  $this->tpl->setVariable('VAL_TITLE_LINK', $a_set['title']);
107  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_set['id']);
108  $this->tpl->setVariable('VAL_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
109 
110  switch ($a_set['frequence']) {
111  case IL_CAL_FREQ_DAILY:
112  $this->tpl->setVariable('VAL_FREQUENCE', $this->lng->txt('cal_daily'));
113  break;
114 
115  case IL_CAL_FREQ_WEEKLY:
116  $this->tpl->setVariable('VAL_FREQUENCE', $this->lng->txt('cal_weekly'));
117  break;
118 
119  case IL_CAL_FREQ_MONTHLY:
120  $this->tpl->setVariable('VAL_FREQUENCE', $this->lng->txt('cal_monthly'));
121  break;
122 
123  case IL_CAL_FREQ_YEARLY:
124  $this->tpl->setVariable('VAL_FREQUENCE', $this->lng->txt('cal_yearly'));
125  break;
126 
127  default:
128  //$this->tpl->setVariable('VAL_FREQUENCE',$this->lng->txt('cal_no_recurrence'));
129  $this->tpl->setVariable('VAL_FREQUENCE', '');
130  break;
131  }
132  $this->tpl->setVariable('VAL_BEGIN', $a_set['dt']);
133  if ($a_set['duration']) {
134  $this->tpl->setVariable('VAL_DURATION', ilDatePresentation::secondsToString($a_set['duration']));
135  } else {
136  $this->tpl->setVariable('VAL_DURATION', '');
137  }
138  }
139 
144  protected static function getToday()
145  {
146  return $this->today;
147  }
148 
155  public function setAppointments($a_apps)
156  {
157  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
158  include_once('./Services/Calendar/classes/class.ilCalendarRecurrences.php');
159  include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
160 
161  $cat = new ilCalendarCategory($this->cat_id);
162 
163  foreach ($a_apps as $cal_entry_id) {
164  $entry = new ilCalendarEntry($cal_entry_id);
165  $rec = ilCalendarRecurrences::_getFirstRecurrence($entry->getEntryId());
166 
167  // booking
168  if ($cat->getType() == ilCalendarCategory::TYPE_CH) {
169  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
170  $book = new ilBookingEntry($entry->getContextId());
171  if ($book) {
172  $title = $entry->getTitle();
173  if ($book->isOwner()) {
174  $max = (int) $book->getNumberOfBookings();
175  $current = (int) $book->getCurrentNumberOfBookings($entry->getEntryId());
176  if ($max > 1) {
177  $title .= ' (' . $current . '/' . $max . ')';
178  } elseif ($current == $max) {
179  $title .= ' (' . $this->lng->txt('cal_booked_out') . ')';
180  } else {
181  $title .= ' (' . $this->lng->txt('cal_book_free') . ')';
182  }
183  } elseif ($book->hasBooked($entry->getEntryId())) {
184  $title .= ' (' . $this->lng->txt('cal_date_booked') . ')';
185  }
186  }
187  } else {
188  $title = $entry->getPresentationTitle();
189  }
190 
191  $tmp_arr['id'] = $entry->getEntryId();
192  $tmp_arr['title'] = $title;
193  $tmp_arr['description'] = $entry->getDescription();
194  $tmp_arr['fullday'] = $entry->isFullday();
195  $tmp_arr['begin'] = $entry->getStart()->get(IL_CAL_UNIX);
196  $tmp_arr['end'] = $entry->getEnd()->get(IL_CAL_UNIX);
197 
198  $tmp_arr['dt_sort'] = $entry->getStart()->get(IL_CAL_UNIX);
199  $tmp_arr['dt'] = ilDatePresentation::formatPeriod(
200  $entry->getStart(),
201  $entry->getEnd()
202  );
203 
204  #$tmp_arr['duration'] = ($dur = $tmp_arr['end'] - $tmp_arr['begin']) ? $dur : 60 * 60 * 24;
205  $tmp_arr['duration'] = $tmp_arr['end'] - $tmp_arr['begin'];
206  if ($tmp_arr['fullday']) {
207  $tmp_arr['duration'] += (60 * 60 * 24);
208  }
209 
210  if (!$tmp_arr['fullday'] and $tmp_arr['end'] == $tmp_arr['begin']) {
211  $tmp_arr['duration'] = '';
212  }
213  $tmp_arr['frequence'] = $rec->getFrequenceType();
214  $tmp_arr['deletable'] = (!$entry->isAutoGenerated() and $this->is_editable);
215 
216  $appointments[] = $tmp_arr;
217  }
218  $this->setData($appointments ? $appointments : array());
219  }
220 }
const IL_CAL_FREQ_MONTHLY
Model for a calendar entry.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
global $DIC
Definition: saml.php:7
static _getFirstRecurrence($a_cal_id)
get first recurrence
Booking definition.
Stores calendar categories.
const IL_CAL_UNIX
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
Class ilTable2GUI.
static secondsToString($seconds, $force_with_seconds=false, $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
const IL_CAL_FREQ_DAILY
Model of calendar entry recurrcences.
const IL_CAL_FREQ_YEARLY
addMultiCommand($a_cmd, $a_text)
Add Command button.
enable($a_module_name)
enables particular modules of table
static _getInstance($a_usr_id=0)
get singleton instance
setRowTemplate($a_template, $a_template_dir="")
Set row template.
__construct($a_parent_obj, $a_parent_cmd, $a_category_id)
Constructor.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
setFormName($a_formname="")
Set Form name.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
const IL_CAL_FREQ_WEEKLY