ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarEntry.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('Services/Calendar/classes/class.ilDate.php');
25 include_once('./Services/Calendar/interfaces/interface.ilDatePeriod.php');
26 
27 define('IL_CAL_TRANSLATION_NONE',0);
28 define('IL_CAL_TRANSLATION_SYSTEM',1);
29 
30 
40 class ilCalendarEntry implements ilDatePeriod
41 {
42  protected $log;
43  protected $db;
44 
45 
46  protected $entry_id;
47  protected $last_update;
48  protected $title;
49  protected $subtitle;
50  protected $description;
51  protected $location;
53  protected $start = null;
54  protected $fullday;
55  protected $end = null;
56  protected $is_auto_generated = false;
57  protected $context_id = 0;
59 
67  public function __construct($a_id = 0)
68  {
69  global $ilDB,$ilLog;
70 
71  $this->log = $ilLog;
72  $this->db = $ilDB;
73 
74  if($this->entry_id = $a_id)
75  {
76  $this->read();
77  }
78  }
79 
80 
88  public static function _delete($a_entry_id)
89  {
90  global $ilDB;
91 
92  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
93  ilCalendarRecurrence::_delete($a_entry_id);
94 
95  $query = "DELETE FROM cal_entries ".
96  "WHERE cal_id = ".$ilDB->quote($a_entry_id)." ";
97  $ilDB->query($query);
98  return true;
99  }
100 
107  public function getEntryId()
108  {
109  return $this->entry_id;
110  }
111 
119  public function getLastUpdate()
120  {
121  return $this->last_update ? $this->last_update : new ilDateTime(time(),IL_CAL_UNIX);
122  }
123 
131  public function setLastUpdate($a_date)
132  {
133  $this->last_update = $a_date;
134  }
135 
136 
143  public function getStart()
144  {
145  return $this->start ? $this->start : $this->start = new ilDateTime();
146 
147  }
148 
155  public function setStart(ilDateTime $a_start)
156  {
157  $this->start = $a_start;
158  }
159 
165  public function getEnd()
166  {
167  return $this->end ? $this->end : $this->end = new ilDateTime();
168  }
169 
175  public function setEnd($a_end)
176  {
177  $this->end = $a_end;
178  }
179 
187  public function setTitle($a_title)
188  {
189  $this->title = $a_title;
190  }
191 
198  public function getTitle()
199  {
200  return $this->title;
201  }
202 
210  public function getPresentationTitle()
211  {
212  global $ilUser,$lng;
213 
215  {
216  $title = $this->getTitle();
217  }
218  else
219  {
220  $title = $this->getTitle().' ('.$lng->txt($this->getSubtitle()).')';
221  }
222 
223  return ilUtil::shortenText(ilUtil::shortenWords($title,20),40,true);
224  }
225 
235  public function setSubtitle($a_subtitle)
236  {
237  $this->subtitle = $a_subtitle;
238  }
239 
246  public function getSubtitle()
247  {
248  return $this->subtitle;
249  }
250 
258  public function setDescription($a_description)
259  {
260  $this->description = $a_description;
261  }
262 
268  public function getDescription()
269  {
270  return $this->description;
271  }
272 
280  public function setLocation($a_location)
281  {
282  $this->location = $a_location;
283  }
284 
290  public function getLocation()
291  {
292  return $this->location;
293  }
294 
302  public function setFurtherInformations($a_informations)
303  {
304  $this->further_informations = $a_informations;
305  }
306 
312  public function getFurtherInformations()
313  {
315  }
316 
326  public function setFullday($a_fullday)
327  {
328  $this->fullday = (bool) $a_fullday;
329  }
330 
336  public function isFullday()
337  {
338  return (bool) $this->fullday;
339  }
340 
348  public function isAutoGenerated()
349  {
350  return (bool) $this->is_auto_generated;
351  }
352 
360  public function setAutoGenerated($a_status)
361  {
362  $this->is_auto_generated = $a_status;
363  }
364 
372  public function setContextId($a_context_id)
373  {
374  $this->context_id = $a_context_id;
375  }
376 
383  public function getContextId()
384  {
385  return $this->context_id;
386  }
387 
395  public function setTranslationType($a_type)
396  {
397  $this->translation_type = $a_type;
398  }
399 
406  public function getTranslationType()
407  {
409  }
410 
417  public function update()
418  {
419  $query = "UPDATE cal_entries ".
420  "SET title = ".$this->db->quote($this->getTitle()).", ".
421  "last_update = UTC_TIMESTAMP(), ".
422  "subtitle = ".$this->db->quote($this->getSubtitle()).", ".
423  "description = ".$this->db->quote($this->getDescription()).", ".
424  "location = ".$this->db->quote($this->getLocation()).", ".
425  "fullday = ".($this->isFullday() ? 1 : 0).", ".
426  "start = ".$this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC')).", ".
427  "end = ".$this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC')).", ".
428  "informations = ".$this->db->quote($this->getFurtherInformations()).", ".
429  "auto_generated = ".$this->db->quote($this->isAutoGenerated()).", ".
430  "translation_type = ".$this->db->quote($this->getTranslationType()).", ".
431  "context_id = ".$this->db->quote($this->getContextId())." ".
432  "WHERE cal_id = ".$this->db->quote($this->getEntryId())." ";
433 
434 
435  $res = $this->db->query($query);
436  return true;
437  }
438 
445  public function save()
446  {
447  $query = "INSERT INTO cal_entries ".
448  "SET title = ".$this->db->quote($this->getTitle()).", ".
449  "last_update = UTC_TIMESTAMP(), ".
450  "subtitle = ".$this->db->quote($this->getSubtitle()).", ".
451  "description = ".$this->db->quote($this->getDescription()).", ".
452  "location = ".$this->db->quote($this->getLocation()).", ".
453  "fullday = ".($this->isFullday() ? 1 : 0).", ".
454  "start = ".$this->db->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC')).", ".
455  "end = ".$this->db->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC')).", ".
456  "informations = ".$this->db->quote($this->getFurtherInformations()).", ".
457  "auto_generated = ".$this->db->quote($this->isAutoGenerated()).", ".
458  "context_id = ".$this->db->quote($this->getContextId()).", ".
459  "translation_type = ".$this->db->quote($this->getTranslationType())." ";
460 
461  $res = $this->db->query($query);
462  $this->entry_id = $this->db->getLastInsertId();
463  return true;
464  }
465 
472  public function delete()
473  {
474  include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
476 
477  $query = "DELETE FROM cal_entries ".
478  "WHERE cal_id = ".$this->db->quote($this->getEntryId())." ";
479  $this->db->query($query);
480  return true;
481  }
482 
489  public function validate()
490  {
491  global $ilErr,$lng;
492 
493  $success = true;
494  $ilErr->setMessage('');
495  if(!strlen($this->getTitle()))
496  {
497  $success = false;
498  $ilErr->appendMessage($lng->txt('err_missing_title'));
499  }
500  if(ilDateTime::_before($this->getEnd(),$this->getStart(),''))
501  {
502  $success = false;
503  $ilErr->appendMessage($lng->txt('err_end_before_start'));
504  }
505  return $success;
506  }
507 
508 
509 
515  protected function read()
516  {
517  $query = "SELECT * FROM cal_entries WHERE cal_id = ".$this->db->quote($this->getEntryId())." ";
518  $res = $this->db->query($query);
519  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
520  {
521  $this->setLastUpdate(new ilDateTime($row->last_update,IL_CAL_DATETIME,'UTC'));
522  $this->setTitle($row->title);
523  $this->setSubtitle($row->subtitle);
524  $this->setDescription($row->description);
525  $this->setLocation($row->location);
526  $this->setFurtherInformations($row->informations);
527  $this->setFullday((bool) $row->fullday);
528  $this->setAutoGenerated($row->auto_generated);
529  $this->setContextId($row->context_id);
530  $this->setTranslationType($row->translation_type);
531 
532  if($this->isFullday())
533  {
534  $this->start = new ilDate($row->start,IL_CAL_DATETIME);
535  $this->end = new ilDate($row->end,IL_CAL_DATETIME);
536  }
537  else
538  {
539  $this->start = new ilDateTime($row->start,IL_CAL_DATETIME,'UTC');
540  $this->end = new ilDateTime($row->end,IL_CAL_DATETIME,'UTC');
541  }
542  }
543 
544  }
545 }
546 ?>