ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
37 
38  $ilDB = $DIC['ilDB'];
39 
40  $query = 'DELETE FROM cal_notification ' .
41  'WHERE user_id = ' . $ilDB->quote($a_usr_id, 'integer');
42  $res = $ilDB->manipulate($query);
43  return true;
44  }
45 
52  public static function deleteCalendarEntry($a_cal_id)
53  {
54  global $DIC;
55 
56  $ilDB = $DIC['ilDB'];
57 
58  $query = 'DELETE FROM cal_notification ' .
59  'WHERE cal_id = ' . $ilDB->quote($a_cal_id, 'integer');
60  $res = $ilDB->manipulate($query);
61  return true;
62  }
63 
68  public function setEntryId($a_id)
69  {
70  $this->cal_id = $a_id;
71  }
72 
76  public function getEntryId()
77  {
78  return $this->cal_id;
79  }
80 
81  public function getRecipients()
82  {
83  return (array) $this->rcps;
84  }
85 
86  public function validate()
87  {
88  global $DIC;
89 
90  $ilErr = $DIC['ilErr'];
91  $lng = $DIC['lng'];
92 
93  if (!count($this->getRecipients())) {
94  return true;
95  }
96  foreach ((array) $this->getRecipients() as $rcp_data) {
97  if ($rcp_data['type'] == self::TYPE_USER) {
98  continue;
99  } else {
100  if (!ilUtil::is_email($rcp_data['email'])) {
101  $ilErr->appendMessage($lng->txt('cal_err_invalid_notification_rcps'));
102  return false;
103  }
104  }
105  }
106  return true;
107  }
108 
112  public function save()
113  {
114  global $DIC;
115 
116  $ilDB = $DIC['ilDB'];
117 
118  $this->deleteRecipients();
119 
120  foreach ($this->getRecipients() as $rcp) {
121  $query = 'INSERT INTO cal_notification ' .
122  '(notification_id,cal_id, user_type, user_id, email) ' .
123  'VALUES ( ' .
124  $ilDB->quote($ilDB->nextId('cal_notification'), 'integer') . ', ' .
125  $ilDB->quote((int) $this->getEntryId(), 'integer') . ', ' .
126  $ilDB->quote((int) $rcp['type'], 'integer') . ', ' .
127  $ilDB->quote((int) $rcp['usr_id'], 'integer') . ', ' .
128  $ilDB->quote($rcp['email'], 'text') .
129  ')';
130  $ilDB->manipulate($query);
131  }
132  return true;
133  }
134 
141  public function addRecipient($a_type, $a_usr_id = 0, $a_email = '')
142  {
143  $this->rcps[] = array(
144  'type' => $a_type,
145  'usr_id' => $a_usr_id,
146  'email' => $a_email
147  );
148  }
149 
154  public function setRecipients($a_rcps)
155  {
156  $this->rcps = array();
157  }
158 
164  public function deleteRecipients()
165  {
166  global $DIC;
167 
168  $ilDB = $DIC['ilDB'];
169 
170  $query = 'DELETE FROM cal_notification ' .
171  'WHERE cal_id = ' . $ilDB->quote($this->getEntryId(), 'integer');
172  $res = $ilDB->manipulate($query);
173  return true;
174  }
175 
176 
177 
182  protected function read()
183  {
184  global $DIC;
185 
186  $ilDB = $DIC['ilDB'];
187 
188  if (!$this->getEntryId()) {
189  return true;
190  }
191 
192  $query = 'SELECT * FROM cal_notification ' .
193  'WHERE cal_id = ' . $ilDB->quote($this->getEntryId(), 'integer');
194  $res = $ilDB->query($query);
195 
196  $this->rcps = array();
197  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
198  $this->addRecipient(
199  $row->user_type,
200  $row->user_id,
201  $row->email
202  );
203  }
204  }
205 
206  // Create table (not merged into into 4.3)
207  public static function createTable()
208  {
209  global $DIC;
210 
211  $ilDB = $DIC['ilDB'];
212 
213  if ($ilDB->tableExists('cal_notification')) {
214  return true;
215  }
216 
217  // Create notification table
218  $ilDB->createTable(
219  'cal_notification',
220  array(
221  'notification_id' => array('type' => 'integer','length' => 4,'notnull' => true),
222  'cal_id' => array('type' => 'integer','length' => 4, 'notnull' => true, 'default' => 0),
223  'user_type' => array('type' => 'integer','length' => 1, 'notnull' => true, 'default' => 0),
224  'user_id' => array('type' => 'integer','length' => 4, 'notnull' => true, 'default' => 0),
225  'email' => array('type' => 'text','length' => 64, 'notnull' => false)
226  )
227  );
228  $ilDB->addPrimaryKey(
229  'cal_notification',
230  array(
231  'notification_id'
232  )
233  );
234  $ilDB->createSequence('cal_notification');
235  $ilDB->addIndex('cal_notification', array('cal_id'), 'i1');
236  }
237 }
addRecipient($a_type, $a_usr_id=0, $a_email='')
Add recipient.
global $DIC
Definition: saml.php:7
static is_email($a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
setEntryId($a_id)
Set calendar entry id.
$ilErr
Definition: raiseError.php:18
$a_type
Definition: workflow.php:92
foreach($_POST as $key=> $value) $res
$lng
$query
static deleteUser($a_usr_id)
Delete a singel user ilDB $ilDB.
$row
global $ilDB
static deleteCalendarEntry($a_cal_id)
Delete notification for a calendar entry ilDB $ilDB.
deleteRecipients()
Delete all recipients ilDB $ilDB.
__construct($a_cal_id=0)
Init with calendar entry id.