ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCalendarUserNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
12 const TYPE_USER = 1;
13 const TYPE_EMAIL = 2;
14
15
16 private $cal_id = 0;
17 private $rcps = array();
18
22 public function __construct($a_cal_id = 0)
23 {
24 $this->cal_id = $a_cal_id;
25 $this->read();
26 }
27
34 public static function deleteUser($a_usr_id)
35 {
36 global $ilDB;
37
38 $query = 'DELETE FROM cal_notification ' .
39 'WHERE user_id = ' . $ilDB->quote($a_usr_id, 'integer');
40 $res = $ilDB->manipulate($query);
41 return true;
42 }
43
50 public static function deleteCalendarEntry($a_cal_id)
51 {
52 global $ilDB;
53
54 $query = 'DELETE FROM cal_notification ' .
55 'WHERE cal_id = ' . $ilDB->quote($a_cal_id, 'integer');
56 $res = $ilDB->manipulate($query);
57 return true;
58 }
59
64 public function setEntryId($a_id)
65 {
66 $this->cal_id = $a_id;
67 }
68
72 public function getEntryId()
73 {
74 return $this->cal_id;
75 }
76
77 public function getRecipients()
78 {
79 return (array) $this->rcps;
80 }
81
82 public function validate()
83 {
84 global $ilErr, $lng;
85
86 if (!count($this->getRecipients())) {
87 return true;
88 }
89 foreach ((array) $this->getRecipients() as $rcp_data) {
90 if ($rcp_data['type'] == self::TYPE_USER) {
91 continue;
92 } else {
93 if (!ilUtil::is_email($rcp_data['email'])) {
94 $ilErr->appendMessage($lng->txt('cal_err_invalid_notification_rcps'));
95 return false;
96 }
97 }
98 }
99 return true;
100 }
101
105 public function save()
106 {
107 global $ilDB;
108
109 $this->deleteRecipients();
110
111 foreach ($this->getRecipients() as $rcp) {
112 $query = 'INSERT INTO cal_notification ' .
113 '(notification_id,cal_id, user_type, user_id, email) ' .
114 'VALUES ( ' .
115 $ilDB->quote($ilDB->nextId('cal_notification'), 'integer') . ', ' .
116 $ilDB->quote((int) $this->getEntryId(), 'integer') . ', ' .
117 $ilDB->quote((int) $rcp['type'], 'integer') . ', ' .
118 $ilDB->quote((int) $rcp['usr_id'], 'integer') . ', ' .
119 $ilDB->quote($rcp['email'], 'text') .
120 ')';
121 $ilDB->manipulate($query);
122 }
123 return true;
124 }
125
132 public function addRecipient($a_type, $a_usr_id = 0, $a_email = '')
133 {
134 $this->rcps[] = array(
135 'type' => $a_type,
136 'usr_id' => $a_usr_id,
137 'email' => $a_email
138 );
139 }
140
145 public function setRecipients($a_rcps)
146 {
147 $this->rcps = array();
148 }
149
155 public function deleteRecipients()
156 {
157 global $ilDB;
158
159 $query = 'DELETE FROM cal_notification ' .
160 'WHERE cal_id = ' . $ilDB->quote($this->getEntryId(), 'integer');
161 $res = $ilDB->manipulate($query);
162 return true;
163 }
164
165
166
171 protected function read()
172 {
173 global $ilDB;
174
175 if (!$this->getEntryId()) {
176 return true;
177 }
178
179 $query = 'SELECT * FROM cal_notification ' .
180 'WHERE cal_id = ' . $ilDB->quote($this->getEntryId(), 'integer');
181 $res = $ilDB->query($query);
182
183 $this->rcps = array();
184 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
185 $this->addRecipient(
186 $row->user_type,
187 $row->user_id,
188 $row->email
189 );
190 }
191 }
192
193 // Create table (not merged into into 4.3)
194 public static function createTable()
195 {
196 global $ilDB;
197
198 if ($ilDB->tableExists('cal_notification')) {
199 return true;
200 }
201
202 // Create notification table
203 $ilDB->createTable(
204 'cal_notification',
205 array(
206 'notification_id' => array('type' => 'integer','length' => 4,'notnull' => true),
207 'cal_id' => array('type' => 'integer','length' => 4, 'notnull' => true, 'default' => 0),
208 'user_type' => array('type' => 'integer','length' => 1, 'notnull' => true, 'default' => 0),
209 'user_id' => array('type' => 'integer','length' => 4, 'notnull' => true, 'default' => 0),
210 'email' => array('type' => 'text','length' => 64, 'notnull' => false)
211 )
212 );
213 $ilDB->addPrimaryKey(
214 'cal_notification',
215 array(
216 'notification_id'
217 )
218 );
219 $ilDB->createSequence('cal_notification');
220 $ilDB->addIndex('cal_notification', array('cal_id'), 'i1');
221 }
222}
An exception for terminatinating execution or to throw for unit testing.
setEntryId($a_id)
Set calendar entry id.
deleteRecipients()
Delete all recipients @global ilDB $ilDB.
static deleteCalendarEntry($a_cal_id)
Delete notification for a calendar entry @global ilDB $ilDB.
addRecipient($a_type, $a_usr_id=0, $a_email='')
Add recipient.
static deleteUser($a_usr_id)
Delete a singel user @global ilDB $ilDB.
read()
Read recipients @global ilDB $ilDB.
__construct($a_cal_id=0)
Init with calendar entry id.
static is_email($a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
global $lng
Definition: privfeed.php:17
$query
global $ilErr
Definition: raiseError.php:16
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92