ILIAS  eassessment Revision 61809
 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()
203  {
204  global $ilUser,$lng;
205 
207  {
208  $title = $this->getTitle();
209  }
210  else
211  {
212  $title = $this->getTitle().' ('.$lng->txt($this->getSubtitle()).')';
213  }
214 
215  return ilUtil::shortenText(ilUtil::shortenWords($title,20),40,true);
216  }
217 
227  public function setSubtitle($a_subtitle)
228  {
229  $this->subtitle = $a_subtitle;
230  }
231 
238  public function getSubtitle()
239  {
240  return $this->subtitle;
241  }
242 
250  public function setDescription($a_description)
251  {
252  $this->description = $a_description;
253  }
254 
260  public function getDescription()
261  {
262  return $this->description;
263  }
264 
272  public function setLocation($a_location)
273  {
274  $this->location = $a_location;
275  }
276 
282  public function getLocation()
283  {
284  return $this->location;
285  }
286 
294  public function setFurtherInformations($a_informations)
295  {
296  $this->further_informations = $a_informations;
297  }
298 
304  public function getFurtherInformations()
305  {
307  }
308 
318  public function setFullday($a_fullday)
319  {
320  $this->fullday = (bool) $a_fullday;
321  }
322 
328  public function isFullday()
329  {
330  return (bool) $this->fullday;
331  }
332 
340  public function isAutoGenerated()
341  {
342  return (bool) $this->is_auto_generated;
343  }
344 
352  public function setAutoGenerated($a_status)
353  {
354  $this->is_auto_generated = $a_status;
355  }
356 
364  public function isMilestone()
365  {
366  return (bool) $this->is_milestone;
367  }
368 
376  public function setMilestone($a_status)
377  {
378  $this->is_milestone = $a_status;
379  }
380 
386  function setCompletion($a_completion)
387  {
388  $this->completion = $a_completion;
389  }
390 
396  function getCompletion()
397  {
398  return $this->completion;
399  }
400 
408  public function setContextId($a_context_id)
409  {
410  $this->context_id = $a_context_id;
411  }
412 
419  public function getContextId()
420  {
421  return $this->context_id;
422  }
423 
431  public function setTranslationType($a_type)
432  {
433  $this->translation_type = $a_type;
434  }
435 
442  public function getTranslationType()
443  {
445  }
446 
451  public function enableNotification($a_status)
452  {
453  $this->notification = $a_status;
454  }
455 
460  public function isNotificationEnabled()
461  {
462  return (bool) $this->notification;
463  }
464 
471  public function update()
472  {
473  global $ilDB;
474 
475  $now = new ilDateTime(time(),IL_CAL_UNIX);
476  $utc_timestamp = $now->get(IL_CAL_TIMESTAMP,'',ilTimeZone::UTC);
477 
478 
479  $query = "UPDATE cal_entries ".
480  "SET title = ".$this->db->quote($this->getTitle() ,'text').", ".
481  "last_update = ".$ilDB->quote($utc_timestamp,'timestamp').", ".
482  "subtitle = ".$this->db->quote($this->getSubtitle() ,'text').", ".
483  "description = ".$this->db->quote($this->getDescription(),'text').", ".
484  "location = ".$this->db->quote($this->getLocation() ,'text').", ".
485  "fullday = ".$ilDB->quote($this->isFullday() ? 1 : 0,'integer').", ".
486  "starta = ".$this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
487  "enda = ".$this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
488  "informations = ".$this->db->quote($this->getFurtherInformations() ,'text').", ".
489  "auto_generated = ".$this->db->quote($this->isAutoGenerated() ,'integer').", ".
490  "translation_type = ".$this->db->quote($this->getTranslationType() ,'integer').", ".
491  "context_id = ".$this->db->quote($this->getContextId() ,'integer').", ".
492  "completion = ".$this->db->quote($this->getCompletion(), 'integer').", ".
493  "is_milestone = ".$this->db->quote($this->isMilestone() ? 1 : 0, 'integer').", ".
494  'notification = '.$this->db->quote($this->isNotificationEnabled() ? 1 : 0,'integer').' '.
495  "WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
496  $res = $ilDB->manipulate($query);
497 
498  return true;
499  }
500 
507  public function save()
508  {
509  global $ilDB;
510 
511  $next_id = $ilDB->nextId('cal_entries');
512  $now = new ilDateTime(time(),IL_CAL_UNIX);
513  $utc_timestamp = $now->get(IL_CAL_TIMESTAMP,'',ilTimeZone::UTC);
514 
515  $query = "INSERT INTO cal_entries (cal_id,title,last_update,subtitle,description,location,fullday,starta,enda, ".
516  "informations,auto_generated,context_id,translation_type, completion, is_milestone, notification) ".
517  "VALUES( ".
518  $ilDB->quote($next_id,'integer').", ".
519  $this->db->quote($this->getTitle(),'text').", ".
520  $ilDB->quote($utc_timestamp,'timestamp').", ".
521  $this->db->quote($this->getSubtitle(),'text').", ".
522  $this->db->quote($this->getDescription() ,'text').", ".
523  $this->db->quote($this->getLocation() ,'text').", ".
524  $ilDB->quote($this->isFullday() ? 1 : 0,'integer').", ".
525  $this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
526  $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
527  $this->db->quote($this->getFurtherInformations() ,'text').", ".
528  $this->db->quote($this->isAutoGenerated() ,'integer').", ".
529  $this->db->quote($this->getContextId() ,'integer').", ".
530  $this->db->quote($this->getTranslationType() ,'integer').", ".
531  $this->db->quote($this->getCompletion(), 'integer').", ".
532  $this->db->quote($this->isMilestone() ? 1 : 0, 'integer').", ".
533  $this->db->quote($this->isNotificationEnabled() ? 1 : 0,'integer').' '.
534  ")";
535  $res = $ilDB->manipulate($query);
536 
537  $this->entry_id = $next_id;
538  return true;
539  }
540 
547  public function delete()
548  {
549  global $ilDB;
550 
551  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
553 
554  $query = "DELETE FROM cal_entries ".
555  "WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
556  $res = $ilDB->manipulate($query);
557 
558  return true;
559  }
560 
567  public function validate()
568  {
569  global $ilErr,$lng;
570 
571  $success = true;
572  $ilErr->setMessage('');
573  if(!strlen($this->getTitle()))
574  {
575  $success = false;
576  $ilErr->appendMessage($lng->txt('err_missing_title'));
577  }
578  if(ilDateTime::_before($this->getEnd(),$this->getStart(),''))
579  {
580  $success = false;
581  $ilErr->appendMessage($lng->txt('err_end_before_start'));
582  }
583  return $success;
584  }
585 
586 
587 
593  protected function read()
594  {
595  global $ilDB;
596 
597  $query = "SELECT * FROM cal_entries WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
598  $res = $this->db->query($query);
599  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
600  {
601  $this->setLastUpdate(new ilDateTime($row->last_update,IL_CAL_DATETIME,'UTC'));
602  $this->setTitle($row->title);
603  $this->setSubtitle($row->subtitle);
604  $this->setDescription($row->description);
605  $this->setLocation($row->location);
606  $this->setFurtherInformations($row->informations);
607  $this->setFullday((bool) $row->fullday);
608  $this->setAutoGenerated($row->auto_generated);
609  $this->setContextId($row->context_id);
610  $this->setTranslationType($row->translation_type);
611  $this->setCompletion($row->completion);
612  $this->setMilestone($row->is_milestone);
613  $this->enableNotification((bool) $row->notification);
614 
615  if($this->isFullday())
616  {
617  $this->start = new ilDate($row->starta,IL_CAL_DATETIME);
618  $this->end = new ilDate($row->enda,IL_CAL_DATETIME);
619  }
620  else
621  {
622  $this->start = new ilDateTime($row->starta,IL_CAL_DATETIME,'UTC');
623  $this->end = new ilDateTime($row->enda,IL_CAL_DATETIME,'UTC');
624  }
625  }
626 
627  }
628 
634  public function appointmentToMailString($lng)
635  {
636  $body = $lng->txt('cal_details');
637  $body .= "\n\n";
638  $body .= $lng->txt('title').': '.$this->getTitle()."\n";
639 
641  $body .= $lng->txt('date').': '.ilDatePresentation::formatPeriod($this->getStart(), $this->getEnd())."\n";
643 
644  if(strlen($this->getLocation()))
645  {
646  $body .= $lng->txt('cal_where').': '.$this->getLocation()."\n";
647  }
648 
649  if(strlen($this->getDescription()))
650  {
651  $body .= $lng->txt('description').': '.$this->getDescription()."\n";
652  }
653  return $body;
654  }
655 
656 
660  function writeResponsibleUsers($a_users)
661  {
662  global $ilDB;
663 
664  $ilDB->manipulateF("DELETE FROM cal_entry_responsible WHERE cal_id = %s",
665  array("integer"), array($this->getEntryId()));
666 
667  if (is_array($a_users))
668  {
669  foreach ($a_users as $user_id)
670  {
671  $ilDB->manipulateF("INSERT INTO cal_entry_responsible (cal_id, user_id) ".
672  " VALUES (%s,%s)", array("integer", "integer"),
673  array($this->getEntryId(), $user_id));
674  }
675  }
676 
677  $this->responsible_users = $a_users;
678  }
679 
684  {
685  global $ilDB;
686 
687  $set = $ilDB->queryF("SELECT * FROM cal_entry_responsible WHERE cal_id = %s",
688  array("integer"), array($this->getEntryId()));
689 
690  $return = array();
691  while($rec = $ilDB->fetchAssoc($set))
692  {
693  $n = ilObjUser::_lookupName($rec["user_id"]);
694  $return[] = array_merge($n,
695  array("login" => ilObjUser::_lookupLogin($rec["user_id"])));
696  }
697 
698  return $return;
699  }
700 }
701 ?>