3 * FusionForge mailing lists
5 * Copyright 2002, Tim Perdue/GForge, LLC
6 * Copyright 2003, Guillaume Smet
7 * Copyright 2009, Roland Mas
8 * Copyright 2013, Franck Villaume - TrivialDev
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'include/Error.class.php';
27 require_once $gfcommon.'mail/MailingList.class.php';
29 class MailingListFactory extends Error {
39 * The mailing lists array.
41 * @var array $mailingLists.
49 * @param Group $Group The Group object to which these mailing lists are associated.
51 function MailingListFactory(& $Group) {
54 if (!$Group || !is_object($Group)) {
57 if ($Group->isError()) {
58 $this->setError('MailingListFactory:: '.$Group->getErrorMessage());
61 if (!$Group->usesMail()) {
62 $this->setError(sprintf(_('%s does not use the Mailing-list tool'),
63 $Group->getPublicName()));
66 $this->Group =& $Group;
72 * getGroup - get the Group object this MailingListFactory is associated with.
74 * @return object The Group object.
76 function &getGroup() {
81 * getMailingLists - get an array of MailingList objects for this Group.
83 * @return array The array of MailingList objects.
85 function getMailingLists() {
86 if (isset($this->mailingLists) && is_array($this->mailingLists)) {
87 return $this->mailingLists;
90 $public_flag = MAIL__MAILING_LIST_IS_PUBLIC;
92 if (session_loggedin()) {
93 $perm = $this->Group->getPermission();
94 if ($perm && is_object($perm) && $perm->isMember()) {
95 $public_flag = MAIL__MAILING_LIST_IS_PRIVATE.', '.MAIL__MAILING_LIST_IS_PUBLIC;
99 $result = db_query_params ('SELECT * FROM mail_group_list WHERE group_id=$1 AND is_public = ANY ($2) ORDER BY list_name',
100 array ($this->Group->getID(),
101 db_int_array_to_any_clause (array (MAIL__MAILING_LIST_IS_PRIVATE,
102 MAIL__MAILING_LIST_IS_PUBLIC)))) ;
105 $this->setError(sprintf(_('Error Getting %1$s'), _('Error Getting %1$s')).db_error());
108 $this->mailingLists = array();
109 while ($arr = db_fetch_array($result)) {
110 $this->mailingLists[] = new MailingList($this->Group, $arr['group_list_id'], $arr);
113 return $this->mailingLists;
119 // c-file-style: "bsd"