ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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  if($this->getMode() == self::MODE_ADDRESSBOOK)
183  {
184  $res = $this->db->queryf('
185  SELECT * FROM addressbook_mlist_ass
186  INNER JOIN addressbook ON addressbook.addr_id = addressbook_mlist_ass.addr_id
187  WHERE ml_id = %s',
188  array('integer'),
189  array($this->getId()));
190  }
191  else
192  {
193  $res = $this->db->queryf('
194  SELECT * FROM addressbook_mlist_ass
195  INNER JOIN usr_data ON addressbook_mlist_ass.addr_id = usr_data.usr_id
196  WHERE ml_id = %s',
197  array('integer'),
198  array($this->getId()));
199  }
200 
201  $entries = array();
202 
203  $counter = 0;
204  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
205  {
206  $entries[$counter] = array('a_id' => $row->a_id,
207  'addr_id' => $row->addr_id,
208  'login' => $row->login,
209  'email' => $row->email,
210  'firstname' => $row->firstname,
211  'lastname' => $row->lastname
212  );
213 
214  ++$counter;
215  }
216 
217  return $entries;
218  }
219 
220  public function assignAddressbookEntry($addr_id = 0)
221  {
222  $nextId = $this->db->nextId('addressbook_mlist_ass');
223  $statement = $this->db->manipulateF('
224  INSERT INTO addressbook_mlist_ass
225  ( a_id,
226  ml_id,
227  addr_id
228  )
229  VALUES(%s,%s,%s )',
230  array('integer', 'integer', 'integer'),
231  array($nextId, $this->getId(), $addr_id));
232 
233  return true;
234  }
235 
236  public function deassignAddressbookEntry($a_id = 0)
237  {
238 
239  $statement = $this->db->manipulateF('
240  DELETE FROM addressbook_mlist_ass
241  WHERE a_id = %s',
242  array('integer'),
243  array($a_id));
244 
245  return true;
246  }
247 
248  public function deassignAllEntries()
249  {
250  $statement = $this->db->manipulateF('
251  DELETE FROM addressbook_mlist_ass
252  WHERE ml_id = %s',
253  array('integer'),
254  array($this->getId()));
255 
256  return true;
257  }
258 
259  public function setId($a_mail_id = 0)
260  {
261  $this->mail_id = $a_mail_id;
262  }
263  public function getId()
264  {
265  return $this->mail_id;
266  }
267  public function setUserId($a_user_id = 0)
268  {
269  $this->user_id = $a_user_id;
270  }
271  public function getUserId()
272  {
273  return $this->user_id;
274  }
275  public function setTitle($a_title = '')
276  {
277  $this->title = $a_title;
278  }
279  public function getTitle()
280  {
281  return $this->title;
282  }
283  public function setDescription($a_description = '')
284  {
285  $this->description = $a_description;
286  }
287  public function getDescription()
288  {
289  return $this->description;
290  }
291  public function setCreatedate($_createdate = '0000-00-00 00:00:00')
292  {
293  $this->createdate = $_createdate;
294  }
295  public function getCreatedate()
296  {
297  return $this->createdate;
298  }
299  public function setChangedate($a_changedate = '0000-00-00 00:00:00')
300  {
301  if($a_changedate == '0000-00-00 00:00:00')
302  $this->changedate = NULL;
303  else
304  $this->changedate = $a_changedate;
305  }
306  public function getChangedate()
307  {
308  return $this->changedate;
309  }
310 
311  public static function _isOwner($a_ml_id, $a_usr_id)
312  {
313  global $ilDB;
314 
315  $res = $ilDB->queryf('
316  SELECT * FROM addressbook_mlist
317  WHERE ml_id = %s
318  AND user_id =%s',
319  array('integer', 'integer'),
320  array($a_ml_id, $a_usr_id));
321 
322  $row = $ilDB->fetchObject($res);
323 
324  return is_object($row) ? true : false;
325  }
326 
327  public function setMode($a_mode)
328  {
329  $a_mode = (int)$a_mode;
330  if(in_array($a_mode, array(self::MODE_ADDRESSBOOK, self::MODE_TEMPORARY)))
331  {
332  $this->mode = (int)$a_mode;
333  }
334  }
335 
336  public function getMode()
337  {
338  return $this->mode;
339  }
340 }
341 ?>
static _isOwner($a_ml_id, $a_usr_id)
setTitle($a_title='')
assignAddressbookEntry($addr_id=0)
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
deassignAddressbookEntry($a_id=0)
__construct(ilObjUser $user, $id=0)