5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/GForge, LLC
7 * Copyright 2009, Roland Mas
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 require_once $gfcommon.'include/Error.class.php';
28 require_once $gfcommon.'forum/Forum.class.php';
30 class ForumFactory extends Error {
49 * @param object The Group object to which this forum is associated.
51 function ForumFactory(&$Group) {
53 if (!$Group || !is_object($Group)) {
54 $this->setError(_('Forum:: No Valid Group Object'));
57 if ($Group->isError()) {
58 $this->setError(_('Forum').':: '.$Group->getErrorMessage());
61 $this->Group =& $Group;
67 * getGroup - get the Group object this ForumFactory is associated with.
69 * @return object The Group object.
71 function &getGroup() {
76 * getForums - get an array of Forum objects for this Group.
78 * @return array The array of Forum objects.
80 function &getForums() {
81 global $sys_database_type;
88 if ($sys_database_type == "mysql") {
89 if (session_loggedin()) {
90 $perm =& $this->Group->getPermission( session_get_user() );
91 if (!$perm || !is_object($perm) || !$perm->isMember()) {
96 if ($perm->isForumAdmin()) {
99 $exists=" AND group_forum_id IN (SELECT role_setting.ref_id
100 FROM role_setting, user_group
101 WHERE role_setting.value::integer >= 0
102 AND role_setting.section_name = 'forum'
103 AND role_setting.ref_id=forum_group_list_vw.group_forum_id
105 AND user_group.role_id = role_setting.role_id
106 AND user_group.user_id='".user_getid()."') ";
115 (SELECT count(*) AS `count`
117 SELECT DISTINCT group_forum_id, thread_id FROM forum
119 WHERE tmp.group_forum_id = fgl.group_forum_id
121 FROM forum_group_list_vw AS fgl
122 WHERE group_id='". $this->Group->getID() ."'
123 AND is_public $public_flag
125 ORDER BY group_forum_id;";
127 $result = db_query_mysql ($sql);
129 $rows = db_numrows($result);
132 $this->setError(_('Forum not found').' : '.db_error());
133 $this->forums = false;
135 while ($arr = db_fetch_array($result)) {
136 $this->forums[] = new Forum($this->Group, $arr['group_forum_id'], $arr);
139 return $this->forums;
140 } else { // Not MySQL
141 if (session_loggedin()) {
142 $perm =& $this->Group->getPermission( session_get_user() );
143 if (!$perm || !is_object($perm) || !$perm->isMember()) {
144 $result = db_query_params ('SELECT * FROM forum_group_list_vw
147 ORDER BY group_forum_id',
148 array ($this->Group->getID())) ;
151 if ($perm->isForumAdmin()) {
152 $result = db_query_params ('SELECT * FROM forum_group_list_vw
155 ORDER BY group_forum_id',
156 array ($this->Group->getID())) ;
158 $result = db_query_params ('SELECT * FROM forum_group_list_vw
161 AND group_forum_id IN (SELECT role_setting.ref_id
162 FROM role_setting, user_group
163 WHERE role_setting.section_name = $2
164 AND role_setting.value::integer >= 0
165 AND role_setting.ref_id=forum_group_list_vw.group_forum_id
166 AND user_group.role_id = role_setting.role_id
167 AND user_group.user_id=$3)
168 ORDER BY group_forum_id',
169 array ($this->Group->getID(),
175 $result = db_query_params ('SELECT * FROM forum_group_list_vw
178 ORDER BY group_forum_id',
179 array ($this->Group->getID())) ;
182 $rows = db_numrows($result);
185 $this->setError(_('Forum not found').' : '.db_error());
186 $this->forums = false;
188 while ($arr = db_fetch_array($result)) {
189 $this->forums[] = new Forum($this->Group, $arr['group_forum_id'], $arr);
192 return $this->forums;
198 * getForumsAdmin - get an array of all (public, private and suspended) Forum objects for this Group.
200 * @return array The array of Forum objects.
202 function &getForumsAdmin() {
203 global $sys_database_type;
206 return $this->forums;
210 if ($sys_database_type == "mysql") {
211 if (session_loggedin()) {
212 $perm =& $this->Group->getPermission( session_get_user() );
213 if (!$perm || !is_object($perm) || !$perm->isForumAdmin()) {
214 $this->setError(_("You don't have a permission to access this page"));
215 $this->forums = false;
218 (SELECT count(*) AS `count`
220 SELECT DISTINCT group_forum_id, thread_id FROM forum
222 WHERE tmp.group_forum_id = fgl.group_forum_id
224 FROM forum_group_list_vw AS fgl
225 WHERE group_id='". $this->Group->getID() . "'
226 ORDER BY group_forum_id;";
228 $result = db_query_mysql ($sql);
230 $rows = db_numrows($result);
233 $this->setError(_('Forum not found').' : '.db_error());
234 $this->forums = false;
236 while ($arr = db_fetch_array($result)) {
237 $this->forums[] = new Forum($this->Group, $arr['group_forum_id'], $arr);
242 $this->setError(_("You don't have a permission to access this page"));
243 $this->forums = false;
246 return $this->forums;
248 } else { // Not MySQL
249 if (session_loggedin()) {
250 $perm =& $this->Group->getPermission( session_get_user() );
251 if (!$perm || !is_object($perm) || !$perm->isForumAdmin()) {
252 $this->setError(_("You don't have a permission to access this page"));
253 $this->forums = false;
255 $result = db_query_params ('SELECT * FROM forum_group_list_vw
257 ORDER BY group_forum_id',
258 array ($this->Group->getID())) ;
261 $this->setError(_("You don't have a permission to access this page"));
262 $this->forums = false;
265 $rows = db_numrows($result);
268 $this->setError(_('Forum not found').' : '.db_error());
269 $this->forums = false;
271 while ($arr = db_fetch_array($result)) {
272 $this->forums[] = new Forum($this->Group, $arr['group_forum_id'], $arr);
275 return $this->forums;
282 // c-file-style: "bsd"