ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCalendarEntry.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('Services/Calendar/classes/class.ilDate.php');
5include_once('./Services/Calendar/interfaces/interface.ilDatePeriod.php');
6
7define('IL_CAL_TRANSLATION_NONE', 0);
8define('IL_CAL_TRANSLATION_SYSTEM', 1);
9
10
21{
22 protected $log;
23 protected $db;
24
25
26 protected $entry_id;
27 protected $last_update;
28 protected $title;
29 protected $subtitle;
30 protected $description;
31 protected $location;
33 protected $start = null;
34 protected $fullday;
35 protected $end = null;
36 protected $is_auto_generated = false;
37 protected $context_id = 0;
38 protected $context_info = '';
40 protected $is_milestone = false;
41 protected $completion = 0;
42
43 protected $notification = false;
44
52 public function __construct($a_id = 0)
53 {
54 global $DIC;
55
56 $ilDB = $DIC['ilDB'];
57 $this->log = $DIC->logger()->cal();
58
59 $this->db = $ilDB;
60
61 if ($this->entry_id = $a_id) {
62 $this->read();
63 }
64 }
65
69 public function __clone()
70 {
71 $this->entry_id = null;
72 }
73
81 public static function _delete($a_entry_id)
82 {
83 global $DIC;
84
85 $ilDB = $DIC['ilDB'];
86
87 include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
89
90 $query = "DELETE FROM cal_entries " .
91 "WHERE cal_id = " . $ilDB->quote($a_entry_id, 'integer') . " ";
92 $res = $ilDB->manipulate($query);
93
94 return true;
95 }
96
101 public function setContextInfo($a_info)
102 {
103 $this->context_info = $a_info;
104 }
105
109 public function getContextInfo()
110 {
111 return $this->context_info;
112 }
113
120 public function getEntryId()
121 {
122 return $this->entry_id;
123 }
124
132 public function getLastUpdate()
133 {
134 return $this->last_update ? $this->last_update : new ilDateTime(time(), IL_CAL_UNIX);
135 }
136
144 public function setLastUpdate($a_date)
145 {
146 $this->last_update = $a_date;
147 }
148
149
156 public function getStart()
157 {
158 return $this->start;
159 }
160
167 public function setStart($a_start)
168 {
169 $this->start = $a_start;
170 }
171
177 public function getEnd()
178 {
179 return $this->end;
180 }
181
187 public function setEnd($a_end)
188 {
189 $this->end = $a_end;
190 }
191
199 public function setTitle($a_title)
200 {
201 $this->title = $a_title;
202 }
203
210 public function getTitle()
211 {
212 return $this->title;
213 }
214
222 public function getPresentationTitle($a_shorten = true)
223 {
224 global $DIC;
225
226 $lng = $DIC['lng'];
227
229 $title = $this->getTitle();
230 } elseif (strlen($this->getSubtitle())) {
231 // parse dynamic title?
232 if (preg_match("/#([a-z]+)#/", $this->getSubtitle(), $matches)) {
233 $subtitle = $this->parseDynamicTitle($matches[1]);
234 } else {
235 $subtitle = $lng->txt($this->getSubtitle());
236 }
237 $title = $this->getTitle() .
238 (strlen($subtitle)
239 ? ' (' . $subtitle . ')'
240 : '');
241 } else {
242 $title = $lng->txt($this->getTitle());
243 }
244
245 if ($a_shorten) {
246 return ilUtil::shortenText(ilUtil::shortenWords($title, 20), 40, true);
247 }
248 return $title;
249 }
250
251 public function getPresentationStyle()
252 {
253 // see parseDynamicTitle()
254 return $this->presentation_style;
255 }
256
257 protected function parseDynamicTitle($a_type)
258 {
259 global $DIC;
260
261 $lng = $DIC['lng'];
262
263 $title = $style = "";
264 switch ($a_type) {
265 case "consultationhour":
266 include_once 'Services/Booking/classes/class.ilBookingEntry.php';
267 $entry = new ilBookingEntry($this->getContextId());
268 if ($entry) {
269 if ($entry->isOwner()) {
270 $max = (int) $entry->getNumberOfBookings();
271 $current = (int) $entry->getCurrentNumberOfBookings($this->getEntryId());
272 if (!$current) {
273 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: green';
274 $title = $lng->txt('cal_book_free');
275 } elseif ($current >= $max) {
276 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: red';
277 $title = $lng->txt('cal_booked_out');
278 } else {
279 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: yellow';
280 $title = $current . '/' . $max;
281 }
282 } else {
284 $entry->getObjId(),
285 $this->getContextId(),
286 $this->getStart()
287 );
288 $orig_event = $apps[0];
289 $max = $entry->getNumberOfBookings();
290 $current = $entry->getCurrentNumberOfBookings($this->getEntryId());
291 if ($entry->hasBooked($orig_event)) {
292 $title = $lng->txt('cal_date_booked');
293 } elseif ($current >= $max) {
294 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: red';
295 $title = $lng->txt('cal_booked_out');
296 } else {
297 $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: green';
298 $title = $lng->txt('cal_book_free');
299 }
300 }
301 }
302 break;
303 }
304
305 if ($style) {
306 $this->presentation_style = $style;
307 }
308 return $title;
309 }
310
320 public function setSubtitle($a_subtitle)
321 {
322 $this->subtitle = $a_subtitle;
323 }
324
331 public function getSubtitle()
332 {
333 return $this->subtitle;
334 }
335
343 public function setDescription($a_description)
344 {
345 $this->description = $a_description;
346 }
347
353 public function getDescription()
354 {
355 return $this->description;
356 }
357
365 public function setLocation($a_location)
366 {
367 $this->location = $a_location;
368 }
369
375 public function getLocation()
376 {
377 return $this->location;
378 }
379
387 public function setFurtherInformations($a_informations)
388 {
389 $this->further_informations = $a_informations;
390 }
391
397 public function getFurtherInformations()
398 {
400 }
401
411 public function setFullday($a_fullday)
412 {
413 $this->fullday = (bool) $a_fullday;
414 }
415
421 public function isFullday()
422 {
423 return (bool) $this->fullday;
424 }
425
433 public function isAutoGenerated()
434 {
435 return (bool) $this->is_auto_generated;
436 }
437
445 public function setAutoGenerated($a_status)
446 {
447 $this->is_auto_generated = $a_status;
448 }
449
457 public function isMilestone()
458 {
459 return (bool) $this->is_milestone;
460 }
461
469 public function setMilestone($a_status)
470 {
471 $this->is_milestone = $a_status;
472 }
473
479 public function setCompletion($a_completion)
480 {
481 $this->completion = $a_completion;
482 }
483
489 public function getCompletion()
490 {
491 return $this->completion;
492 }
493
501 public function setContextId($a_context_id)
502 {
503 $this->context_id = $a_context_id;
504 }
505
512 public function getContextId()
513 {
514 return $this->context_id;
515 }
516
524 public function setTranslationType($a_type)
525 {
526 $this->translation_type = $a_type;
527 }
528
535 public function getTranslationType()
536 {
538 }
539
544 public function enableNotification($a_status)
545 {
546 $this->notification = $a_status;
547 }
548
553 public function isNotificationEnabled()
554 {
555 return (bool) $this->notification;
556 }
557
564 public function update()
565 {
566 global $DIC;
567
568 $ilDB = $DIC['ilDB'];
569
570 $now = new ilDateTime(time(), IL_CAL_UNIX);
571 $utc_timestamp = $now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
572
573
574 $query = "UPDATE cal_entries " .
575 "SET title = " . $this->db->quote($this->getTitle(), 'text') . ", " .
576 "last_update = " . $ilDB->quote($utc_timestamp, 'timestamp') . ", " .
577 "subtitle = " . $this->db->quote($this->getSubtitle(), 'text') . ", " .
578 "description = " . $this->db->quote($this->getDescription(), 'text') . ", " .
579 "location = " . $this->db->quote($this->getLocation(), 'text') . ", " .
580 "fullday = " . $ilDB->quote($this->isFullday() ? 1 : 0, 'integer') . ", " .
581 "starta = " . $this->db->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
582 "enda = " . $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
583 "informations = " . $this->db->quote($this->getFurtherInformations(), 'text') . ", " .
584 "auto_generated = " . $this->db->quote($this->isAutoGenerated(), 'integer') . ", " .
585 "translation_type = " . $this->db->quote($this->getTranslationType(), 'integer') . ", " .
586 "context_id = " . $this->db->quote($this->getContextId(), 'integer') . ", " .
587 'context_info = ' . $this->db->quote($this->getContextInfo(), 'text') . ', ' .
588 "completion = " . $this->db->quote($this->getCompletion(), 'integer') . ", " .
589 "is_milestone = " . $this->db->quote($this->isMilestone() ? 1 : 0, 'integer') . ", " .
590 'notification = ' . $this->db->quote($this->isNotificationEnabled() ? 1 : 0, 'integer') . ' ' .
591 "WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
592 $res = $ilDB->manipulate($query);
593
594 return true;
595 }
596
603 public function save()
604 {
605 global $DIC;
606
607 $ilDB = $DIC['ilDB'];
608
609 $next_id = $ilDB->nextId('cal_entries');
610 $now = new ilDateTime(time(), IL_CAL_UNIX);
611 $utc_timestamp = $now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
612
613 $query = "INSERT INTO cal_entries (cal_id,title,last_update,subtitle,description,location,fullday,starta,enda, " .
614 "informations,auto_generated,context_id,context_info,translation_type, completion, is_milestone, notification) " .
615 "VALUES( " .
616 $ilDB->quote($next_id, 'integer') . ", " .
617 $this->db->quote($this->getTitle(), 'text') . ", " .
618 $ilDB->quote($utc_timestamp, 'timestamp') . ", " .
619 $this->db->quote($this->getSubtitle(), 'text') . ", " .
620 $this->db->quote($this->getDescription(), 'text') . ", " .
621 $this->db->quote($this->getLocation(), 'text') . ", " .
622 $ilDB->quote($this->isFullday() ? 1 : 0, 'integer') . ", " .
623 $this->db->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
624 $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
625 $this->db->quote($this->getFurtherInformations(), 'text') . ", " .
626 $this->db->quote($this->isAutoGenerated(), 'integer') . ", " .
627 $this->db->quote($this->getContextId(), 'integer') . ", " .
628 $this->db->quote($this->getContextInfo(), 'text') . ', ' .
629 $this->db->quote($this->getTranslationType(), 'integer') . ", " .
630 $this->db->quote($this->getCompletion(), 'integer') . ", " .
631 $this->db->quote($this->isMilestone() ? 1 : 0, 'integer') . ", " .
632 $this->db->quote($this->isNotificationEnabled() ? 1 : 0, 'integer') . ' ' .
633 ")";
634 $res = $ilDB->manipulate($query);
635
636 $this->entry_id = $next_id;
637 return true;
638 }
639
646 public function delete()
647 {
648 global $DIC;
649
650 $ilDB = $DIC['ilDB'];
651
652 include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
654
655 $query = "DELETE FROM cal_entries " .
656 "WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
657 $res = $ilDB->manipulate($query);
658
659 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
661
662 return true;
663 }
664
671 public function validate()
672 {
673 global $DIC;
674
675 $ilErr = $DIC['ilErr'];
676 $lng = $DIC['lng'];
677
678 $success = true;
679 $ilErr->setMessage('');
680 if (!strlen($this->getTitle())) {
681 $success = false;
682 $ilErr->appendMessage($lng->txt('err_missing_title'));
683 }
684 if (!$this->getStart() || !$this->getEnd()) {
685 $success = false;
686 } elseif (ilDateTime::_before($this->getEnd(), $this->getStart(), '')) {
687 $success = false;
688 $ilErr->appendMessage($lng->txt('err_end_before_start'));
689 }
690 return $success;
691 }
692
693
694
700 protected function read()
701 {
702 global $DIC;
703
704 $ilDB = $DIC['ilDB'];
705
706 $query = "SELECT * FROM cal_entries WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
707 $res = $this->db->query($query);
708 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
709 $this->setLastUpdate(new ilDateTime($row->last_update, IL_CAL_DATETIME, 'UTC'));
710 $this->setTitle($row->title);
711 $this->setSubtitle($row->subtitle);
712 $this->setDescription($row->description);
713 $this->setLocation($row->location);
714 $this->setFurtherInformations($row->informations);
715 $this->setFullday((bool) $row->fullday);
716 $this->setAutoGenerated($row->auto_generated);
717 $this->setContextId($row->context_id);
718 $this->setContextInfo($row->context_info);
719 $this->setTranslationType($row->translation_type);
720 $this->setCompletion($row->completion);
721 $this->setMilestone($row->is_milestone);
722 $this->enableNotification((bool) $row->notification);
723
724 if ($this->isFullday()) {
725 $this->start = new ilDate($row->starta, IL_CAL_DATETIME);
726 $this->end = new ilDate($row->enda, IL_CAL_DATETIME);
727 } else {
728 $this->start = new ilDateTime($row->starta, IL_CAL_DATETIME, 'UTC');
729 $this->end = new ilDateTime($row->enda, IL_CAL_DATETIME, 'UTC');
730 }
731 }
732 }
733
740 {
741 $body = $lng->txt('cal_details');
742 $body .= "\n\n";
743 $body .= $lng->txt('title') . ': ' . $this->getTitle() . "\n";
744
746 $body .= $lng->txt('date') . ': ' . ilDatePresentation::formatPeriod($this->getStart(), $this->getEnd()) . "\n";
748
749 if (strlen($this->getLocation())) {
750 $body .= $lng->txt('cal_where') . ': ' . $this->getLocation() . "\n";
751 }
752
753 if (strlen($this->getDescription())) {
754 $body .= $lng->txt('description') . ': ' . $this->getDescription() . "\n";
755 }
756 return $body;
757 }
758
759
763 public function writeResponsibleUsers($a_users)
764 {
765 global $DIC;
766
767 $ilDB = $DIC['ilDB'];
768
769 $ilDB->manipulateF(
770 "DELETE FROM cal_entry_responsible WHERE cal_id = %s",
771 array("integer"),
772 array($this->getEntryId())
773 );
774
775 if (is_array($a_users)) {
776 foreach ($a_users as $user_id) {
777 $ilDB->manipulateF(
778 "INSERT INTO cal_entry_responsible (cal_id, user_id) " .
779 " VALUES (%s,%s)",
780 array("integer", "integer"),
781 array($this->getEntryId(), $user_id)
782 );
783 }
784 }
785
786 $this->responsible_users = $a_users;
787 }
788
792 public function readResponsibleUsers()
793 {
794 global $DIC;
795
796 $ilDB = $DIC['ilDB'];
797
798 $set = $ilDB->queryF(
799 "SELECT * FROM cal_entry_responsible WHERE cal_id = %s",
800 array("integer"),
801 array($this->getEntryId())
802 );
803
804 $return = array();
805 while ($rec = $ilDB->fetchAssoc($set)) {
806 $n = ilObjUser::_lookupName($rec["user_id"]);
807 $return[] = array_merge(
808 $n,
809 array("login" => ilObjUser::_lookupLogin($rec["user_id"]))
810 );
811 }
812
813 return $return;
814 }
815}
$n
Definition: RandomTest.php:85
$success
Definition: Utf8Test.php:86
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_TRANSLATION_NONE
const IL_CAL_UNIX
const IL_CAL_DATETIME
Booking definition.
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
Model for a calendar entry.
setTranslationType($a_type)
@access public
enableNotification($a_status)
Enable course group notification.
setLastUpdate($a_date)
set last update
writeResponsibleUsers($a_users)
Write users responsible for a milestone.
setAutoGenerated($a_status)
set auto generated
setFullday($a_fullday)
set fullday event Fullday events do not change their time in different timezones.
setLocation($a_location)
set location
static _delete($a_entry_id)
delete entry
setTitle($a_title)
set title
setCompletion($a_completion)
Set Completion.
setFurtherInformations($a_informations)
set further informations
getContextId()
get context id
setMilestone($a_status)
set milestone
readResponsibleUsers()
Read responsible users.
getEnd()
get end @access public
setStart($a_start)
@access public
__construct($a_id=0)
Constructor.
getTranslationType()
get translation type
getCompletion()
Get Completion.
setEnd($a_end)
set end @access public
getPresentationTitle($a_shorten=true)
get title for presentation.
setContextId($a_context_id)
set context id
isAutoGenerated()
is auto generated
isNotificationEnabled()
Check if course group notification is enabled.
setContextInfo($a_info)
Set context info.
read()
@access protected
__clone()
clone instance
setSubtitle($a_subtitle)
set subtitle Used for automatic generated appointments.
getFurtherInformations()
get further informations
getLastUpdate()
get last update
getDescription()
get description
setDescription($a_description)
set description
static _delete($a_cal_id)
delete
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
static setUseRelativeDates($a_status)
set use relative dates
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
static shortenWords($a_str, $a_len=30, $a_dots=true)
Ensure that the maximum word lenght within a text is not longer than $a_len.
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
global $DIC
Definition: goto.php:24
notification()
Definition: notification.php:2
$query
$ilErr
Definition: raiseError.php:18
$lng
foreach($_POST as $key=> $value) $res
global $ilDB