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
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 $description = $this->da->quoteSmart($description);
95 $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);";
96 return db_insertid($this->update($sql,array($group_id, $realListName,$isPublic,$listPassword,$creator_id,$requested,$description)),'mail_group_list','group_list_id');
98 function deleteList($group_id, $list_id) {
99 return $this->updateList($list_id,$group_id,"deleted",9,1);
102 function updateList($group_list_id,$group_id, $description, $isPublic,$status) {
103 $group_id = $this->da->quoteSmart($group_id);
104 $group_list_id = $this->da->quoteSmart($group_list_id);
105 $isPublic = $this->da->quoteSmart($isPublic);
106 $status = $this->da->quoteSmart($status);
107 $description = $this->da->quoteSmart($description);
108 $sql = "UPDATE mail_group_list SET is_public=$1, description=$2," .
109 "status=$3 WHERE group_list_id=$4 AND group_id=$5;";
110 return $this->update($sql,array($isPublic,$description,$status,$group_list_id,$group_id));
114 function & newSubscriber($usermail, $username, $userpasswd, $listname) {
115 $usermail = $this->da->quoteSmart($usermail);
116 $username = $this->da->quoteSmart($username);
117 $userpasswd = $this->da->quoteSmart($userpasswd);
118 $listname = $this->da->quoteSmart($listname);
119 $sql="INSERT INTO plugin_mailman (address,password,name,listname) VALUES ($1,$2,$3,$4);";
120 return $this->update($sql,array($usermail,$userpasswd,$username,$listname));
123 function & deleteSubscriber($usermail, $listname) {
124 $usermail = $this->da->quoteSmart($usermail);
125 $listname = $this->da->quoteSmart($listname);
126 $sql="DELETE FROM plugin_mailman WHERE listname=$1 AND address=$2;";
127 return $this->update($sql,array($listname,$usermail));
129 function & userIsMonitoring($usermail,$listname) {
130 $usermail = $this->da->quoteSmart($usermail);
131 $listname = $this->da->quoteSmart($listname);
132 $sql="SELECT count(*) AS count FROM plugin_mailman WHERE address=$1 AND listname=$2;";
133 return $this->retrieve($sql,array($usermail,$listname));
136 function & listsMonitoredByUser($usermail) {
137 $usermail = $this->da->quoteSmart($usermail);
138 $sql="SELECT groups.group_name,groups.group_id,mail_group_list.group_list_id,mail_group_list.list_name ".
139 "FROM groups,mail_group_list,plugin_mailman ".
140 "WHERE groups.group_id=mail_group_list.group_id AND groups.status ='A' ".
141 "AND mail_group_list.list_name=plugin_mailman.listname ".
142 "AND plugin_mailman.address=$1 ORDER BY group_name DESC";
144 return $this->retrieve($sql,array($usermail));
147 function & compareInfos($mail) {
148 $mail = $this->da->quoteSmart($mail);
149 $sql="SELECT password, name FROM plugin_mailman WHERE address=$1;";
150 return $this->retrieve($sql,array($mail));
153 function & updateInfos($mail,$passwd,$name) {
154 $mail = $this->da->quoteSmart($mail);
155 $passwd = $this->da->quoteSmart($passwd);
156 $name = $this->da->quoteSmart($name);
157 $sql="UPDATE plugin_mailman SET password=$1, name=$2 WHERE address=$3;";
158 return $this->update($sql,array($passwd,$name,$mail));