ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
All Data Structures Namespaces Files Functions Variables Typedefs Modules Pages
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 
4 include_once('Services/Calendar/classes/class.ilDate.php');
5 include_once('./Services/Calendar/interfaces/interface.ilDatePeriod.php');
6 
7 define('IL_CAL_TRANSLATION_NONE', 0);
8 define('IL_CAL_TRANSLATION_SYSTEM', 1);
9 
10 
20 class ilCalendarEntry implements ilDatePeriod
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;
39  protected $is_milestone = false;
40  protected $completion = 0;
41 
42  protected $notification = false;
43 
51  public function __construct($a_id = 0)
52  {
53  global $ilDB,$ilLog;
54 
55  $this->log = $ilLog;
56  $this->db = $ilDB;
57 
58  if ($this->entry_id = $a_id) {
59  $this->read();
60  }
61  }
62 
66  public function __clone()
67  {
68  $this->entry_id = null;
69  }
70 
78  public static function _delete($a_entry_id)
79  {
80  global $ilDB;
81 
82  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
83  ilCalendarRecurrence::_delete($a_entry_id);
84 
85  $query = "DELETE FROM cal_entries " .
86  "WHERE cal_id = " . $ilDB->quote($a_entry_id, 'integer') . " ";
87  $res = $ilDB->manipulate($query);
88 
89  return true;
90  }
91 
98  public function getEntryId()
99  {
100  return $this->entry_id;
101  }
102 
110  public function getLastUpdate()
111  {
112  return $this->last_update ? $this->last_update : new ilDateTime(time(), IL_CAL_UNIX);
113  }
114 
122  public function setLastUpdate($a_date)
123  {
124  $this->last_update = $a_date;
125  }
126 
127 
134  public function getStart()
135  {
136  return $this->start;
137  }
138 
145  public function setStart($a_start)
146  {
147  $this->start = $a_start;
148  }
149 
155  public function getEnd()
156  {
157  return $this->end;
158  }
159 
165  public function setEnd($a_end)
166  {
167  $this->end = $a_end;
168  }
169 
177  public function setTitle($a_title)
178  {
179  $this->title = $a_title;
180  }
181 
188  public function getTitle()
189  {
190  return $this->title;
191  }
192 
200  public function getPresentationTitle($a_shorten = true)
201  {
202  global $lng;
203 
205  $title = $this->getTitle();
206  } elseif (strlen($this->getSubtitle())) {
207  // parse dynamic title?
208  if (preg_match("/#([a-z]+)#/", $this->getSubtitle(), $matches)) {
209  $subtitle = $this->parseDynamicTitle($matches[1]);
210  } else {
211  $subtitle = $lng->txt($this->getSubtitle());
212  }
213  $title = $this->getTitle() .
214  (strlen($subtitle)
215  ? ' (' . $subtitle . ')'
216  : '');
217  } else {
218  $title = $lng->txt($this->getTitle());
219  }
220 
221  if ($a_shorten) {
222  return ilUtil::shortenText(ilUtil::shortenWords($title, 20), 40, true);
223  }
224  return $title;
225  }
226 
227  public function getPresentationStyle()
228  {
229  // see parseDynamicTitle()
230  return $this->presentation_style;
231  }
232 
233  protected function parseDynamicTitle($a_type)
234  {
235  global $lng;
236 
237  $title = $style = "";
238  switch ($a_type) {
239  case "consultationhour":
240  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
241  $entry = new ilBookingEntry($this->getContextId());
242  if ($entry) {
243  if ($entry->isOwner()) {
244  $max = (int) $entry->getNumberOfBookings();
245  $current = (int) $entry->getCurrentNumberOfBookings($this->getEntryId());
246  if (!$current) {
247  $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: green';
248  $title = $lng->txt('cal_book_free');
249  } elseif ($current >= $max) {
250  $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: red';
251  $title = $lng->txt('cal_booked_out');
252  } else {
253  $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: yellow';
254  $title = $current . '/' . $max;
255  }
256  } else {
257  /*
258  * if($entry->hasBooked($this->getEntryId()))
259  */
260  include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
261  $apps = ilConsultationHourAppointments::getAppointmentIds($entry->getObjId(), $this->getContextId(), $this->getStart());
262  $orig_event = $apps[0];
263  if ($entry->hasBooked($orig_event)) {
264  $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: green';
265  $title = $lng->txt('cal_date_booked');
266  }
267  }
268  }
269  break;
270  }
271 
272  if ($style) {
273  $this->presentation_style = $style;
274  }
275  return $title;
276  }
277 
287  public function setSubtitle($a_subtitle)
288  {
289  $this->subtitle = $a_subtitle;
290  }
291 
298  public function getSubtitle()
299  {
300  return $this->subtitle;
301  }
302 
310  public function setDescription($a_description)
311  {
312  $this->description = $a_description;
313  }
314 
320  public function getDescription()
321  {
322  return $this->description;
323  }
324 
332  public function setLocation($a_location)
333  {
334  $this->location = $a_location;
335  }
336 
342  public function getLocation()
343  {
344  return $this->location;
345  }
346 
354  public function setFurtherInformations($a_informations)
355  {
356  $this->further_informations = $a_informations;
357  }
358 
364  public function getFurtherInformations()
365  {
367  }
368 
378  public function setFullday($a_fullday)
379  {
380  $this->fullday = (bool) $a_fullday;
381  }
382 
388  public function isFullday()
389  {
390  return (bool) $this->fullday;
391  }
392 
400  public function isAutoGenerated()
401  {
402  return (bool) $this->is_auto_generated;
403  }
404 
412  public function setAutoGenerated($a_status)
413  {
414  $this->is_auto_generated = $a_status;
415  }
416 
424  public function isMilestone()
425  {
426  return (bool) $this->is_milestone;
427  }
428 
436  public function setMilestone($a_status)
437  {
438  $this->is_milestone = $a_status;
439  }
440 
446  public function setCompletion($a_completion)
447  {
448  $this->completion = $a_completion;
449  }
450 
456  public function getCompletion()
457  {
458  return $this->completion;
459  }
460 
468  public function setContextId($a_context_id)
469  {
470  $this->context_id = $a_context_id;
471  }
472 
479  public function getContextId()
480  {
481  return $this->context_id;
482  }
483 
491  public function setTranslationType($a_type)
492  {
493  $this->translation_type = $a_type;
494  }
495 
502  public function getTranslationType()
503  {
505  }
506 
511  public function enableNotification($a_status)
512  {
513  $this->notification = $a_status;
514  }
515 
520  public function isNotificationEnabled()
521  {
522  return (bool) $this->notification;
523  }
524 
531  public function update()
532  {
533  global $ilDB;
534 
535  $now = new ilDateTime(time(), IL_CAL_UNIX);
536  $utc_timestamp = $now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
537 
538 
539  $query = "UPDATE cal_entries " .
540  "SET title = " . $this->db->quote($this->getTitle(), 'text') . ", " .
541  "last_update = " . $ilDB->quote($utc_timestamp, 'timestamp') . ", " .
542  "subtitle = " . $this->db->quote($this->getSubtitle(), 'text') . ", " .
543  "description = " . $this->db->quote($this->getDescription(), 'text') . ", " .
544  "location = " . $this->db->quote($this->getLocation(), 'text') . ", " .
545  "fullday = " . $ilDB->quote($this->isFullday() ? 1 : 0, 'integer') . ", " .
546  "starta = " . $this->db->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
547  "enda = " . $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
548  "informations = " . $this->db->quote($this->getFurtherInformations(), 'text') . ", " .
549  "auto_generated = " . $this->db->quote($this->isAutoGenerated(), 'integer') . ", " .
550  "translation_type = " . $this->db->quote($this->getTranslationType(), 'integer') . ", " .
551  "context_id = " . $this->db->quote($this->getContextId(), 'integer') . ", " .
552  "completion = " . $this->db->quote($this->getCompletion(), 'integer') . ", " .
553  "is_milestone = " . $this->db->quote($this->isMilestone() ? 1 : 0, 'integer') . ", " .
554  'notification = ' . $this->db->quote($this->isNotificationEnabled() ? 1 : 0, 'integer') . ' ' .
555  "WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
556  $res = $ilDB->manipulate($query);
557 
558  return true;
559  }
560 
567  public function save()
568  {
569  global $ilDB;
570 
571  $next_id = $ilDB->nextId('cal_entries');
572  $now = new ilDateTime(time(), IL_CAL_UNIX);
573  $utc_timestamp = $now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
574 
575  $query = "INSERT INTO cal_entries (cal_id,title,last_update,subtitle,description,location,fullday,starta,enda, " .
576  "informations,auto_generated,context_id,translation_type, completion, is_milestone, notification) " .
577  "VALUES( " .
578  $ilDB->quote($next_id, 'integer') . ", " .
579  $this->db->quote($this->getTitle(), 'text') . ", " .
580  $ilDB->quote($utc_timestamp, 'timestamp') . ", " .
581  $this->db->quote($this->getSubtitle(), 'text') . ", " .
582  $this->db->quote($this->getDescription(), 'text') . ", " .
583  $this->db->quote($this->getLocation(), 'text') . ", " .
584  $ilDB->quote($this->isFullday() ? 1 : 0, 'integer') . ", " .
585  $this->db->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
586  $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
587  $this->db->quote($this->getFurtherInformations(), 'text') . ", " .
588  $this->db->quote($this->isAutoGenerated(), 'integer') . ", " .
589  $this->db->quote($this->getContextId(), 'integer') . ", " .
590  $this->db->quote($this->getTranslationType(), 'integer') . ", " .
591  $this->db->quote($this->getCompletion(), 'integer') . ", " .
592  $this->db->quote($this->isMilestone() ? 1 : 0, 'integer') . ", " .
593  $this->db->quote($this->isNotificationEnabled() ? 1 : 0, 'integer') . ' ' .
594  ")";
595  $res = $ilDB->manipulate($query);
596 
597  $this->entry_id = $next_id;
598  return true;
599  }
600 
607  public function delete()
608  {
609  global $ilDB;
610 
611  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
613 
614  $query = "DELETE FROM cal_entries " .
615  "WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
616  $res = $ilDB->manipulate($query);
617 
618  include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
620 
621  return true;
622  }
623 
630  public function validate()
631  {
632  global $ilErr,$lng;
633 
634  $success = true;
635  $ilErr->setMessage('');
636  if (!strlen($this->getTitle())) {
637  $success = false;
638  $ilErr->appendMessage($lng->txt('err_missing_title'));
639  }
640  if (!$this->getStart() || !$this->getEnd()) {
641  $success = false;
642  } elseif (ilDateTime::_before($this->getEnd(), $this->getStart(), '')) {
643  $success = false;
644  $ilErr->appendMessage($lng->txt('err_end_before_start'));
645  }
646  return $success;
647  }
648 
649 
650 
656  protected function read()
657  {
658  global $ilDB;
659 
660  $query = "SELECT * FROM cal_entries WHERE cal_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
661  $res = $this->db->query($query);
662  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
663  $this->setLastUpdate(new ilDateTime($row->last_update, IL_CAL_DATETIME, 'UTC'));
664  $this->setTitle($row->title);
665  $this->setSubtitle($row->subtitle);
666  $this->setDescription($row->description);
667  $this->setLocation($row->location);
668  $this->setFurtherInformations($row->informations);
669  $this->setFullday((bool) $row->fullday);
670  $this->setAutoGenerated($row->auto_generated);
671  $this->setContextId($row->context_id);
672  $this->setTranslationType($row->translation_type);
673  $this->setCompletion($row->completion);
674  $this->setMilestone($row->is_milestone);
675  $this->enableNotification((bool) $row->notification);
676 
677  if ($this->isFullday()) {
678  $this->start = new ilDate($row->starta, IL_CAL_DATETIME);
679  $this->end = new ilDate($row->enda, IL_CAL_DATETIME);
680  } else {
681  $this->start = new ilDateTime($row->starta, IL_CAL_DATETIME, 'UTC');
682  $this->end = new ilDateTime($row->enda, IL_CAL_DATETIME, 'UTC');
683  }
684  }
685  }
686 
692  public function appointmentToMailString($lng)
693  {
694  $body = $lng->txt('cal_details');
695  $body .= "\n\n";
696  $body .= $lng->txt('title') . ': ' . $this->getTitle() . "\n";
697 
699  $body .= $lng->txt('date') . ': ' . ilDatePresentation::formatPeriod($this->getStart(), $this->getEnd()) . "\n";
701 
702  if (strlen($this->getLocation())) {
703  $body .= $lng->txt('cal_where') . ': ' . $this->getLocation() . "\n";
704  }
705 
706  if (strlen($this->getDescription())) {
707  $body .= $lng->txt('description') . ': ' . $this->getDescription() . "\n";
708  }
709  return $body;
710  }
711 
712 
716  public function writeResponsibleUsers($a_users)
717  {
718  global $ilDB;
719 
720  $ilDB->manipulateF(
721  "DELETE FROM cal_entry_responsible WHERE cal_id = %s",
722  array("integer"),
723  array($this->getEntryId())
724  );
725 
726  if (is_array($a_users)) {
727  foreach ($a_users as $user_id) {
728  $ilDB->manipulateF(
729  "INSERT INTO cal_entry_responsible (cal_id, user_id) " .
730  " VALUES (%s,%s)",
731  array("integer", "integer"),
732  array($this->getEntryId(), $user_id)
733  );
734  }
735  }
736 
737  $this->responsible_users = $a_users;
738  }
739 
743  public function readResponsibleUsers()
744  {
745  global $ilDB;
746 
747  $set = $ilDB->queryF(
748  "SELECT * FROM cal_entry_responsible WHERE cal_id = %s",
749  array("integer"),
750  array($this->getEntryId())
751  );
752 
753  $return = array();
754  while ($rec = $ilDB->fetchAssoc($set)) {
755  $n = ilObjUser::_lookupName($rec["user_id"]);
756  $return[] = array_merge(
757  $n,
758  array("login" => ilObjUser::_lookupLogin($rec["user_id"]))
759  );
760  }
761 
762  return $return;
763  }
764 }
getTranslationType()
get translation type
save()
save one entry
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
setContextId($a_context_id)
set context id
global $ilErr
Definition: raiseError.php:16
Model for a calendar entry.
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.
$style
Definition: example_012.php:70
getPresentationTitle($a_shorten=true)
get title for presentation.
setTitle($a_title)
set title
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
const IL_CAL_DATETIME
setLastUpdate($a_date)
set last update
enableNotification($a_status)
Enable course group notification.
const IL_CAL_TRANSLATION_NONE
__clone()
clone instance
setFurtherInformations($a_informations)
set further informations
setDescription($a_description)
set description
readResponsibleUsers()
Read responsible users.
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.
getFurtherInformations()
get further informations
$a_context_id
Definition: workflow.php:97
getEntryId()
get entry id
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
Booking definition.
static setUseRelativeDates($a_status)
set use relative dates
const IL_CAL_UNIX
setSubtitle($a_subtitle)
set subtitle Used for automatic generated appointments.
getSubtitle()
get subtitle
isMilestone()
is milestone
$a_type
Definition: workflow.php:92
static _delete($a_entry_id)
delete entry
setFullday($a_fullday)
set fullday event Fullday events do not change their time in different timezones. ...
getDescription()
get description
getEnd()
get end public
getCompletion()
Get Completion.
$success
Definition: Utf8Test.php:86
Class for single dates.
foreach($_POST as $key=> $value) $res
writeResponsibleUsers($a_users)
Write users responsible for a milestone.
isAutoGenerated()
is auto generated
notification()
Definition: notification.php:2
Date and time handling
$query
$n
Definition: RandomTest.php:85
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
getContextId()
get context id
setCompletion($a_completion)
Set Completion.
Create styles array
The data for the language used.
static _delete($a_cal_id)
delete
setTranslationType($a_type)
public
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
setLocation($a_location)
set location
getLocation()
get location
setStart($a_start)
public
setMilestone($a_status)
set milestone
global $lng
Definition: privfeed.php:17
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
__construct($a_id=0)
Constructor.
isNotificationEnabled()
Check if course group notification is enabled.
setEnd($a_end)
set end public
getLastUpdate()
get last update
setAutoGenerated($a_status)
set auto generated