3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
20 * Portions Copyright 2010 (c) Mélanie Le Bail
23 require_once 'common/dao/include/DataAccessObject.class.php';
26 * Data Access Object for mailing lists
28 class MailmanListDao extends DataAccessObject {
30 public function __construct($da) {
31 parent::__construct($da);
36 * Search active (=not deteted) mailing lists
37 * return all active lists
38 * @return DataAccessResult
40 function & searchAllActiveML() {
43 WHERE is_public IN (0,1)";
44 return $this->retrieve($sql,array());
48 * Searches by group_list_id
49 * @return DataAccessResult
51 function & searchByGroupListId($group_list_id) {
52 $group_list_id = $this->da->quoteSmart($group_list_id);
53 $sql = "SELECT * FROM mail_group_list
54 WHERE group_list_id = $1";
55 return $this->retrieve($sql,array($group_list_id));
58 * Searches by list_name
59 * @return DataAccessResult
61 function & searchByName($realListName) {
62 $realListName = $this->da->quoteSmart($realListName);
63 $sql = 'SELECT 1 FROM mail_group_list WHERE lower(list_name)=$1';
64 return $this->retrieve($sql,array($realListName));
67 * Searches by group_id
68 * @return DataAccessResult
70 function & searchByGroupId($group_id) {
71 $group_id = $this->da->quoteSmart($group_id);
72 $sql = "SELECT * FROM mail_group_list
73 WHERE group_id = $1 ORDER BY group_list_id";
74 return $this->retrieve($sql,array($group_id));
77 * Searches data with group_list_id and group_id
78 * @return DataAccessResult
80 function & searchListFromGroup($group_list_id,$group_id) {
81 $group_id = $this->da->quoteSmart($group_id);
82 $group_list_id = $this->da->quoteSmart($group_list_id);
83 $sql = "SELECT * FROM mail_group_list
84 WHERE group_id = $1 AND group_list_id=$2";
85 return $this->retrieve($sql,array($group_id,$group_list_id));
88 function & insertNewList($group_id, $realListName,$isPublic,$listPassword,$creator_id,$requested,$description) {
89 $group_id = $this->da->quoteSmart($group_id);
90 $realListName = $this->da->quoteSmart($realListName);
91 $isPublic = $this->da->quoteSmart($isPublic);
92 $creator_id = $this->da->quoteSmart($creator_id);
93 $requested = $this->da->quoteSmart($requested);
94 $listPassword = $this->da->quoteSmart($listPassword);
95 $description = $this->da->quoteSmart($description);
96 $sql = "INSERT INTO mail_group_list (group_id, list_name, is_public, password, list_admin, status, description) VALUES ($1,$2,$3,$4,$5,$6,$7);";
97 return db_insertid($this->update($sql,array($group_id, $realListName,$isPublic,$listPassword,$creator_id,$requested,$description)),'mail_group_list','group_list_id');
99 function deleteList($group_id, $list_id) {
100 return $this->updateList($list_id,$group_id,"deleted",9,1);
103 function updateList($group_list_id,$group_id, $description, $isPublic,$status) {
104 $group_id = $this->da->quoteSmart($group_id);
105 $group_list_id = $this->da->quoteSmart($group_list_id);
106 $isPublic = $this->da->quoteSmart($isPublic);
107 $status = $this->da->quoteSmart($status);
108 $description = $this->da->quoteSmart($description);
109 $sql = "UPDATE mail_group_list SET is_public=$1, description=$2," .
110 "status=$3 WHERE group_list_id=$4 AND group_id=$5;";
111 return $this->update($sql,array($isPublic,$description,$status,$group_list_id,$group_id));
115 function newSubscriber($usermail, $username, $userpasswd, $listname) {
116 $usermail = $this->da->quoteSmart($usermail);
117 $username = $this->da->quoteSmart($username);
118 $userpasswd = $this->da->quoteSmart($userpasswd);
119 $listname = $this->da->quoteSmart($listname);
120 $sql="INSERT INTO plugin_mailman (address,password,name,listname) VALUES ($1,$2,$3,$4);";
121 return $this->update($sql,array($usermail,$userpasswd,$username,$listname));
124 function deleteSubscriber($usermail, $listname) {
125 $usermail = $this->da->quoteSmart($usermail);
126 $listname = $this->da->quoteSmart($listname);
127 $sql="DELETE FROM plugin_mailman WHERE listname=$1 AND address=$2;";
128 return $this->update($sql,array($listname,$usermail));
130 function & userIsMonitoring($usermail,$listname) {
131 $usermail = $this->da->quoteSmart($usermail);
132 $listname = $this->da->quoteSmart($listname);
133 $sql="SELECT count(*) AS count FROM plugin_mailman WHERE address=$1 AND listname=$2;";
134 return $this->retrieve($sql,array($usermail,$listname));
137 function & listsMonitoredByUser($usermail) {
138 $usermail = $this->da->quoteSmart($usermail);
139 $sql="SELECT groups.group_name,groups.group_id,mail_group_list.group_list_id,mail_group_list.list_name ".
140 "FROM groups,mail_group_list,plugin_mailman ".
141 "WHERE groups.group_id=mail_group_list.group_id AND groups.status ='A' ".
142 "AND mail_group_list.list_name=plugin_mailman.listname ".
143 "AND plugin_mailman.address=$1 ORDER BY group_name DESC";
145 return $this->retrieve($sql,array($usermail));
148 function & compareInfos($mail) {
149 $mail = $this->da->quoteSmart($mail);
150 $sql="SELECT password, name FROM plugin_mailman WHERE address=$1;";
151 return $this->retrieve($sql,array($mail));
154 function updateInfos($mail,$passwd,$name) {
155 $mail = $this->da->quoteSmart($mail);
156 $passwd = $this->da->quoteSmart($passwd);
157 $name = $this->da->quoteSmart($name);
158 $sql="UPDATE plugin_mailman SET password=$1, name=$2 WHERE address=$3;";
159 return $this->update($sql,array($passwd,$name,$mail));