ILIAS  release_8 Revision v8.24
class.ilCalendarEntry.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
28{
29 public const TRANSLATION_NONE = 0;
30 public const TRANSLATION_SYSTEM = 1;
31
32 protected ilLogger $log;
33 protected ilDBInterface $db;
34 protected ilLanguage $lng;
36
37 protected int $entry_id = 0;
38 protected ?ilDateTime $last_update = null;
39 protected string $title = '';
40 protected string $presentation_style = '';
41 protected string $subtitle = '';
42 protected string $description = '';
43 protected string $location = '';
44 protected string $further_informations = '';
45 protected ?ilDateTime $start = null;
46 protected bool $fullday = false;
47 protected ?ilDateTime $end = null;
48 protected bool $is_auto_generated = false;
49 protected int $context_id = 0;
50 protected string $context_info = '';
52 protected bool $is_milestone = false;
53 protected int $completion = 0;
54 protected bool $notification = false;
55 protected array $responsible_users = [];
56
57 public function __construct(int $a_id = 0)
58 {
59 global $DIC;
60
61 $this->log = $DIC->logger()->cal();
62 $this->lng = $DIC->language();
63 $this->db = $DIC->database();
64 $this->error = $DIC['ilErr'];
65 $this->entry_id = $a_id;
66 if ($this->entry_id > 0) {
67 $this->read();
68 }
69 }
70
74 public function __clone()
75 {
76 $this->entry_id = 0;
77 }
78
79 public static function _delete(int $a_entry_id): void
80 {
81 global $DIC;
82
83 $ilDB = $DIC['ilDB'];
85
86 $query = "DELETE FROM cal_entries " .
87 "WHERE cal_id = " . $ilDB->quote($a_entry_id, 'integer') . " ";
88 $res = $ilDB->manipulate($query);
89 }
90
91 public function setContextInfo(string $a_info): void
92 {
93 $this->context_info = $a_info;
94 }
95
96 public function getContextInfo(): string
97 {
99 }
100
101 public function getEntryId(): int
102 {
103 return $this->entry_id;
104 }
105
106 public function getLastUpdate(): ilDateTime
107 {
108 return $this->last_update ?: new ilDateTime(time(), IL_CAL_UNIX);
109 }
110
111 public function setLastUpdate(ilDateTime $a_date): void
112 {
113 $this->last_update = $a_date;
114 }
115
116 public function getStart(): ?ilDateTime
117 {
118 return $this->start;
119 }
120
121 public function setStart(?ilDateTime $a_start): void
122 {
123 $this->start = $a_start;
124 }
125
126 public function getEnd(): ?ilDateTime
127 {
128 return $this->end;
129 }
130
131 public function setEnd(?ilDateTime $a_end): void
132 {
133 $this->end = $a_end;
134 }
135
136 public function setTitle(string $a_title): void
137 {
138 $this->title = $a_title;
139 }
140
141 public function getTitle(): string
142 {
143 return $this->title;
144 }
145
146 public function getPresentationTitle(bool $a_shorten = true): string
147 {
149 $title = $this->getTitle();
150 } elseif (strlen($this->getSubtitle())) {
151 // parse dynamic title?
152 if (preg_match("/#([a-z]+)#/", $this->getSubtitle(), $matches)) {
153 $subtitle = $this->parseDynamicTitle($matches[1]);
154 } else {
155 $subtitle = $this->lng->txt($this->getSubtitle());
156 }
157 $title = $this->getTitle() .
158 (strlen($subtitle)
159 ? ' (' . $subtitle . ')'
160 : '');
161 } else {
162 $title = $this->lng->txt($this->getTitle());
163 }
164
165 if ($a_shorten) {
167 }
168 return $title;
169 }
170
171 protected function parseDynamicTitle(string $a_type): string
172 {
173 $title = $style = "";
174 switch ($a_type) {
175 case "consultationhour":
176 $entry = new ilBookingEntry($this->getContextId());
177 if ($entry) {
178 if ($entry->isOwner()) {
179 $max = $entry->getNumberOfBookings();
180 $current = $entry->getCurrentNumberOfBookings($this->getEntryId());
181 if (!$current) {
182 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: green';
183 $title = $this->lng->txt('cal_book_free');
184 } elseif ($current >= $max) {
185 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: red';
186 $title = $this->lng->txt('cal_booked_out');
187 } else {
188 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: yellow';
189 $title = $current . '/' . $max;
190 }
191 } else {
193 $entry->getObjId(),
194 $this->getContextId(),
195 $this->getStart()
196 );
197 if ($apps === []) {
198 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: red';
199 $title = $this->lng->txt('cal_booked_out');
200 } else {
201 $orig_event = $apps[0];
202 $max = $entry->getNumberOfBookings();
203 $current = $entry->getCurrentNumberOfBookings($this->getEntryId());
204 if ($entry->hasBooked($orig_event)) {
205 $title = $this->lng->txt('cal_date_booked');
206 } elseif ($current >= $max) {
207 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: red';
208 $title = $this->lng->txt('cal_booked_out');
209 } else {
210 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: green';
211 $title = $this->lng->txt('cal_book_free');
212 }
213 }
214 }
215 }
216 break;
217 }
218 if (strlen($style)) {
219 $this->presentation_style = $style;
220 }
221
222 return $title;
223 }
224
225 public function getPresentationStyle(): string
226 {
228 }
229
235 public function setSubtitle(string $a_subtitle): void
236 {
237 $this->subtitle = $a_subtitle;
238 }
239
240 public function getSubtitle(): string
241 {
242 return $this->subtitle;
243 }
244
245 public function setDescription(string $a_description): void
246 {
247 $this->description = $a_description;
248 }
249
250 public function getDescription(): string
251 {
252 return $this->description;
253 }
254
255 public function setLocation(string $a_location): void
256 {
257 $this->location = $a_location;
258 }
259
260 public function getLocation(): string
261 {
262 return $this->location;
263 }
264
265 public function setFurtherInformations(string $a_informations): void
266 {
267 $this->further_informations = $a_informations;
268 }
269
270 public function getFurtherInformations(): string
271 {
273 }
274
280 public function setFullday(bool $a_fullday): void
281 {
282 $this->fullday = $a_fullday;
283 }
284
285 public function isFullday(): bool
286 {
287 return $this->fullday;
288 }
289
290 public function isAutoGenerated(): bool
291 {
293 }
294
295 public function setAutoGenerated(bool $a_status): void
296 {
297 $this->is_auto_generated = $a_status;
298 }
299
300 public function isMilestone(): bool
301 {
302 return $this->is_milestone;
303 }
304
305 public function setMilestone(bool $a_status): void
306 {
307 $this->is_milestone = $a_status;
308 }
309
310 public function setCompletion(int $a_completion): void
311 {
312 $this->completion = $a_completion;
313 }
314
315 public function getCompletion(): int
316 {
317 return $this->completion;
318 }
319
320 public function setContextId(int $a_context_id): void
321 {
322 $this->context_id = $a_context_id;
323 }
324
325 public function getContextId(): int
326 {
327 return $this->context_id;
328 }
329
330 public function setTranslationType(int $a_type): void
331 {
332 $this->translation_type = $a_type;
333 }
334
335 public function getTranslationType(): int
336 {
338 }
339
340 public function enableNotification(bool $a_status): void
341 {
342 $this->notification = $a_status;
343 }
344
345 public function isNotificationEnabled(): bool
346 {
347 return $this->notification;
348 }
349
350 public function update(): void
351 {
352 $now = new ilDateTime(time(), IL_CAL_UNIX);
353 $utc_timestamp = $now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
354 $query = "UPDATE cal_entries " .
355 "SET title = " . $this->db->quote($this->getTitle(), 'text') . ", " .
356 "last_update = " . $this->db->quote($utc_timestamp, 'timestamp') . ", " .
357 "subtitle = " . $this->db->quote($this->getSubtitle(), 'text') . ", " .
358 "description = " . $this->db->quote($this->getDescription(), 'text') . ", " .
359 "location = " . $this->db->quote($this->getLocation(), 'text') . ", " .
360 "fullday = " . $this->db->quote($this->isFullday() ? 1 : 0, 'integer') . ", " .
361 "starta = " . $this->db->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
362 "enda = " . $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
363 "informations = " . $this->db->quote($this->getFurtherInformations(), 'text') . ", " .
364 "auto_generated = " . $this->db->quote($this->isAutoGenerated(), 'integer') . ", " .
365 "translation_type = " . $this->db->quote($this->getTranslationType(), 'integer') . ", " .
366 "context_id = " . $this->db->quote($this->getContextId(), 'integer') . ", " .
367 'context_info = ' . $this->db->quote($this->getContextInfo(), 'text') . ', ' .
368 "completion = " . $this->db->quote($this->getCompletion(), 'integer') . ", " .
369 "is_milestone = " . $this->db->quote($this->isMilestone() ? 1 : 0, 'integer') . ", " .
370 'notification = ' . $this->db->quote($this->isNotificationEnabled() ? 1 : 0, 'integer') . ' ' .
371 "WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
372 $res = $this->db->manipulate($query);
373 }
374
375 public function save(): void
376 {
377 $next_id = $this->db->nextId('cal_entries');
378 $now = new ilDateTime(time(), IL_CAL_UNIX);
379 $utc_timestamp = $now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
380
381 $query = "INSERT INTO cal_entries (cal_id,title,last_update,subtitle,description,location,fullday,starta,enda, " .
382 "informations,auto_generated,context_id,context_info,translation_type, completion, is_milestone, notification) " .
383 "VALUES( " .
384 $this->db->quote($next_id, 'integer') . ", " .
385 $this->db->quote($this->getTitle(), 'text') . ", " .
386 $this->db->quote($utc_timestamp, 'timestamp') . ", " .
387 $this->db->quote($this->getSubtitle(), 'text') . ", " .
388 $this->db->quote($this->getDescription(), 'text') . ", " .
389 $this->db->quote($this->getLocation(), 'text') . ", " .
390 $this->db->quote($this->isFullday() ? 1 : 0, 'integer') . ", " .
391 $this->db->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
392 $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
393 $this->db->quote($this->getFurtherInformations(), 'text') . ", " .
394 $this->db->quote($this->isAutoGenerated(), 'integer') . ", " .
395 $this->db->quote($this->getContextId(), 'integer') . ", " .
396 $this->db->quote($this->getContextInfo(), 'text') . ', ' .
397 $this->db->quote($this->getTranslationType(), 'integer') . ", " .
398 $this->db->quote($this->getCompletion(), 'integer') . ", " .
399 $this->db->quote($this->isMilestone() ? 1 : 0, 'integer') . ", " .
400 $this->db->quote($this->isNotificationEnabled() ? 1 : 0, 'integer') . ' ' .
401 ")";
402 $res = $this->db->manipulate($query);
403
404 $this->entry_id = $next_id;
405 }
406
407 public function delete(): void
408 {
410
411 $query = "DELETE FROM cal_entries " .
412 "WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
413 $res = $this->db->manipulate($query);
414
416 }
417
418 public function validate(): bool
419 {
420 $success = true;
421 $this->error->setMessage('');
422 if (!strlen($this->getTitle())) {
423 $success = false;
424 $this->error->appendMessage($this->lng->txt('err_missing_title'));
425 }
426 if (!$this->getStart() || !$this->getEnd()) {
427 $success = false;
428 } elseif (ilDateTime::_before($this->getEnd(), $this->getStart(), '')) {
429 $success = false;
430 $this->error->appendMessage($this->lng->txt('err_end_before_start'));
431 }
432 return $success;
433 }
434
435 protected function read(): void
436 {
437 $query = "SELECT * FROM cal_entries WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
438 $res = $this->db->query($query);
439 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
440 $this->setLastUpdate(new ilDateTime((string) $row->last_update, IL_CAL_DATETIME, 'UTC'));
441 $this->setTitle((string) $row->title);
442 $this->setSubtitle((string) $row->subtitle);
443 $this->setDescription((string) $row->description);
444 $this->setLocation((string) $row->location);
445 $this->setFurtherInformations((string) $row->informations);
446 $this->setFullday((bool) $row->fullday);
447 $this->setAutoGenerated((bool) $row->auto_generated);
448 $this->setContextId((int) $row->context_id);
449 $this->setContextInfo((string) $row->context_info);
450 $this->setTranslationType((int) $row->translation_type);
451 $this->setCompletion((int) $row->completion);
452 $this->setMilestone((bool) $row->is_milestone);
453 $this->enableNotification((bool) $row->notification);
454
455 if ($this->isFullday()) {
456 $this->start = new ilDate((string) $row->starta, IL_CAL_DATETIME);
457 $this->end = new ilDate((string) $row->enda, IL_CAL_DATETIME);
458 } else {
459 $this->start = new ilDateTime((string) $row->starta, IL_CAL_DATETIME, 'UTC');
460 $this->end = new ilDateTime((string) $row->enda, IL_CAL_DATETIME, 'UTC');
461 }
462 }
463 }
464
465 public function appointmentToMailString(ilLanguage $lng): string
466 {
467 $body = $lng->txt('cal_details');
468 $body .= "\n\n";
469 $body .= $lng->txt('title') . ': ' . $this->getTitle() . "\n";
470
472 $body .= $lng->txt('date') . ': ' . ilDatePresentation::formatPeriod($this->getStart(), $this->getEnd()) . "\n";
474
475 if (strlen($this->getLocation())) {
476 $body .= $lng->txt('cal_where') . ': ' . $this->getLocation() . "\n";
477 }
478
479 if (strlen($this->getDescription())) {
480 $body .= $lng->txt('description') . ': ' . $this->getDescription() . "\n";
481 }
482 return $body;
483 }
484
485 public function writeResponsibleUsers(array $a_users): void
486 {
487 $this->db->manipulateF(
488 "DELETE FROM cal_entry_responsible WHERE cal_id = %s",
489 array("integer"),
490 array($this->getEntryId())
491 );
492
493 if (is_array($a_users)) {
494 foreach ($a_users as $user_id) {
495 $this->db->manipulateF(
496 "INSERT INTO cal_entry_responsible (cal_id, user_id) " .
497 " VALUES (%s,%s)",
498 array("integer", "integer"),
499 array($this->getEntryId(), $user_id)
500 );
501 }
502 }
503
504 $this->responsible_users = $a_users;
505 }
506
507 public function readResponsibleUsers(): array
508 {
509 $set = $this->db->queryF(
510 "SELECT * FROM cal_entry_responsible WHERE cal_id = %s",
511 array("integer"),
512 array($this->getEntryId())
513 );
514
515 $return = array();
516 while ($rec = $this->db->fetchAssoc($set)) {
517 $n = ilObjUser::_lookupName((int) $rec["user_id"]);
518 $return[] = array_merge(
519 $n,
520 array("login" => ilObjUser::_lookupLogin((int) $rec["user_id"]))
521 );
522 }
523 return $return;
524 }
525}
const IL_CAL_UNIX
const IL_CAL_DATETIME
error(string $a_errmsg)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _deleteByAppointmentId(int $a_app_id)
Delete appointment assignment.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _delete(int $a_entry_id)
setEnd(?ilDateTime $a_end)
setTranslationType(int $a_type)
setStart(?ilDateTime $a_start)
ilErrorHandling $error
setMilestone(bool $a_status)
setLastUpdate(ilDateTime $a_date)
setDescription(string $a_description)
setFullday(bool $a_fullday)
set fullday event Fullday events do not change their time in different timezones.
setLocation(string $a_location)
setCompletion(int $a_completion)
enableNotification(bool $a_status)
getEnd()
Get end of period.
setSubtitle(string $a_subtitle)
set subtitle Used for automatic generated appointments.
getStart()
Get start of date period.
isFullday()
is event a fullday period
__clone()
clone instance
appointmentToMailString(ilLanguage $lng)
writeResponsibleUsers(array $a_users)
parseDynamicTitle(string $a_type)
setFurtherInformations(string $a_informations)
setAutoGenerated(bool $a_status)
getPresentationTitle(bool $a_shorten=true)
setContextInfo(string $a_info)
setContextId(int $a_context_id)
setTitle(string $a_title)
static _delete(int $a_cal_id)
static getAppointmentIds(int $a_user_id, int $a_context_id=null, ?ilDateTime $a_start=null, ?int $a_type=null, bool $a_check_owner=true)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
static setUseRelativeDates(bool $a_status)
set use relative dates
@classDescription Date and time handling
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.
Class for single dates.
Error Handling & global info handling uses PEAR error class.
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Component logger with individual log levels by component id.
static _lookupName(int $a_user_id)
lookup user name
static _lookupLogin(int $a_user_id)
static shortenWords(string $a_str, int $a_len=30, bool $a_dots=true)
Ensure that the maximum word lenght within a text is not longer than $a_len.
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query