ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
88 return true;
89 }
90 foreach((array) $this->getRecipients() as $rcp_data)
91 {
92 if($rcp_data['type'] == self::TYPE_USER)
93 {
94 continue;
95 }
96 else
97 {
98 if(!ilUtil::is_email($rcp_data['email']))
99 {
100 $ilErr->appendMessage($lng->txt('cal_err_invalid_notification_rcps'));
101 return false;
102 }
103 }
104 }
105 return true;
106 }
107
111 public function save()
112 {
113 global $ilDB;
114
115 $this->deleteRecipients();
116
117 foreach($this->getRecipients() as $rcp)
118 {
119 $query = 'INSERT INTO cal_notification '.
120 '(notification_id,cal_id, user_type, user_id, email) '.
121 'VALUES ( '.
122 $ilDB->quote($ilDB->nextId('cal_notification'),'integer').', '.
123 $ilDB->quote((int) $this->getEntryId(),'integer').', '.
124 $ilDB->quote((int) $rcp['type'],'integer').', '.
125 $ilDB->quote((int) $rcp['usr_id'],'integer').', '.
126 $ilDB->quote($rcp['email'],'text').
127 ')';
128 $ilDB->manipulate($query);
129 }
130 return true;
131 }
132
139 public function addRecipient($a_type,$a_usr_id = 0,$a_email = '')
140 {
141 $this->rcps[] = array(
142 'type' => $a_type,
143 'usr_id' => $a_usr_id,
144 'email' => $a_email
145 );
146 }
147
152 public function setRecipients($a_rcps)
153 {
154 $this->rcps = array();
155 }
156
162 public function deleteRecipients()
163 {
164 global $ilDB;
165
166 $query = 'DELETE FROM cal_notification '.
167 'WHERE cal_id = '.$ilDB->quote($this->getEntryId(),'integer');
168 $res = $ilDB->manipulate($query);
169 return true;
170 }
171
172
173
178 protected function read()
179 {
180 global $ilDB;
181
182 if(!$this->getEntryId())
183 {
184 return true;
185 }
186
187 $query = 'SELECT * FROM cal_notification '.
188 'WHERE cal_id = '.$ilDB->quote($this->getEntryId(),'integer');
189 $res = $ilDB->query($query);
190
191 $this->rcps = array();
192 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
193 {
194 $this->addRecipient(
195 $row->user_type,
196 $row->user_id,
197 $row->email
198 );
199 }
200 }
201
202 // Create table (not merged into into 4.3)
203 public static function createTable()
204 {
205 global $ilDB;
206
207 if($ilDB->tableExists('cal_notification'))
208 {
209 return true;
210 }
211
212 // Create notification table
213 $ilDB->createTable(
214 'cal_notification',
215 array(
216 'notification_id' => array('type' => 'integer','length' => 4,'notnull' => true),
217 'cal_id' => array('type' => 'integer','length' => 4, 'notnull' => true, 'default' => 0),
218 'user_type' => array('type' => 'integer','length' => 1, 'notnull' => true, 'default' => 0),
219 'user_id' => array('type' => 'integer','length' => 4, 'notnull' => true, 'default' => 0),
220 'email' => array('type' => 'text','length' => 64, 'notnull' => false)
221 )
222 );
223 $ilDB->addPrimaryKey(
224 'cal_notification',
225 array(
226 'notification_id'
227 )
228 );
229 $ilDB->createSequence('cal_notification');
230 $ilDB->addIndex('cal_notification', array('cal_id'),'i1');
231 }
232}
233?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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)
This preg-based function checks whether an e-mail address is formally valid.
global $lng
Definition: privfeed.php:40
global $ilDB