ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups 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  public function __construct(ilObjUser $user, $id = 0)
43  {
44  global $ilDB;
45 
46  $this->db = $ilDB;
47  $this->user = $user;
48 
49  $this->mail_id = $id;
50  $this->user_id = $this->user->getId();
51 
52 
53  $this->read();
54  }
55 
56  public function insert()
57  {
58  $nextId = $this->db->nextId('addressbook_mlist');
59  $statement = $this->db->manipulateF('
60  INSERT INTO addressbook_mlist
61  ( ml_id,
62  user_id,
63  title,
64  description,
65  createdate,
66  changedate
67  )
68  VALUES(%s, %s, %s, %s, %s, %s)',
69  array( 'integer',
70  'integer',
71  'text',
72  'text',
73  'timestamp',
74  'timestamp'),
75  array( $nextId,
76  $this->getUserId(),
77  $this->getTitle(),
78  $this->getDescription(),
79  $this->getCreatedate(),
80  NULL
81  ));
82 
83  $this->mail_id = $nextId;
84 
85  return true;
86  }
87 
88  public function update()
89  {
90  if ($this->mail_id && $this->user_id)
91  {
92  $statement = $this->db->manipulateF('
93  UPDATE addressbook_mlist
94  SET title = %s,
95  description = %s,
96  changedate = %s
97  WHERE ml_id = %s
98  AND user_id = %s',
99  array( 'text',
100  'text',
101  'timestamp',
102  'integer',
103  'integer'
104  ),
105  array( $this->getTitle(),
106  $this->getDescription(),
107  $this->getChangedate(),
108  $this->getId(),
109  $this->getUserId()
110  ));
111 
112  return true;
113  }
114  else
115  {
116  return false;
117  }
118  }
119 
120  public function delete()
121  {
122  if ($this->mail_id && $this->user_id)
123  {
124  $this->deassignAllEntries();
125 
126  $statement = $this->db->manipulateF('
127  DELETE FROM addressbook_mlist
128  WHERE ml_id = %s
129  AND user_id = %s',
130  array('integer', 'integer'),
131  array($this->getId(), $this->getUserId()));
132 
133  return true;
134  }
135  else
136  {
137  return false;
138  }
139  }
140 
141  private function read()
142  {
143  if ($this->getId() && $this->getUserId())
144  {
145  $res = $this->db->queryf('
146  SELECT * FROM addressbook_mlist
147  WHERE ml_id = %s
148  AND user_id =%s',
149  array('integer', 'integer'),
150  array($this->getId(), $this->getUserId()));
151 
152  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
153 
154  if (is_object($row))
155  {
156  $this->setId($row->ml_id);
157  $this->setUserId($row->user_id);
158  $this->setTitle($row->title);
159  $this->setDescription($row->description);
160  $this->setCreatedate($row->createdate);
161  $this->setChangedate($row->changedae);
162  }
163  }
164 
165 
166  return true;
167  }
168 
169  public function getAssignedEntries()
170  {
171  $res = $this->db->queryf('
172  SELECT * FROM addressbook_mlist_ass
173  INNER JOIN addressbook ON addressbook.addr_id = addressbook_mlist_ass.addr_id
174  WHERE ml_id = %s',
175  array('integer'),
176  array($this->getId()));
177 
178  $entries = array();
179 
180  $counter = 0;
181  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
182  {
183  $entries[$counter] = array('a_id' => $row->a_id,
184  'addr_id' => $row->addr_id,
185  'login' => $row->login,
186  'email' => $row->email,
187  'firstname' => $row->firstname,
188  'lastname' => $row->lastname
189  );
190 
191  ++$counter;
192  }
193 
194  return $entries;
195  }
196 
197  public function assignAddressbookEntry($addr_id = 0)
198  {
199  $nextId = $this->db->nextId('addressbook_mlist_ass');
200  $statement = $this->db->manipulateF('
201  INSERT INTO addressbook_mlist_ass
202  ( a_id,
203  ml_id,
204  addr_id
205  )
206  VALUES(%s,%s,%s )',
207  array('integer', 'integer', 'integer'),
208  array($nextId, $this->getId(), $addr_id));
209 
210  return true;
211  }
212 
213  public function deassignAddressbookEntry($a_id = 0)
214  {
215 
216  $statement = $this->db->manipulateF('
217  DELETE FROM addressbook_mlist_ass
218  WHERE a_id = %s',
219  array('integer'),
220  array($a_id));
221 
222  return true;
223  }
224 
225  public function deassignAllEntries()
226  {
227  $statement = $this->db->manipulateF('
228  DELETE FROM addressbook_mlist_ass
229  WHERE ml_id = %s',
230  array('integer'),
231  array($this->getId()));
232 
233  return true;
234  }
235 
236  public function setId($a_mail_id = 0)
237  {
238  $this->mail_id = $a_mail_id;
239  }
240  public function getId()
241  {
242  return $this->mail_id;
243  }
244  public function setUserId($a_user_id = 0)
245  {
246  $this->user_id = $a_user_id;
247  }
248  public function getUserId()
249  {
250  return $this->user_id;
251  }
252  public function setTitle($a_title = '')
253  {
254  $this->title = $a_title;
255  }
256  public function getTitle()
257  {
258  return $this->title;
259  }
260  public function setDescription($a_description = '')
261  {
262  $this->description = $a_description;
263  }
264  public function getDescription()
265  {
266  return $this->description;
267  }
268  public function setCreatedate($_createdate = '0000-00-00 00:00:00')
269  {
270  $this->createdate = $_createdate;
271  }
272  public function getCreatedate()
273  {
274  return $this->createdate;
275  }
276  public function setChangedate($a_changedate = '0000-00-00 00:00:00')
277  {
278  if($a_changedate == '0000-00-00 00:00:00')
279  $this->changedate = NULL;
280  else
281  $this->changedate = $a_changedate;
282  }
283  public function getChangedate()
284  {
285  return $this->changedate;
286  }
287 
288  public static function _isOwner($a_ml_id, $a_usr_id)
289  {
290  global $ilDB;
291 
292  $res = $ilDB->queryf('
293  SELECT * FROM addressbook_mlist
294  WHERE ml_id = %s
295  AND user_id =%s',
296  array('integer', 'integer'),
297  array($a_ml_id, $a_usr_id));
298 
299  $row = $ilDB->fetchObject($res);
300 
301  return is_object($row) ? true : false;
302  }
303 }
304 ?>