ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
60  $this->read();
61  }
62  }
63 
67  public function __clone()
68  {
69  $this->entry_id = NULL;
70  }
71 
79  public static function _delete($a_entry_id)
80  {
81  global $ilDB;
82 
83  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
84  ilCalendarRecurrence::_delete($a_entry_id);
85 
86  $query = "DELETE FROM cal_entries ".
87  "WHERE cal_id = ".$ilDB->quote($a_entry_id ,'integer')." ";
88  $res = $ilDB->manipulate($query);
89 
90  return true;
91  }
92 
99  public function getEntryId()
100  {
101  return $this->entry_id;
102  }
103 
111  public function getLastUpdate()
112  {
113  return $this->last_update ? $this->last_update : new ilDateTime(time(),IL_CAL_UNIX);
114  }
115 
123  public function setLastUpdate($a_date)
124  {
125  $this->last_update = $a_date;
126  }
127 
128 
135  public function getStart()
136  {
137  return $this->start;
138 
139  }
140 
147  public function setStart($a_start)
148  {
149  $this->start = $a_start;
150  }
151 
157  public function getEnd()
158  {
159  return $this->end;
160  }
161 
167  public function setEnd($a_end)
168  {
169  $this->end = $a_end;
170  }
171 
179  public function setTitle($a_title)
180  {
181  $this->title = $a_title;
182  }
183 
190  public function getTitle()
191  {
192  return $this->title;
193  }
194 
202  public function getPresentationTitle($a_shorten = true)
203  {
204  global $lng;
205 
207  {
208  $title = $this->getTitle();
209  }
210  elseif(strlen($this->getSubtitle()))
211  {
212  // parse dynamic title?
213  if(preg_match("/#([a-z]+)#/", $this->getSubtitle(), $matches))
214  {
215  $subtitle = $this->parseDynamicTitle($matches[1]);
216  }
217  else
218  {
219  $subtitle = $lng->txt($this->getSubtitle());
220  }
221  $title = $this->getTitle().
222  (strlen($subtitle)
223  ? ' ('.$subtitle.')'
224  : '');
225  }
226  else
227  {
228  $title = $lng->txt($this->getTitle());
229  }
230 
231  if($a_shorten)
232  {
233  return ilUtil::shortenText(ilUtil::shortenWords($title,20),40,true);
234  }
235  return $title;
236  }
237 
238  public function getPresentationStyle()
239  {
240  // see parseDynamicTitle()
241  return $this->presentation_style;
242  }
243 
244  protected function parseDynamicTitle($a_type)
245  {
246  global $lng;
247 
248  $title = $style = "";
249  switch($a_type)
250  {
251  case "consultationhour":
252  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
253  $entry = new ilBookingEntry($this->getContextId());
254  if($entry)
255  {
256  if($entry->isOwner())
257  {
258  $max = (int)$entry->getNumberOfBookings();
259  $current = (int)$entry->getCurrentNumberOfBookings($this->getEntryId());
260  if(!$current)
261  {
262  $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: green';
263  $title = $lng->txt('cal_book_free');
264  }
265  elseif($current >= $max)
266  {
267  $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: red';
268  $title = $lng->txt('cal_booked_out');
269  }
270  else
271  {
272  $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: yellow';
273  $title = $current.'/'.$max;
274  }
275  }
276  else
277  {
278  /*
279  * if($entry->hasBooked($this->getEntryId()))
280  */
281  include_once 'Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
282  $apps = ilConsultationHourAppointments::getAppointmentIds($entry->getObjId(), $this->getContextId(), $this->getStart());
283  $orig_event = $apps[0];
284  if($entry->hasBooked($orig_event))
285  {
286  $style = ';border-left-width: 5px; border-left-style: solid; border-left-color: green';
287  $title = $lng->txt('cal_date_booked');
288  }
289  }
290  }
291  break;
292  }
293 
294  if($style)
295  {
296  $this->presentation_style = $style;
297  }
298  return $title;
299  }
300 
310  public function setSubtitle($a_subtitle)
311  {
312  $this->subtitle = $a_subtitle;
313  }
314 
321  public function getSubtitle()
322  {
323  return $this->subtitle;
324  }
325 
333  public function setDescription($a_description)
334  {
335  $this->description = $a_description;
336  }
337 
343  public function getDescription()
344  {
345  return $this->description;
346  }
347 
355  public function setLocation($a_location)
356  {
357  $this->location = $a_location;
358  }
359 
365  public function getLocation()
366  {
367  return $this->location;
368  }
369 
377  public function setFurtherInformations($a_informations)
378  {
379  $this->further_informations = $a_informations;
380  }
381 
387  public function getFurtherInformations()
388  {
390  }
391 
401  public function setFullday($a_fullday)
402  {
403  $this->fullday = (bool) $a_fullday;
404  }
405 
411  public function isFullday()
412  {
413  return (bool) $this->fullday;
414  }
415 
423  public function isAutoGenerated()
424  {
425  return (bool) $this->is_auto_generated;
426  }
427 
435  public function setAutoGenerated($a_status)
436  {
437  $this->is_auto_generated = $a_status;
438  }
439 
447  public function isMilestone()
448  {
449  return (bool) $this->is_milestone;
450  }
451 
459  public function setMilestone($a_status)
460  {
461  $this->is_milestone = $a_status;
462  }
463 
469  function setCompletion($a_completion)
470  {
471  $this->completion = $a_completion;
472  }
473 
479  function getCompletion()
480  {
481  return $this->completion;
482  }
483 
491  public function setContextId($a_context_id)
492  {
493  $this->context_id = $a_context_id;
494  }
495 
502  public function getContextId()
503  {
504  return $this->context_id;
505  }
506 
514  public function setTranslationType($a_type)
515  {
516  $this->translation_type = $a_type;
517  }
518 
525  public function getTranslationType()
526  {
528  }
529 
534  public function enableNotification($a_status)
535  {
536  $this->notification = $a_status;
537  }
538 
543  public function isNotificationEnabled()
544  {
545  return (bool) $this->notification;
546  }
547 
554  public function update()
555  {
556  global $ilDB;
557 
558  $now = new ilDateTime(time(),IL_CAL_UNIX);
559  $utc_timestamp = $now->get(IL_CAL_DATETIME,'',ilTimeZone::UTC);
560 
561 
562  $query = "UPDATE cal_entries ".
563  "SET title = ".$this->db->quote($this->getTitle() ,'text').", ".
564  "last_update = ".$ilDB->quote($utc_timestamp,'timestamp').", ".
565  "subtitle = ".$this->db->quote($this->getSubtitle() ,'text').", ".
566  "description = ".$this->db->quote($this->getDescription(),'text').", ".
567  "location = ".$this->db->quote($this->getLocation() ,'text').", ".
568  "fullday = ".$ilDB->quote($this->isFullday() ? 1 : 0,'integer').", ".
569  "starta = ".$this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
570  "enda = ".$this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
571  "informations = ".$this->db->quote($this->getFurtherInformations() ,'text').", ".
572  "auto_generated = ".$this->db->quote($this->isAutoGenerated() ,'integer').", ".
573  "translation_type = ".$this->db->quote($this->getTranslationType() ,'integer').", ".
574  "context_id = ".$this->db->quote($this->getContextId() ,'integer').", ".
575  "completion = ".$this->db->quote($this->getCompletion(), 'integer').", ".
576  "is_milestone = ".$this->db->quote($this->isMilestone() ? 1 : 0, 'integer').", ".
577  'notification = '.$this->db->quote($this->isNotificationEnabled() ? 1 : 0,'integer').' '.
578  "WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
579  $res = $ilDB->manipulate($query);
580 
581  return true;
582  }
583 
590  public function save()
591  {
592  global $ilDB;
593 
594  $next_id = $ilDB->nextId('cal_entries');
595  $now = new ilDateTime(time(),IL_CAL_UNIX);
596  $utc_timestamp = $now->get(IL_CAL_DATETIME,'',ilTimeZone::UTC);
597 
598  $query = "INSERT INTO cal_entries (cal_id,title,last_update,subtitle,description,location,fullday,starta,enda, ".
599  "informations,auto_generated,context_id,translation_type, completion, is_milestone, notification) ".
600  "VALUES( ".
601  $ilDB->quote($next_id,'integer').", ".
602  $this->db->quote($this->getTitle(),'text').", ".
603  $ilDB->quote($utc_timestamp,'timestamp').", ".
604  $this->db->quote($this->getSubtitle(),'text').", ".
605  $this->db->quote($this->getDescription() ,'text').", ".
606  $this->db->quote($this->getLocation() ,'text').", ".
607  $ilDB->quote($this->isFullday() ? 1 : 0,'integer').", ".
608  $this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
609  $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
610  $this->db->quote($this->getFurtherInformations() ,'text').", ".
611  $this->db->quote($this->isAutoGenerated() ,'integer').", ".
612  $this->db->quote($this->getContextId() ,'integer').", ".
613  $this->db->quote($this->getTranslationType() ,'integer').", ".
614  $this->db->quote($this->getCompletion(), 'integer').", ".
615  $this->db->quote($this->isMilestone() ? 1 : 0, 'integer').", ".
616  $this->db->quote($this->isNotificationEnabled() ? 1 : 0,'integer').' '.
617  ")";
618  $res = $ilDB->manipulate($query);
619 
620  $this->entry_id = $next_id;
621  return true;
622  }
623 
630  public function delete()
631  {
632  global $ilDB;
633 
634  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
636 
637  $query = "DELETE FROM cal_entries ".
638  "WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
639  $res = $ilDB->manipulate($query);
640 
641  include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
643 
644  return true;
645  }
646 
653  public function validate()
654  {
655  global $ilErr,$lng;
656 
657  $success = true;
658  $ilErr->setMessage('');
659  if(!strlen($this->getTitle()))
660  {
661  $success = false;
662  $ilErr->appendMessage($lng->txt('err_missing_title'));
663  }
664  if(!$this->getStart() || !$this->getEnd())
665  {
666  $success = false;
667  }
668  else if(ilDateTime::_before($this->getEnd(),$this->getStart(),''))
669  {
670  $success = false;
671  $ilErr->appendMessage($lng->txt('err_end_before_start'));
672  }
673  return $success;
674  }
675 
676 
677 
683  protected function read()
684  {
685  global $ilDB;
686 
687  $query = "SELECT * FROM cal_entries WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
688  $res = $this->db->query($query);
689  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
690  {
691  $this->setLastUpdate(new ilDateTime($row->last_update,IL_CAL_DATETIME,'UTC'));
692  $this->setTitle($row->title);
693  $this->setSubtitle($row->subtitle);
694  $this->setDescription($row->description);
695  $this->setLocation($row->location);
696  $this->setFurtherInformations($row->informations);
697  $this->setFullday((bool) $row->fullday);
698  $this->setAutoGenerated($row->auto_generated);
699  $this->setContextId($row->context_id);
700  $this->setTranslationType($row->translation_type);
701  $this->setCompletion($row->completion);
702  $this->setMilestone($row->is_milestone);
703  $this->enableNotification((bool) $row->notification);
704 
705  if($this->isFullday())
706  {
707  $this->start = new ilDate($row->starta,IL_CAL_DATETIME);
708  $this->end = new ilDate($row->enda,IL_CAL_DATETIME);
709  }
710  else
711  {
712  $this->start = new ilDateTime($row->starta,IL_CAL_DATETIME,'UTC');
713  $this->end = new ilDateTime($row->enda,IL_CAL_DATETIME,'UTC');
714  }
715  }
716 
717  }
718 
724  public function appointmentToMailString($lng)
725  {
726  $body = $lng->txt('cal_details');
727  $body .= "\n\n";
728  $body .= $lng->txt('title').': '.$this->getTitle()."\n";
729 
731  $body .= $lng->txt('date').': '.ilDatePresentation::formatPeriod($this->getStart(), $this->getEnd())."\n";
733 
734  if(strlen($this->getLocation()))
735  {
736  $body .= $lng->txt('cal_where').': '.$this->getLocation()."\n";
737  }
738 
739  if(strlen($this->getDescription()))
740  {
741  $body .= $lng->txt('description').': '.$this->getDescription()."\n";
742  }
743  return $body;
744  }
745 
746 
750  function writeResponsibleUsers($a_users)
751  {
752  global $ilDB;
753 
754  $ilDB->manipulateF("DELETE FROM cal_entry_responsible WHERE cal_id = %s",
755  array("integer"), array($this->getEntryId()));
756 
757  if (is_array($a_users))
758  {
759  foreach ($a_users as $user_id)
760  {
761  $ilDB->manipulateF("INSERT INTO cal_entry_responsible (cal_id, user_id) ".
762  " VALUES (%s,%s)", array("integer", "integer"),
763  array($this->getEntryId(), $user_id));
764  }
765  }
766 
767  $this->responsible_users = $a_users;
768  }
769 
774  {
775  global $ilDB;
776 
777  $set = $ilDB->queryF("SELECT * FROM cal_entry_responsible WHERE cal_id = %s",
778  array("integer"), array($this->getEntryId()));
779 
780  $return = array();
781  while($rec = $ilDB->fetchAssoc($set))
782  {
783  $n = ilObjUser::_lookupName($rec["user_id"]);
784  $return[] = array_merge($n,
785  array("login" => ilObjUser::_lookupLogin($rec["user_id"])));
786  }
787 
788  return $return;
789  }
790 }
791 ?>
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
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 getAppointmentIds($a_user_id, $a_context_id=NULL, $a_start=NULL, $a_type=NULL, $a_check_owner=true)
Get all appointment ids.
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.
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
getFurtherInformations()
get further informations
$a_context_id
Definition: workflow.php:98
getEntryId()
get entry id
Booking definition.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
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:93
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.
writeResponsibleUsers($a_users)
Write users responsible for a milestone.
isAutoGenerated()
is auto generated
notification()
Definition: notification.php:2
Date and time handling
$n
Definition: RandomTest.php:80
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
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