ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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  {
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 ? $this->start : $this->start = new ilDateTime();
138 
139  }
140 
147  public function setStart(ilDateTime $a_start)
148  {
149  $this->start = $a_start;
150  }
151 
157  public function getEnd()
158  {
159  return $this->end ? $this->end : $this->end = new ilDateTime();
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 $ilUser,$lng;
205 
206  // #11587
208  !$this->getSubtitle())
209  {
210  $title = $this->getTitle();
211  }
212  else
213  {
214  $title = $this->getTitle().' ('.$lng->txt($this->getSubtitle()).')';
215  }
216 
217  if($a_shorten)
218  {
219  return ilUtil::shortenText(ilUtil::shortenWords($title,20),40,true);
220  }
221  return $title;
222  }
223 
233  public function setSubtitle($a_subtitle)
234  {
235  $this->subtitle = $a_subtitle;
236  }
237 
244  public function getSubtitle()
245  {
246  return $this->subtitle;
247  }
248 
256  public function setDescription($a_description)
257  {
258  $this->description = $a_description;
259  }
260 
266  public function getDescription()
267  {
268  return $this->description;
269  }
270 
278  public function setLocation($a_location)
279  {
280  $this->location = $a_location;
281  }
282 
288  public function getLocation()
289  {
290  return $this->location;
291  }
292 
300  public function setFurtherInformations($a_informations)
301  {
302  $this->further_informations = $a_informations;
303  }
304 
310  public function getFurtherInformations()
311  {
313  }
314 
324  public function setFullday($a_fullday)
325  {
326  $this->fullday = (bool) $a_fullday;
327  }
328 
334  public function isFullday()
335  {
336  return (bool) $this->fullday;
337  }
338 
346  public function isAutoGenerated()
347  {
348  return (bool) $this->is_auto_generated;
349  }
350 
358  public function setAutoGenerated($a_status)
359  {
360  $this->is_auto_generated = $a_status;
361  }
362 
370  public function isMilestone()
371  {
372  return (bool) $this->is_milestone;
373  }
374 
382  public function setMilestone($a_status)
383  {
384  $this->is_milestone = $a_status;
385  }
386 
392  function setCompletion($a_completion)
393  {
394  $this->completion = $a_completion;
395  }
396 
402  function getCompletion()
403  {
404  return $this->completion;
405  }
406 
414  public function setContextId($a_context_id)
415  {
416  $this->context_id = $a_context_id;
417  }
418 
425  public function getContextId()
426  {
427  return $this->context_id;
428  }
429 
437  public function setTranslationType($a_type)
438  {
439  $this->translation_type = $a_type;
440  }
441 
448  public function getTranslationType()
449  {
451  }
452 
457  public function enableNotification($a_status)
458  {
459  $this->notification = $a_status;
460  }
461 
466  public function isNotificationEnabled()
467  {
468  return (bool) $this->notification;
469  }
470 
477  public function update()
478  {
479  global $ilDB;
480 
481  $now = new ilDateTime(time(),IL_CAL_UNIX);
482  $utc_timestamp = $now->get(IL_CAL_TIMESTAMP,'',ilTimeZone::UTC);
483 
484 
485  $query = "UPDATE cal_entries ".
486  "SET title = ".$this->db->quote($this->getTitle() ,'text').", ".
487  "last_update = ".$ilDB->quote($utc_timestamp,'timestamp').", ".
488  "subtitle = ".$this->db->quote($this->getSubtitle() ,'text').", ".
489  "description = ".$this->db->quote($this->getDescription(),'text').", ".
490  "location = ".$this->db->quote($this->getLocation() ,'text').", ".
491  "fullday = ".$ilDB->quote($this->isFullday() ? 1 : 0,'integer').", ".
492  "starta = ".$this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
493  "enda = ".$this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
494  "informations = ".$this->db->quote($this->getFurtherInformations() ,'text').", ".
495  "auto_generated = ".$this->db->quote($this->isAutoGenerated() ,'integer').", ".
496  "translation_type = ".$this->db->quote($this->getTranslationType() ,'integer').", ".
497  "context_id = ".$this->db->quote($this->getContextId() ,'integer').", ".
498  "completion = ".$this->db->quote($this->getCompletion(), 'integer').", ".
499  "is_milestone = ".$this->db->quote($this->isMilestone() ? 1 : 0, 'integer').", ".
500  'notification = '.$this->db->quote($this->isNotificationEnabled() ? 1 : 0,'integer').' '.
501  "WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
502  $res = $ilDB->manipulate($query);
503 
504  return true;
505  }
506 
513  public function save()
514  {
515  global $ilDB;
516 
517  $next_id = $ilDB->nextId('cal_entries');
518  $now = new ilDateTime(time(),IL_CAL_UNIX);
519  $utc_timestamp = $now->get(IL_CAL_TIMESTAMP,'',ilTimeZone::UTC);
520 
521  $query = "INSERT INTO cal_entries (cal_id,title,last_update,subtitle,description,location,fullday,starta,enda, ".
522  "informations,auto_generated,context_id,translation_type, completion, is_milestone, notification) ".
523  "VALUES( ".
524  $ilDB->quote($next_id,'integer').", ".
525  $this->db->quote($this->getTitle(),'text').", ".
526  $ilDB->quote($utc_timestamp,'timestamp').", ".
527  $this->db->quote($this->getSubtitle(),'text').", ".
528  $this->db->quote($this->getDescription() ,'text').", ".
529  $this->db->quote($this->getLocation() ,'text').", ".
530  $ilDB->quote($this->isFullday() ? 1 : 0,'integer').", ".
531  $this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
532  $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
533  $this->db->quote($this->getFurtherInformations() ,'text').", ".
534  $this->db->quote($this->isAutoGenerated() ,'integer').", ".
535  $this->db->quote($this->getContextId() ,'integer').", ".
536  $this->db->quote($this->getTranslationType() ,'integer').", ".
537  $this->db->quote($this->getCompletion(), 'integer').", ".
538  $this->db->quote($this->isMilestone() ? 1 : 0, 'integer').", ".
539  $this->db->quote($this->isNotificationEnabled() ? 1 : 0,'integer').' '.
540  ")";
541  $res = $ilDB->manipulate($query);
542 
543  $this->entry_id = $next_id;
544  return true;
545  }
546 
553  public function delete()
554  {
555  global $ilDB;
556 
557  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
559 
560  $query = "DELETE FROM cal_entries ".
561  "WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
562  $res = $ilDB->manipulate($query);
563 
564  return true;
565  }
566 
573  public function validate()
574  {
575  global $ilErr,$lng;
576 
577  $success = true;
578  $ilErr->setMessage('');
579  if(!strlen($this->getTitle()))
580  {
581  $success = false;
582  $ilErr->appendMessage($lng->txt('err_missing_title'));
583  }
584  if(ilDateTime::_before($this->getEnd(),$this->getStart(),''))
585  {
586  $success = false;
587  $ilErr->appendMessage($lng->txt('err_end_before_start'));
588  }
589  return $success;
590  }
591 
592 
593 
599  protected function read()
600  {
601  global $ilDB;
602 
603  $query = "SELECT * FROM cal_entries WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
604  $res = $this->db->query($query);
605  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
606  {
607  $this->setLastUpdate(new ilDateTime($row->last_update,IL_CAL_DATETIME,'UTC'));
608  $this->setTitle($row->title);
609  $this->setSubtitle($row->subtitle);
610  $this->setDescription($row->description);
611  $this->setLocation($row->location);
612  $this->setFurtherInformations($row->informations);
613  $this->setFullday((bool) $row->fullday);
614  $this->setAutoGenerated($row->auto_generated);
615  $this->setContextId($row->context_id);
616  $this->setTranslationType($row->translation_type);
617  $this->setCompletion($row->completion);
618  $this->setMilestone($row->is_milestone);
619  $this->enableNotification((bool) $row->notification);
620 
621  if($this->isFullday())
622  {
623  $this->start = new ilDate($row->starta,IL_CAL_DATETIME);
624  $this->end = new ilDate($row->enda,IL_CAL_DATETIME);
625  }
626  else
627  {
628  $this->start = new ilDateTime($row->starta,IL_CAL_DATETIME,'UTC');
629  $this->end = new ilDateTime($row->enda,IL_CAL_DATETIME,'UTC');
630  }
631  }
632 
633  }
634 
640  public function appointmentToMailString($lng)
641  {
642  $body = $lng->txt('cal_details');
643  $body .= "\n\n";
644  $body .= $lng->txt('title').': '.$this->getTitle()."\n";
645 
647  $body .= $lng->txt('date').': '.ilDatePresentation::formatPeriod($this->getStart(), $this->getEnd())."\n";
649 
650  if(strlen($this->getLocation()))
651  {
652  $body .= $lng->txt('cal_where').': '.$this->getLocation()."\n";
653  }
654 
655  if(strlen($this->getDescription()))
656  {
657  $body .= $lng->txt('description').': '.$this->getDescription()."\n";
658  }
659  return $body;
660  }
661 
662 
666  function writeResponsibleUsers($a_users)
667  {
668  global $ilDB;
669 
670  $ilDB->manipulateF("DELETE FROM cal_entry_responsible WHERE cal_id = %s",
671  array("integer"), array($this->getEntryId()));
672 
673  if (is_array($a_users))
674  {
675  foreach ($a_users as $user_id)
676  {
677  $ilDB->manipulateF("INSERT INTO cal_entry_responsible (cal_id, user_id) ".
678  " VALUES (%s,%s)", array("integer", "integer"),
679  array($this->getEntryId(), $user_id));
680  }
681  }
682 
683  $this->responsible_users = $a_users;
684  }
685 
690  {
691  global $ilDB;
692 
693  $set = $ilDB->queryF("SELECT * FROM cal_entry_responsible WHERE cal_id = %s",
694  array("integer"), array($this->getEntryId()));
695 
696  $return = array();
697  while($rec = $ilDB->fetchAssoc($set))
698  {
699  $n = ilObjUser::_lookupName($rec["user_id"]);
700  $return[] = array_merge($n,
701  array("login" => ilObjUser::_lookupLogin($rec["user_id"])));
702  }
703 
704  return $return;
705  }
706 }
707 ?>