ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMailingList.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 
31 {
32  private $mail_id = 0;
33  private $user_id = 0;
34  private $title = '';
35  private $description = '';
36  private $createdate = null;
37  private $changedate = null;
38 
42  private $user;
43 
47  private $db;
48 
49  const MODE_ADDRESSBOOK = 1;
50  const MODE_TEMPORARY = 2;
51 
52  public function __construct(ilObjUser $user, $id = 0)
53  {
54  global $DIC;
55 
56  $this->db = $DIC['ilDB'];
57  $this->user = $user;
58 
59  $this->mail_id = $id;
60  $this->user_id = $this->user->getId();
61 
62  $this->setMode(self::MODE_ADDRESSBOOK);
63 
64  $this->read();
65  }
66 
67  public function insert()
68  {
69  $nextId = $this->db->nextId('addressbook_mlist');
70  $statement = $this->db->manipulateF(
71  '
72  INSERT INTO addressbook_mlist
73  ( ml_id,
74  user_id,
75  title,
76  description,
77  createdate,
78  changedate,
79  lmode
80  )
81  VALUES(%s, %s, %s, %s, %s, %s, %s)',
82  array( 'integer',
83  'integer',
84  'text',
85  'text',
86  'timestamp',
87  'timestamp',
88  'integer'),
89  array( $nextId,
90  $this->getUserId(),
91  $this->getTitle(),
92  $this->getDescription(),
93  $this->getCreatedate(),
94  null,
95  $this->getMode()
96  )
97  );
98 
99  $this->mail_id = $nextId;
100 
101  return true;
102  }
103 
104  public function update()
105  {
106  if ($this->mail_id && $this->user_id) {
107  $statement = $this->db->manipulateF(
108  '
109  UPDATE addressbook_mlist
110  SET title = %s,
111  description = %s,
112  changedate = %s,
113  lmode = %s
114  WHERE ml_id = %s
115  AND user_id = %s',
116  array( 'text',
117  'text',
118  'timestamp',
119  'integer',
120  'integer',
121  'integer'
122  ),
123  array( $this->getTitle(),
124  $this->getDescription(),
125  $this->getChangedate(),
126  $this->getMode(),
127  $this->getId(),
128  $this->getUserId()
129  )
130  );
131 
132  return true;
133  } else {
134  return false;
135  }
136  }
137 
138  public function delete()
139  {
140  if ($this->mail_id && $this->user_id) {
141  $this->deassignAllEntries();
142 
143  $statement = $this->db->manipulateF(
144  '
145  DELETE FROM addressbook_mlist
146  WHERE ml_id = %s
147  AND user_id = %s',
148  array('integer', 'integer'),
149  array($this->getId(), $this->getUserId())
150  );
151 
152  return true;
153  } else {
154  return false;
155  }
156  }
157 
158  private function read()
159  {
160  if ($this->getId() && $this->getUserId()) {
161  $res = $this->db->queryf(
162  '
163  SELECT * FROM addressbook_mlist
164  WHERE ml_id = %s
165  AND user_id =%s',
166  array('integer', 'integer'),
167  array($this->getId(), $this->getUserId())
168  );
169 
171 
172  if (is_object($row)) {
173  $this->setId($row->ml_id);
174  $this->setUserId($row->user_id);
175  $this->setTitle($row->title);
176  $this->setDescription($row->description);
177  $this->setCreatedate($row->createdate);
178  $this->setChangedate($row->changedae);
179  $this->setMode($row->lmode);
180  }
181  }
182 
183 
184  return true;
185  }
186 
187  public function getAssignedEntries()
188  {
189  $res = $this->db->queryf(
190  'SELECT a_id, usr_data.usr_id FROM addressbook_mlist_ass INNER JOIN usr_data ON usr_data.usr_id = addressbook_mlist_ass.usr_id WHERE ml_id = %s',
191  array('integer'),
192  array($this->getId())
193  );
194 
195  $entries = array();
196  $counter = 0;
197  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
198  $entries[$row->a_id] = array(
199  'a_id' => $row->a_id,
200  'usr_id' => $row->usr_id
201  );
202  ++$counter;
203  }
204 
205  return $entries;
206  }
207 
212  public function assignUser($usr_id = 0)
213  {
214  $nextId = $this->db->nextId('addressbook_mlist_ass');
215  $this->db->manipulateF(
216  'INSERT INTO addressbook_mlist_ass (a_id, ml_id, usr_id) VALUES(%s, %s, %s)',
217  array('integer', 'integer', 'integer'),
218  array($nextId, $this->getId(), $usr_id)
219  );
220  return true;
221  }
222 
227  public function deleteEntry($a_id = 0)
228  {
229  $this->db->manipulateF(
230  'DELETE FROM addressbook_mlist_ass WHERE a_id = %s',
231  array('integer'),
232  array($a_id)
233  );
234  return true;
235  }
236 
240  public function deassignAllEntries()
241  {
242  $this->db->manipulateF(
243  'DELETE FROM addressbook_mlist_ass WHERE ml_id = %s',
244  array('integer'),
245  array($this->getId())
246  );
247  return true;
248  }
249 
250  public function setId($a_mail_id = 0)
251  {
252  $this->mail_id = $a_mail_id;
253  }
254  public function getId()
255  {
256  return $this->mail_id;
257  }
258  public function setUserId($a_user_id = 0)
259  {
260  $this->user_id = $a_user_id;
261  }
262  public function getUserId()
263  {
264  return $this->user_id;
265  }
266  public function setTitle($a_title = '')
267  {
268  $this->title = $a_title;
269  }
270  public function getTitle()
271  {
272  return $this->title;
273  }
274  public function setDescription($a_description = '')
275  {
276  $this->description = $a_description;
277  }
278  public function getDescription()
279  {
280  return $this->description;
281  }
282  public function setCreatedate($_createdate)
283  {
284  $this->createdate = $_createdate;
285  }
286  public function getCreatedate()
287  {
288  return $this->createdate;
289  }
290  public function setChangedate($a_changedate)
291  {
292  $this->changedate = $a_changedate;
293  }
294  public function getChangedate()
295  {
296  return $this->changedate;
297  }
298 
299  public static function _isOwner($a_ml_id, $a_usr_id)
300  {
302  global $DIC;
303  $ilDB = $DIC['ilDB'];
304 
305  $res = $ilDB->queryf(
306  'SELECT * FROM addressbook_mlist WHERE ml_id = %s AND user_id =%s',
307  array('integer', 'integer'),
308  array($a_ml_id, $a_usr_id)
309  );
310  $row = $ilDB->fetchObject($res);
311 
312  return is_object($row) ? true : false;
313  }
314 
315  public function setMode($a_mode)
316  {
317  $a_mode = (int) $a_mode;
318  if (in_array($a_mode, array(self::MODE_ADDRESSBOOK, self::MODE_TEMPORARY))) {
319  $this->mode = (int) $a_mode;
320  }
321  }
322 
323  public function getMode()
324  {
325  return $this->mode;
326  }
327 
331  public static function removeAssignmentsByUserId($usr_id)
332  {
334  global $DIC;
335  $ilDB = $DIC['ilDB'];
336 
337  $ilDB->manipulate('DELETE FROM addressbook_mlist_ass WHERE usr_id = ' . $ilDB->quote($usr_id, 'integer'));
338  }
339 }
setTitle($a_title='')
global $DIC
Definition: saml.php:7
setDescription($a_description='')
if(!array_key_exists('StateId', $_REQUEST)) $id
setId($a_mail_id=0)
setUserId($a_user_id=0)
user()
Definition: user.php:4
setCreatedate($_createdate)
foreach($_POST as $key=> $value) $res
setChangedate($a_changedate)
$row
global $ilDB
__construct(ilObjUser $user, $id=0)