ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailingLists.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 
24 require_once "Services/Contact/classes/class.ilMailingList.php";
25 
33 {
34  private $db = null;
35  private $user = null;
36  private $ml = null;
37 
38  public function __construct(ilObjUser $a_user)
39  {
40  global $ilDB;
41 
42  $this->db = $ilDB;
43  $this->user = $a_user;
44  }
45 
46  public function get($id = 0)
47  {
48  return new ilMailingList($this->user, $id);
49  }
50 
51  public function getSelected($a_ids = array())
52  {
53  $entries = array();
54 
55  if (is_array($a_ids) && !empty($a_ids))
56  {
57  $counter = 0;
58  while($id = @array_pop($a_ids))
59  {
60  $entries[$counter] = new ilMailingList($this->user, $id);
61 
62  ++$counter;
63  }
64  }
65 
66  return $entries;
67  }
68 
69  public function getAll()
70  {
71  $res = $this->db->queryf('
72  SELECT * FROM addressbook_mlist
73  WHERE user_id = %s',
74  array('integer'), array($this->user->getId()));
75 
76  $entries = array();
77 
78  $counter = 0;
79  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
80  {
81  $tmpObj = new ilMailingList($this->user, 0);
82  $tmpObj->setId($row->ml_id);
83  $tmpObj->setUserId($row->user_id);
84  $tmpObj->setTitle($row->title);
85  $tmpObj->setDescription($row->description);
86  $tmpObj->setCreatedate($row->createdate);
87  $tmpObj->setChangedate($row->changedae);
88 
89  $entries[$counter] = $tmpObj;
90 
91  unset($tmpObj);
92 
93  ++$counter;
94  }
95 
96  return $entries;
97  }
98 
99  public function mailingListExists($a_list_name)
100  {
101  $ml_id = substr($a_list_name, strrpos($a_list_name, '_') + 1);
102 
103  if (!is_numeric($ml_id) || $ml_id <= 0)
104  {
105  return false;
106  }
107  else
108  {
109  $this->setCurrentMailingList($ml_id);
110  if ($this->getCurrentMailingList()->getCreateDate() == '0000-00-00 00:00:00') return false;
111  }
112 
113  return true;
114  }
115 
116  public function setCurrentMailingList($id = 0)
117  {
118  $this->ml = $this->get($id);
119  }
120  public function getCurrentMailingList()
121  {
122  return $this->ml;
123  }
124 }
125 ?>