ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
53 
54  $ilDB = $DIC['ilDB'];
55 
56  $this->db = $ilDB;
57  $this->exclusion_id = $a_exclusion_id;
58 
59  if ($this->getId()) {
60  $this->read();
61  }
62  }
63 
64 
69  public function getId()
70  {
71  return $this->exclusion_id;
72  }
73 
78  public function getEntryId()
79  {
80  return $this->cal_id;
81  }
82 
88  public function setEntryId($a_id)
89  {
90  $this->cal_id = $a_id;
91  }
92 
97  public function getDate()
98  {
99  return $this->exclusion instanceof ilDate ? $this->exclusion : null;
100  }
101 
107  public function setDate(ilDate $dt = null)
108  {
109  $this->exclusion = $dt;
110  }
111 
116  public function toICal()
117  {
118  $entry = new ilCalendarEntry($this->getEntryId());
119  $start = $entry->getStart();
120 
121  if ($entry->isFullday()) {
122  return 'EXDATE;VALUE=DATE:' . $this->getDate()->get(IL_CAL_FKT_DATE, 'Ymd');
123  } else {
124  return 'EXDATE:' .
125  $this->getDate()->get(IL_CAL_FKT_DATE, 'Ymd', ilTimeZone::UTC) .
126  'T' . $start->get(IL_CAL_FKT_DATE, 'His', ilTimeZone::UTC) . 'Z';
127  }
128  }
129 
134  public function save()
135  {
136  global $DIC;
137 
138  $ilDB = $DIC['ilDB'];
139 
140  if (!$this->getDate()) {
141  return false;
142  }
143 
144  $query = "INSERT INTO cal_rec_exclusion (excl_id,cal_id,excl_date) " .
145  "VALUES( " .
146  $ilDB->quote($next_id = $ilDB->nextId('cal_rec_exclusion'), 'integer') . ', ' .
147  $ilDB->quote($this->getEntryId(), 'integer') . ', ' .
148  $ilDB->quote($this->getDate()->get(IL_CAL_DATE, '', 'UTC'), 'timestamp') .
149  ')';
150  $ilDB->manipulate($query);
151 
152  $this->exclusion_id = $next_id;
153  return $this->getId();
154  }
155 
160  protected function read()
161  {
162  global $DIC;
163 
164  $ilDB = $DIC['ilDB'];
165 
166  $query = "SELECT * FROM cal_rec_exclusion WHERE excl_id = " . $ilDB->quote($this->getId(), 'integer');
167  $res = $ilDB->query($query);
168  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
169  $this->cal_id = $row->cal_id;
170  $this->setDate(new ilDate($row->excl_date, IL_CAL_DATE, 'UTC'));
171  }
172  }
173 }
Model for a calendar entry.
setDate(ilDate $dt=null)
Set exclusion date.
global $DIC
Definition: saml.php:7
$start
Definition: bench.php:8
Class for single dates.
foreach($_POST as $key=> $value) $res
setEntryId($a_id)
Set entry id (id of calendar appointment)
const IL_CAL_FKT_DATE
$query
$row
const IL_CAL_DATE
global $ilDB
Stores exclusion dates for calendar recurrences.