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