ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  INSERT INTO addressbook_mlist
72  ( ml_id,
73  user_id,
74  title,
75  description,
76  createdate,
77  changedate,
78  lmode
79  )
80  VALUES(%s, %s, %s, %s, %s, %s, %s)',
81  array( 'integer',
82  'integer',
83  'text',
84  'text',
85  'timestamp',
86  'timestamp',
87  'integer'),
88  array( $nextId,
89  $this->getUserId(),
90  $this->getTitle(),
91  $this->getDescription(),
92  $this->getCreatedate(),
93  NULL,
94  $this->getMode()
95  ));
96 
97  $this->mail_id = $nextId;
98 
99  return true;
100  }
101 
102  public function update()
103  {
104  if ($this->mail_id && $this->user_id)
105  {
106  $statement = $this->db->manipulateF('
107  UPDATE addressbook_mlist
108  SET title = %s,
109  description = %s,
110  changedate = %s,
111  lmode = %s
112  WHERE ml_id = %s
113  AND user_id = %s',
114  array( 'text',
115  'text',
116  'timestamp',
117  'integer',
118  'integer',
119  'integer'
120  ),
121  array( $this->getTitle(),
122  $this->getDescription(),
123  $this->getChangedate(),
124  $this->getMode(),
125  $this->getId(),
126  $this->getUserId()
127  ));
128 
129  return true;
130  }
131  else
132  {
133  return false;
134  }
135  }
136 
137  public function delete()
138  {
139  if ($this->mail_id && $this->user_id)
140  {
141  $this->deassignAllEntries();
142 
143  $statement = $this->db->manipulateF('
144  DELETE FROM addressbook_mlist
145  WHERE ml_id = %s
146  AND user_id = %s',
147  array('integer', 'integer'),
148  array($this->getId(), $this->getUserId()));
149 
150  return true;
151  }
152  else
153  {
154  return false;
155  }
156  }
157 
158  private function read()
159  {
160  if ($this->getId() && $this->getUserId())
161  {
162  $res = $this->db->queryf('
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 
170 
171  if (is_object($row))
172  {
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  {
199  $entries[$row->a_id] = array(
200  'a_id' => $row->a_id,
201  'usr_id' => $row->usr_id
202  );
203  ++$counter;
204  }
205 
206  return $entries;
207  }
208 
213  public function assignUser($usr_id = 0)
214  {
215  $nextId = $this->db->nextId('addressbook_mlist_ass');
216  $this->db->manipulateF(
217  'INSERT INTO addressbook_mlist_ass (a_id, ml_id, usr_id) VALUES(%s, %s, %s)',
218  array('integer', 'integer', 'integer'),
219  array($nextId, $this->getId(), $usr_id)
220  );
221  return true;
222  }
223 
228  public function deleteEntry($a_id = 0)
229  {
230  $this->db->manipulateF(
231  'DELETE FROM addressbook_mlist_ass WHERE a_id = %s',
232  array('integer'),
233  array($a_id)
234  );
235  return true;
236  }
237 
241  public function deassignAllEntries()
242  {
243  $this->db->manipulateF(
244  'DELETE FROM addressbook_mlist_ass WHERE ml_id = %s',
245  array('integer'),
246  array($this->getId())
247  );
248  return true;
249  }
250 
251  public function setId($a_mail_id = 0)
252  {
253  $this->mail_id = $a_mail_id;
254  }
255  public function getId()
256  {
257  return $this->mail_id;
258  }
259  public function setUserId($a_user_id = 0)
260  {
261  $this->user_id = $a_user_id;
262  }
263  public function getUserId()
264  {
265  return $this->user_id;
266  }
267  public function setTitle($a_title = '')
268  {
269  $this->title = $a_title;
270  }
271  public function getTitle()
272  {
273  return $this->title;
274  }
275  public function setDescription($a_description = '')
276  {
277  $this->description = $a_description;
278  }
279  public function getDescription()
280  {
281  return $this->description;
282  }
283  public function setCreatedate($_createdate)
284  {
285  $this->createdate = $_createdate;
286  }
287  public function getCreatedate()
288  {
289  return $this->createdate;
290  }
291  public function setChangedate($a_changedate)
292  {
293  $this->changedate = $a_changedate;
294  }
295  public function getChangedate()
296  {
297  return $this->changedate;
298  }
299 
300  public static function _isOwner($a_ml_id, $a_usr_id)
301  {
303  global $DIC;
304  $ilDB = $DIC['ilDB'];
305 
306  $res = $ilDB->queryf(
307  'SELECT * FROM addressbook_mlist WHERE ml_id = %s AND user_id =%s',
308  array('integer', 'integer'),
309  array($a_ml_id, $a_usr_id)
310  );
311  $row = $ilDB->fetchObject($res);
312 
313  return is_object($row) ? true : false;
314  }
315 
316  public function setMode($a_mode)
317  {
318  $a_mode = (int)$a_mode;
319  if(in_array($a_mode, array(self::MODE_ADDRESSBOOK, self::MODE_TEMPORARY)))
320  {
321  $this->mode = (int)$a_mode;
322  }
323  }
324 
325  public function getMode()
326  {
327  return $this->mode;
328  }
329 
333  public static function removeAssignmentsByUserId($usr_id)
334  {
336  global $DIC;
337  $ilDB = $DIC['ilDB'];
338 
339  $ilDB->manipulate('DELETE FROM addressbook_mlist_ass WHERE usr_id = ' . $ilDB->quote($usr_id, 'integer'));
340  }
341 }
setTitle($a_title='')
setDescription($a_description='')
setId($a_mail_id=0)
setUserId($a_user_id=0)
user()
Definition: user.php:4
setCreatedate($_createdate)
$counter
setChangedate($a_changedate)
Create styles array
The data for the language used.
global $ilDB
global $DIC
__construct(ilObjUser $user, $id=0)