ILIAS  release_8 Revision v8.23
class.ilCalendarAppointmentsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /*
5  +-----------------------------------------------------------------------------+
6  | ILIAS open source |
7  +-----------------------------------------------------------------------------+
8  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9  | |
10  | This program is free software; you can redistribute it and/or |
11  | modify it under the terms of the GNU General Public License |
12  | as published by the Free Software Foundation; either version 2 |
13  | of the License, or (at your option) any later version. |
14  | |
15  | This program is distributed in the hope that it will be useful, |
16  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18  | GNU General Public License for more details. |
19  | |
20  | You should have received a copy of the GNU General Public License |
21  | along with this program; if not, write to the Free Software |
22  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23  +-----------------------------------------------------------------------------+
24 */
25 
31 {
32  private int $cat_id = 0;
34  private bool $is_editable = false;
35 
36  public function __construct(object $a_parent_obj, string $a_parent_cmd, int $a_category_id)
37  {
38  global $DIC;
39 
40  $this->categories = ilCalendarCategories::_getInstance();
41  $this->cat_id = $a_category_id;
42  $this->is_editable = $this->categories->isEditable($this->cat_id);
43 
44  $this->setId('calcalapps');
45  parent::__construct($a_parent_obj, $a_parent_cmd);
46 
47  $this->lng->loadLanguageModule('dateplaner');
48 
49  $this->setFormName('appointments');
50  $this->addColumn('', 'f', "1");
51  $this->addColumn($this->lng->txt('cal_start'), 'dt_sort', "30%");
52  $this->addColumn($this->lng->txt('title'), 'title', "60%");
53  $this->addColumn($this->lng->txt('cal_duration'), 'duration', "20%");
54  $this->addColumn($this->lng->txt('cal_recurrences'), 'frequence', "10%");
55 
56  if ($this->is_editable) {
57  $this->addMultiCommand('askDeleteAppointments', $this->lng->txt('delete'));
58  $this->enable('select_all');
59  } else {
60  $this->disable('select_all');
61  }
62 
63  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
64  $this->setRowTemplate("tpl.show_appointment_row.html", "Services/Calendar");
65 
66  $this->setShowRowsSelector(true);
67  $this->enable('sort');
68  $this->enable('header');
69  $this->enable('numinfo');
70 
71  $this->setDefaultOrderField('dt_sort');
72  $this->setSelectAllCheckbox('appointments');
73  }
74 
75  protected function fillRow(array $a_set): void
76  {
77  if ($a_set['deletable']) {
78  $this->tpl->setVariable('VAL_ID', $a_set['id']);
79  }
80 
81  $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
82 
83  $this->tpl->setVariable('VAL_TITLE_LINK', $a_set['title']);
84  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_set['id']);
85  $this->tpl->setVariable('VAL_LINK', $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit'));
86 
87  switch ($a_set['frequence']) {
89  $this->tpl->setVariable('VAL_FREQUENCE', $this->lng->txt('cal_daily'));
90  break;
91 
93  $this->tpl->setVariable('VAL_FREQUENCE', $this->lng->txt('cal_weekly'));
94  break;
95 
97  $this->tpl->setVariable('VAL_FREQUENCE', $this->lng->txt('cal_monthly'));
98  break;
99 
101  $this->tpl->setVariable('VAL_FREQUENCE', $this->lng->txt('cal_yearly'));
102  break;
103 
104  default:
105  //$this->tpl->setVariable('VAL_FREQUENCE',$this->lng->txt('cal_no_recurrence'));
106  $this->tpl->setVariable('VAL_FREQUENCE', '');
107  break;
108  }
109  $this->tpl->setVariable('VAL_BEGIN', $a_set['dt']);
110  if ($a_set['duration']) {
111  $this->tpl->setVariable('VAL_DURATION', ilDatePresentation::secondsToString($a_set['duration']));
112  } else {
113  $this->tpl->setVariable('VAL_DURATION', '');
114  }
115  }
116 
121  public function setAppointments(array $a_apps): void
122  {
123  $cat = new ilCalendarCategory($this->cat_id);
124 
125  $appointments = [];
126  foreach ($a_apps as $cal_entry_id) {
127  $entry = new ilCalendarEntry($cal_entry_id);
128  $rec = ilCalendarRecurrences::_getFirstRecurrence($entry->getEntryId());
129 
130  // booking
131  $title = '';
132  if ($cat->getType() == ilCalendarCategory::TYPE_CH) {
133  $book = new ilBookingEntry($entry->getContextId());
134  if ($book) {
135  $title = $entry->getTitle();
136  if ($book->isOwner()) {
137  $max = $book->getNumberOfBookings();
138  $current = $book->getCurrentNumberOfBookings($entry->getEntryId());
139  if ($max > 1) {
140  $title .= ' (' . $current . '/' . $max . ')';
141  } elseif ($current == $max) {
142  $title .= ' (' . $this->lng->txt('cal_booked_out') . ')';
143  } else {
144  $title .= ' (' . $this->lng->txt('cal_book_free') . ')';
145  }
146  } elseif ($book->hasBooked($entry->getEntryId())) {
147  $title .= ' (' . $this->lng->txt('cal_date_booked') . ')';
148  }
149  }
150  } else {
151  $title = $entry->getPresentationTitle();
152  }
153 
154  $tmp_arr['id'] = $entry->getEntryId();
155  $tmp_arr['title'] = $title;
156  $tmp_arr['description'] = $entry->getDescription();
157  $tmp_arr['fullday'] = $entry->isFullday();
158  $tmp_arr['begin'] = $entry->getStart()->get(IL_CAL_UNIX);
159  $tmp_arr['end'] = $entry->getEnd()->get(IL_CAL_UNIX);
160 
161  $tmp_arr['dt_sort'] = $entry->getStart()->get(IL_CAL_UNIX);
162  $tmp_arr['dt'] = ilDatePresentation::formatPeriod(
163  $entry->getStart(),
164  $entry->getEnd()
165  );
166 
167  $tmp_arr['duration'] = $tmp_arr['end'] - $tmp_arr['begin'];
168  if ($tmp_arr['fullday']) {
169  $tmp_arr['duration'] += (60 * 60 * 24);
170  }
171 
172  if (!$tmp_arr['fullday'] and $tmp_arr['end'] == $tmp_arr['begin']) {
173  $tmp_arr['duration'] = '';
174  }
175  $tmp_arr['frequence'] = $rec->getFrequenceType();
176  $tmp_arr['deletable'] = (!$entry->isAutoGenerated() and $this->is_editable);
177 
178  $appointments[] = $tmp_arr;
179  }
180  $this->setData($appointments);
181  }
182 }
class for calendar categories
setData(array $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
enable(string $a_module_name)
setFormAction(string $a_form_action, bool $a_multipart=false)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Stores calendar categories.
const IL_CAL_UNIX
setFormName(string $a_name="")
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
setId(string $a_val)
global $DIC
Definition: feed.php:28
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_category_id)
static _getInstance($a_usr_id=0)
get singleton instance
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
__construct(Container $dic, ilPlugin $plugin)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
disable(string $a_module_name)
addMultiCommand(string $a_cmd, string $a_text)