ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarRecurrenceExclusion.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.ilDateList.php');
25 include_once('./Services/Calendar/classes/class.ilTimeZone.php');
26 include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
27 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
28 
39 {
40  protected $exclusion = null;
41  protected $cal_id = 0;
42  protected $exclusion_id = 0;
43 
44  protected $db = null;
45 
50  public function __construct($a_exclusion_id = 0)
51  {
52  global $ilDB;
53 
54  $this->db = $ilDB;
55  $this->exclusion_id = $a_exclusion_id;
56 
57  if($this->getId())
58  {
59  $this->read();
60  }
61  }
62 
63 
68  public function getId()
69  {
70  return $this->exclusion_id;
71  }
72 
77  public function getEntryId()
78  {
79  return $this->cal_id;
80  }
81 
87  public function setEntryId($a_id)
88  {
89  $this->cal_id = $a_id;
90  }
91 
96  public function getDate()
97  {
98  return $this->exclusion instanceof ilDate ? $this->exclusion : null;
99  }
100 
106  public function setDate(ilDate $dt = NULL)
107  {
108  $this->exclusion = $dt;
109  }
110 
115  public function toICal()
116  {
117  $entry = new ilCalendarEntry($this->getEntryId());
118  $start = $entry->getStart();
119 
120  if($entry->isFullday())
121  {
122  return 'EXDATE;VALUE=DATE:'.$this->getDate()->get(IL_CAL_FKT_DATE,'Ymd');
123  }
124  else
125  {
126  return 'EXDATE:'.
127  $this->getDate()->get(IL_CAL_FKT_DATE, 'Ymd').
128  'T'.$start->get(IL_CAL_FKT_DATE,'his');
129  }
130  }
131 
136  public function save()
137  {
138  global $ilDB;
139 
140  if(!$this->getDate())
141  {
142  return false;
143  }
144 
145  $query = "INSERT INTO cal_rec_exclusion (excl_id,cal_id,excl_date) ".
146  "VALUES( ".
147  $ilDB->quote($next_id = $ilDB->nextId('cal_rec_exclusion'),'integer').', '.
148  $ilDB->quote($this->getEntryId(),'integer').', '.
149  $ilDB->quote($this->getDate()->get(IL_CAL_DATE,'','UTC'),'timestamp').
150  ')';
151  $ilDB->manipulate($query);
152 
153  $this->exclusion_id = $next_id;
154  return $this->getId();
155  }
156 
161  protected function read()
162  {
163  global $ilDB;
164 
165  $query = "SELECT * FROM cal_rec_exclusion WHERE excl_id = ".$ilDB->quote($this->getId(),'integer');
166  $res = $ilDB->query($query);
167  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
168  {
169  $this->cal_id = $row->cal_id;
170  $this->setDate(new ilDate($row->excl_date,IL_CAL_DATE,'UTC'));
171  }
172  }
173 }
174 ?>