ILIAS  Release_4_0_x_branch Revision 61816
 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 
49  public function __construct($a_id = 0)
50  {
51  global $ilDB,$ilLog;
52 
53  $this->log = $ilLog;
54  $this->db = $ilDB;
55 
56  if($this->entry_id = $a_id)
57  {
58  $this->read();
59  }
60  }
61 
62 
70  public static function _delete($a_entry_id)
71  {
72  global $ilDB;
73 
74  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
75  ilCalendarRecurrence::_delete($a_entry_id);
76 
77  $query = "DELETE FROM cal_entries ".
78  "WHERE cal_id = ".$ilDB->quote($a_entry_id ,'integer')." ";
79  $res = $ilDB->manipulate($query);
80 
81  return true;
82  }
83 
90  public function getEntryId()
91  {
92  return $this->entry_id;
93  }
94 
102  public function getLastUpdate()
103  {
104  return $this->last_update ? $this->last_update : new ilDateTime(time(),IL_CAL_UNIX);
105  }
106 
114  public function setLastUpdate($a_date)
115  {
116  $this->last_update = $a_date;
117  }
118 
119 
126  public function getStart()
127  {
128  return $this->start ? $this->start : $this->start = new ilDateTime();
129 
130  }
131 
138  public function setStart(ilDateTime $a_start)
139  {
140  $this->start = $a_start;
141  }
142 
148  public function getEnd()
149  {
150  return $this->end ? $this->end : $this->end = new ilDateTime();
151  }
152 
158  public function setEnd($a_end)
159  {
160  $this->end = $a_end;
161  }
162 
170  public function setTitle($a_title)
171  {
172  $this->title = $a_title;
173  }
174 
181  public function getTitle()
182  {
183  return $this->title;
184  }
185 
193  public function getPresentationTitle()
194  {
195  global $ilUser,$lng;
196 
198  {
199  $title = $this->getTitle();
200  }
201  else
202  {
203  $title = $this->getTitle().' ('.$lng->txt($this->getSubtitle()).')';
204  }
205 
206  return ilUtil::shortenText(ilUtil::shortenWords($title,20),40,true);
207  }
208 
218  public function setSubtitle($a_subtitle)
219  {
220  $this->subtitle = $a_subtitle;
221  }
222 
229  public function getSubtitle()
230  {
231  return $this->subtitle;
232  }
233 
241  public function setDescription($a_description)
242  {
243  $this->description = $a_description;
244  }
245 
251  public function getDescription()
252  {
253  return $this->description;
254  }
255 
263  public function setLocation($a_location)
264  {
265  $this->location = $a_location;
266  }
267 
273  public function getLocation()
274  {
275  return $this->location;
276  }
277 
285  public function setFurtherInformations($a_informations)
286  {
287  $this->further_informations = $a_informations;
288  }
289 
295  public function getFurtherInformations()
296  {
298  }
299 
309  public function setFullday($a_fullday)
310  {
311  $this->fullday = (bool) $a_fullday;
312  }
313 
319  public function isFullday()
320  {
321  return (bool) $this->fullday;
322  }
323 
331  public function isAutoGenerated()
332  {
333  return (bool) $this->is_auto_generated;
334  }
335 
343  public function setAutoGenerated($a_status)
344  {
345  $this->is_auto_generated = $a_status;
346  }
347 
355  public function isMilestone()
356  {
357  return (bool) $this->is_milestone;
358  }
359 
367  public function setMilestone($a_status)
368  {
369  $this->is_milestone = $a_status;
370  }
371 
377  function setCompletion($a_completion)
378  {
379  $this->completion = $a_completion;
380  }
381 
387  function getCompletion()
388  {
389  return $this->completion;
390  }
391 
399  public function setContextId($a_context_id)
400  {
401  $this->context_id = $a_context_id;
402  }
403 
410  public function getContextId()
411  {
412  return $this->context_id;
413  }
414 
422  public function setTranslationType($a_type)
423  {
424  $this->translation_type = $a_type;
425  }
426 
433  public function getTranslationType()
434  {
436  }
437 
444  public function update()
445  {
446  global $ilDB;
447 
448  $now = new ilDateTime(time(),IL_CAL_UNIX);
449  $utc_timestamp = $now->get(IL_CAL_TIMESTAMP,'',ilTimeZone::UTC);
450 
451 
452  $query = "UPDATE cal_entries ".
453  "SET title = ".$this->db->quote($this->getTitle() ,'text').", ".
454  "last_update = ".$ilDB->quote($utc_timestamp,'timestamp').", ".
455  "subtitle = ".$this->db->quote($this->getSubtitle() ,'text').", ".
456  "description = ".$this->db->quote($this->getDescription(),'text').", ".
457  "location = ".$this->db->quote($this->getLocation() ,'text').", ".
458  "fullday = ".$ilDB->quote($this->isFullday() ? 1 : 0,'integer').", ".
459  "starta = ".$this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
460  "enda = ".$this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
461  "informations = ".$this->db->quote($this->getFurtherInformations() ,'text').", ".
462  "auto_generated = ".$this->db->quote($this->isAutoGenerated() ,'integer').", ".
463  "translation_type = ".$this->db->quote($this->getTranslationType() ,'integer').", ".
464  "context_id = ".$this->db->quote($this->getContextId() ,'integer').", ".
465  "completion = ".$this->db->quote($this->getCompletion(), 'integer').", ".
466  "is_milestone = ".$this->db->quote($this->isMilestone() ? 1 : 0, 'integer')." ".
467  "WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
468  $res = $ilDB->manipulate($query);
469 
470  return true;
471  }
472 
479  public function save()
480  {
481  global $ilDB;
482 
483  $next_id = $ilDB->nextId('cal_entries');
484  $now = new ilDateTime(time(),IL_CAL_UNIX);
485  $utc_timestamp = $now->get(IL_CAL_TIMESTAMP,'',ilTimeZone::UTC);
486 
487  $query = "INSERT INTO cal_entries (cal_id,title,last_update,subtitle,description,location,fullday,starta,enda, ".
488  "informations,auto_generated,context_id,translation_type, completion, is_milestone) ".
489  "VALUES( ".
490  $ilDB->quote($next_id,'integer').", ".
491  $this->db->quote($this->getTitle(),'text').", ".
492  $ilDB->quote($utc_timestamp,'timestamp').", ".
493  $this->db->quote($this->getSubtitle(),'text').", ".
494  $this->db->quote($this->getDescription() ,'text').", ".
495  $this->db->quote($this->getLocation() ,'text').", ".
496  $ilDB->quote($this->isFullday() ? 1 : 0,'integer').", ".
497  $this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
498  $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'),'timestamp').", ".
499  $this->db->quote($this->getFurtherInformations() ,'text').", ".
500  $this->db->quote($this->isAutoGenerated() ,'integer').", ".
501  $this->db->quote($this->getContextId() ,'integer').", ".
502  $this->db->quote($this->getTranslationType() ,'integer').", ".
503  $this->db->quote($this->getCompletion(), 'integer').", ".
504  $this->db->quote($this->isMilestone() ? 1 : 0, 'integer')." ".
505  ")";
506  $res = $ilDB->manipulate($query);
507 
508  $this->entry_id = $next_id;
509  return true;
510  }
511 
518  public function delete()
519  {
520  global $ilDB;
521 
522  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
524 
525  $query = "DELETE FROM cal_entries ".
526  "WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
527  $res = $ilDB->manipulate($query);
528 
529  return true;
530  }
531 
538  public function validate()
539  {
540  global $ilErr,$lng;
541 
542  $success = true;
543  $ilErr->setMessage('');
544  if(!strlen($this->getTitle()))
545  {
546  $success = false;
547  $ilErr->appendMessage($lng->txt('err_missing_title'));
548  }
549  if(ilDateTime::_before($this->getEnd(),$this->getStart(),''))
550  {
551  $success = false;
552  $ilErr->appendMessage($lng->txt('err_end_before_start'));
553  }
554  return $success;
555  }
556 
557 
558 
564  protected function read()
565  {
566  global $ilDB;
567 
568  $query = "SELECT * FROM cal_entries WHERE cal_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
569  $res = $this->db->query($query);
570  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
571  {
572  $this->setLastUpdate(new ilDateTime($row->last_update,IL_CAL_DATETIME,'UTC'));
573  $this->setTitle($row->title);
574  $this->setSubtitle($row->subtitle);
575  $this->setDescription($row->description);
576  $this->setLocation($row->location);
577  $this->setFurtherInformations($row->informations);
578  $this->setFullday((bool) $row->fullday);
579  $this->setAutoGenerated($row->auto_generated);
580  $this->setContextId($row->context_id);
581  $this->setTranslationType($row->translation_type);
582  $this->setCompletion($row->completion);
583  $this->setMilestone($row->is_milestone);
584 
585  if($this->isFullday())
586  {
587  $this->start = new ilDate($row->starta,IL_CAL_DATETIME);
588  $this->end = new ilDate($row->enda,IL_CAL_DATETIME);
589  }
590  else
591  {
592  $this->start = new ilDateTime($row->starta,IL_CAL_DATETIME,'UTC');
593  $this->end = new ilDateTime($row->enda,IL_CAL_DATETIME,'UTC');
594  }
595  }
596 
597  }
598 
602  function writeResponsibleUsers($a_users)
603  {
604  global $ilDB;
605 
606  $ilDB->manipulateF("DELETE FROM cal_entry_responsible WHERE cal_id = %s",
607  array("integer"), array($this->getEntryId()));
608 
609  if (is_array($a_users))
610  {
611  foreach ($a_users as $user_id)
612  {
613  $ilDB->manipulateF("INSERT INTO cal_entry_responsible (cal_id, user_id) ".
614  " VALUES (%s,%s)", array("integer", "integer"),
615  array($this->getEntryId(), $user_id));
616  }
617  }
618 
619  $this->responsible_users = $a_users;
620  }
621 
626  {
627  global $ilDB;
628 
629  $set = $ilDB->queryF("SELECT * FROM cal_entry_responsible WHERE cal_id = %s",
630  array("integer"), array($this->getEntryId()));
631 
632  $return = array();
633  while($rec = $ilDB->fetchAssoc($set))
634  {
635  $n = ilObjUser::_lookupName($rec["user_id"]);
636  $return[] = array_merge($n,
637  array("login" => ilObjUser::_lookupLogin($rec["user_id"])));
638  }
639 
640  return $return;
641  }
642 }
643 ?>