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)) {
55 $this->setError(sprintf(_('%1$s:: No Valid Group Object'), 'MailingListFactory'));
58 if ($Group->isError()) {
59 $this->setError('MailingListFactory:: '.$Group->getErrorMessage());
62 if (!$Group->usesMail()) {
63 $this->setError(sprintf(_('%s does not use the Mailing-list tool'),
64 $Group->getPublicName()));
67 $this->Group =& $Group;
73 * getGroup - get the Group object this MailingListFactory is associated with.
75 * @return object The Group object.
77 function &getGroup() {
82 * getMailingLists - get an array of MailingList objects for this Group.
84 * @return array The array of MailingList objects.
86 function getMailingLists() {
87 if (isset($this->mailingLists) && is_array($this->mailingLists)) {
88 return $this->mailingLists;
91 $public_flag = MAIL__MAILING_LIST_IS_PUBLIC;
93 if (session_loggedin()) {
94 $perm = $this->Group->getPermission();
95 if ($perm && is_object($perm) && $perm->isMember()) {
96 $public_flag = MAIL__MAILING_LIST_IS_PRIVATE.', '.MAIL__MAILING_LIST_IS_PUBLIC;
100 $result = db_query_params ('SELECT * FROM mail_group_list WHERE group_id=$1 AND is_public = ANY ($2) ORDER BY list_name',
101 array ($this->Group->getID(),
102 db_int_array_to_any_clause (array (MAIL__MAILING_LIST_IS_PRIVATE,
103 MAIL__MAILING_LIST_IS_PUBLIC)))) ;
106 $this->setError(sprintf(_('Error Getting %1$s'), _('Error Getting %1$s')).db_error());
109 $this->mailingLists = array();
110 while ($arr = db_fetch_array($result)) {
111 $this->mailingLists[] = new MailingList($this->Group, $arr['group_list_id'], $arr);
114 return $this->mailingLists;
120 // c-file-style: "bsd"