ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarMonthGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 {
29  protected int $bkid; // booking user
30  protected int $num_appointments = 1;
31  protected array $schedule_filters = array();
32 
35  protected string $timezone = 'UTC';
36 
37  public function __construct(ilDate $seed_date)
38  {
40  $this->bkid = $this->initBookingUserFromQuery();
41  }
42 
43  public function setBkId(int $bkid = 0): void
44  {
45  $this->bkid = $bkid;
46  }
47 
48  public function initialize(int $a_calendar_presentation_type): void
49  {
50  parent::initialize($a_calendar_presentation_type);
51  $this->tabs_gui->setSubTabActive('app_month');
52  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
53  $this->app_colors = new ilCalendarAppointmentColors($this->user->getId());
54  if ($this->user->getTimeZone()) {
55  $this->timezone = $this->user->getTimeZone();
56  }
57  }
58 
59  public function executeCommand(): void
60  {
61  $this->ctrl->saveParameter($this, 'seed');
62 
63  $next_class = $this->ctrl->getNextClass();
64  switch ($next_class) {
65  case "ilcalendarappointmentpresentationgui":
66  $this->ctrl->setReturn($this, "");
67  $gui = ilCalendarAppointmentPresentationGUI::_getInstance($this->seed, (array) $this->getCurrentApp());
68  $this->ctrl->forwardCommand($gui);
69  break;
70  case 'ilcalendarappointmentgui':
71  $this->ctrl->setReturn($this, '');
72  $this->tabs_gui->setSubTabActive((string) ilSession::get('cal_last_tab'));
73  // initial date for new calendar appointments
74  $idate = new ilDate($this->initInitialDateFromQuery(), IL_CAL_DATE);
75  $app = new ilCalendarAppointmentGUI($this->seed, $idate, $this->initAppointmentIdFromQuery());
76  $this->ctrl->forwardCommand($app);
77  break;
78 
79  default:
80  $time = microtime(true);
81  $cmd = $this->ctrl->getCmd("show");
82  $this->$cmd();
83  $this->main_tpl->setContent($this->tpl->get());
84  break;
85  }
86  }
87 
91  public function addScheduleFilter(ilCalendarScheduleFilter $a_filter): void
92  {
93  $this->schedule_filters[] = $a_filter;
94  }
95 
96  public function show(): void
97  {
98  $this->tpl = new ilTemplate('tpl.month_view.html', true, true, 'Services/Calendar');
99 
101 
102  $navigation = new ilCalendarHeaderNavigationGUI($this, $this->seed, ilDateTime::MONTH);
103  $this->tpl->setVariable('NAVIGATION', $navigation->getHTML());
104 
105  for ($i = $this->user_settings->getWeekStart(); $i < (7 + $this->user_settings->getWeekStart()); $i++) {
106  $this->tpl->setCurrentBlock('month_header_col');
107  $this->tpl->setVariable('TXT_WEEKDAY', ilCalendarUtil::_numericDayToString($i, true));
108  $this->tpl->parseCurrentBlock();
109  }
110 
111  if ($this->bkid) {
112  $user_id = $this->bkid;
113  $disable_empty = true;
114  $no_add = true;
115  } else {
116  if ($this->user->getId() == ANONYMOUS_USER_ID) {
117  $user_id = $this->user->getId();
118  $disable_empty = false;
119  $no_add = true;
120  } else {
121  $user_id = $this->user->getId();
122  $disable_empty = false;
123  $no_add = false;
124  }
125  }
126 
127  $is_portfolio_embedded = false;
129  $no_add = true;
130  $is_portfolio_embedded = true;
131  }
132  $scheduler = new ilCalendarSchedule($this->seed, ilCalendarSchedule::TYPE_MONTH, $user_id);
133  $scheduler->addSubitemCalendars(true);
134  if (sizeof($this->schedule_filters)) {
135  foreach ($this->schedule_filters as $filter) {
136  $scheduler->addFilter($filter);
137  }
138  }
139  $scheduler->calculate();
140 
142 
143  $counter = 0;
145  (int) $this->seed->get(IL_CAL_FKT_DATE, 'm'),
146  (int) $this->seed->get(IL_CAL_FKT_DATE, 'Y'),
147  $this->user_settings->getWeekStart()
148  )->get() as $date) {
149  $counter++;
150  $has_events = (bool) $this->showEvents($scheduler, $date);
151 
152  if (!$this->view_with_appointments && $has_events) {
153  $this->view_with_appointments = true;
154  }
155 
156  if (!$no_add) {
157  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
158  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
159  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
160  $new_app_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'add');
161 
162  if ($settings->getEnableGroupMilestones()) {
163  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
164  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->seed->get(IL_CAL_DATE));
165  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'idate', $date->get(IL_CAL_DATE));
166  $new_ms_url = $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'addMilestone');
167 
168  $this->tpl->setCurrentBlock("new_ms");
169  $this->tpl->setVariable('DD_ID', $date->get(IL_CAL_UNIX));
170  $this->tpl->setVariable(
171  'DD_TRIGGER',
172  $this->ui_renderer->render($this->ui_factory->symbol()->glyph()->add())
173  );
174  $this->tpl->setVariable('URL_DD_NEW_APP', $new_app_url);
175  $this->tpl->setVariable('TXT_DD_NEW_APP', $this->lng->txt('cal_new_app'));
176  $this->tpl->setVariable('URL_DD_NEW_MS', $new_ms_url);
177  $this->tpl->setVariable('TXT_DD_NEW_MS', $this->lng->txt('cal_new_ms'));
178  $this->tpl->parseCurrentBlock();
179  } else {
180  $this->tpl->setCurrentBlock("new_app");
181  $this->tpl->setVariable(
182  'NEW_GLYPH',
183  $this->ui_renderer->render($this->ui_factory->symbol()->glyph()->add($new_app_url))
184  );
185  $this->tpl->parseCurrentBlock();
186  }
187  }
188 
189  $day = (int) $date->get(IL_CAL_FKT_DATE, 'j');
190  $month = (int) $date->get(IL_CAL_FKT_DATE, 'n');
191 
192  if ($day == 1) {
193  $month_day = '1 ' . ilCalendarUtil::_numericMonthToString($month, false);
194  } else {
195  $month_day = $day;
196  }
197 
198  if (!$is_portfolio_embedded &&
199  (!$disable_empty || $has_events)) {
200  $this->tpl->setCurrentBlock('month_day_link');
201  $this->ctrl->clearParametersByClass('ilcalendardaygui');
202  $this->ctrl->setParameterByClass('ilcalendardaygui', 'seed', $date->get(IL_CAL_DATE));
203  $this->tpl->setVariable('OPEN_DAY_VIEW', $this->ctrl->getLinkTargetByClass('ilcalendardaygui', ''));
204  $this->ctrl->clearParametersByClass('ilcalendardaygui');
205  } else {
206  $this->tpl->setCurrentBlock('month_day_no_link');
207  }
208 
209  $this->tpl->setVariable('MONTH_DAY', $month_day);
210 
211  $this->tpl->parseCurrentBlock();
212 
213  $this->tpl->setCurrentBlock('month_col');
214 
215  if (ilCalendarUtil::_isToday($date)) {
216  $this->tpl->setVariable('TD_CLASS', 'caltoday');
217  } elseif (ilDateTime::_equals($date, $this->seed, IL_CAL_MONTH)) {
218  $this->tpl->setVariable('TD_CLASS', 'calstd');
219  } elseif (ilDateTime::_before($date, $this->seed, IL_CAL_MONTH)) {
220  $this->tpl->setVariable('TD_CLASS', 'calprev');
221  } else {
222  $this->tpl->setVariable('TD_CLASS', 'calnext');
223  }
224  $this->tpl->parseCurrentBlock();
225  if ($counter && !($counter % 7)) {
226  $this->tpl->setCurrentBlock('month_row');
227  $this->tpl->parseCurrentBlock();
228  }
229  }
230  }
231 
232  public function getHTML(): string
233  {
234  $this->show();
235  return $this->tpl->get();
236  }
237 
238  protected function showEvents(ilCalendarSchedule $scheduler, ilDate $date): int
239  {
240  $count = 0;
241  $time = '';
242  foreach ($scheduler->getByDay($date, $this->timezone) as $item) {
243  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
244  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $item['event']->getEntryId());
245 
246  $event_tpl = new ilTemplate('tpl.month_event_view.html', true, true, 'Services/Calendar');
247  // milestone icon
248  if ($item['event']->isMilestone()) {
249  $event_tpl->setCurrentBlock('fullday_ms_icon');
250  $event_tpl->setVariable('ALT_FD_MS', $this->lng->txt("cal_milestone"));
251  $event_tpl->setVariable('SRC_FD_MS', ilUtil::getImagePath("icon_ms.svg"));
252  $event_tpl->parseCurrentBlock();
253  }
254 
255  $compl = ($item['event']->isMilestone() && $item['event']->getCompletion() > 0)
256  ? " (" . $item['event']->getCompletion() . "%)"
257  : "";
258 
259  if (!$item['event']->isFullDay()) {
260  switch ($this->user_settings->getTimeFormat()) {
262  $time = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'H:i', $this->timezone);
263  break;
264 
266  $time = $item['event']->getStart()->get(IL_CAL_FKT_DATE, 'h:ia', $this->timezone);
267  break;
268  }
269  }
270 
271  //plugins can change the modal title.
272  $shy = $this->getAppointmentShyButton($item['event'], (string) $item['dstart'], "");
273  $title = ($time != "") ? $time . " " . $shy : $shy;
274  $event_html = $title . $compl;
275  $event_tpl->setCurrentBlock('il_event');
276 
277  //Start configuring the default template
278  $event_tpl->setVariable(
279  'EVENT_EDIT_LINK',
280  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'edit')
281  );
282  $event_tpl->setVariable('EVENT_NUM', $item['event']->getEntryId());
283  $event_tpl->setVariable('EVENT_CONTENT', $event_html);
284  $color = $this->app_colors->getColorByAppointment($item['event']->getEntryId());
285  $event_tpl->setVariable('EVENT_BGCOLOR', $color);
286  $event_tpl->setVariable('EVENT_ADD_STYLES', $item['event']->getPresentationStyle());
287  $event_tpl->setVariable('EVENT_FONTCOLOR', ilCalendarUtil::calculateFontColor($color));
288 
289  //plugins can override the previous template variables. The plugin slot parses the current block because
290  //it needs to call the template get method to use the resulting HTML in the replaceContent method.
291  if ($event_html_by_plugin = $this->getContentByPlugins(
292  $item['event'],
293  $item['dstart'],
294  $event_html,
295  $event_tpl
296  )) {
297  $event_body_html = $event_html_by_plugin;
298  } else {
299  $event_tpl->parseCurrentBlock();
300  $event_body_html = $event_tpl->get();
301  }
302 
303  $this->tpl->setCurrentBlock("event_nfd");
304  $this->tpl->setVariable("EVENT_CONTENT", $event_body_html);
305  $this->tpl->parseCurrentBlock();
306 
307  $this->num_appointments++;
308  $count++;
309  }
310  return $count;
311  }
312 }
static _getInstance(ilDate $seed, array $a_app)
get singleton instance
$app
Definition: cli.php:39
static get(string $a_var)
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
static _buildMonthDayList(int $a_month, int $a_year, int $weekstart)
Build a month day list.
const ANONYMOUS_USER_ID
Definition: constants.php:27
getByDay(ilDate $a_start, string $a_timezone)
static _numericMonthToString(int $a_month, bool $a_long=true)
numeric month to string
showEvents(ilCalendarSchedule $scheduler, ilDate $date)
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
getContentByPlugins(ilCalendarEntry $a_cal_entry, int $a_start_date, string $a_content, ilTemplate $a_tpl)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
const IL_CAL_MONTH
addScheduleFilter(ilCalendarScheduleFilter $a_filter)
Add schedule filter.
const IL_CAL_UNIX
static _getInstanceByUserId(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Calendar schedule filter interface.
__construct(ilDate $seed_date)
initialize(int $a_calendar_presentation_type)
const IL_CAL_FKT_DATE
static initDragDrop(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Drag and Drop used in Modules/Survey, Services/Calendar, Services/COPage, Services/Form (Jan 2022)
static _numericDayToString(int $a_day, bool $a_long=true)
ilCalendarUserSettings $user_settings
static _getInstance($a_usr_id=0)
get singleton instance
const IL_CAL_DATE
ilCalendarAppointmentColors $app_colors
Administrate calendar appointments.
__construct(Container $dic, ilPlugin $plugin)
static calculateFontColor(string $a_html_color_code)
Calculate best font color from html hex color code.
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
getAppointmentShyButton(ilCalendarEntry $a_calendar_entry, string $a_dstart, string $a_title_forced="")
static _isToday(ilDateTime $date)
$i
Definition: metadata.php:41
Represents a list of calendar appointments (including recurring events) for a specific user in a give...