3 * FusionForge project manager
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.'pm/ProjectGroup.class.php';
30 class ProjectGroupFactory extends Error {
40 * The projectGroups array.
42 * @var array projectGroups.
49 * @param object The Group object to which this ProjectGroupFactory is associated.
50 * @return boolean success.
52 function ProjectGroupFactory(&$Group) {
54 if (!$Group || !is_object($Group)) {
55 $this->setError('ProjectGroup:: No Valid Group Object');
58 if ($Group->isError()) {
59 $this->setError('ProjectGroup:: '.$Group->getErrorMessage());
62 $this->Group =& $Group;
68 * getGroup - get the Group object this ProjectGroupFactory is associated with.
70 * @return object The Group object.
72 function &getGroup() {
77 * getProjectGroups - get an array of ProjectGroup objects.
79 * @return array The array of ProjectGroups.
81 function &getProjectGroups() {
82 if ($this->projectGroups) {
83 return $this->projectGroups;
85 if (session_loggedin()) {
86 $perm =& $this->Group->getPermission( session_get_user() );
87 if (!$perm || !is_object($perm) || !$perm->isMember()) {
88 $result = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_id=$1 AND is_public=1 ORDER BY group_project_id',
89 array ($this->Group->getID())) ;
91 if ($perm->isPMAdmin()) {
92 $result = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_id=$1 AND is_public<3 ORDER BY group_project_id',
93 array ($this->Group->getID())) ;
95 $result = db_query_params ('SELECT * FROM project_group_list_vw
96 WHERE group_id=$1 AND is_public<3
97 AND group_project_id IN (SELECT role_setting.ref_id
98 FROM role_setting, user_group
99 WHERE role_setting.value::integer >= 0
100 AND role_setting.section_name = $2
101 AND role_setting.ref_id=project_group_list_vw.group_project_id
102 AND user_group.role_id = role_setting.role_id
103 AND user_group.user_id=$3
104 ORDER BY group_project_id',
105 array ($this->Group->getID(),
111 $result = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_id=$1 AND is_public=1 ORDER BY group_project_id',
112 array ($this->Group->getID())) ;
114 $rows = db_numrows($result);
116 if (!$result || $rows < 1) {
117 $this->setError(_('No ProjectGroups Found').db_error());
118 $this->projectGroups=NULL;
120 while ($arr = db_fetch_array($result)) {
121 $this->projectGroups[] = new ProjectGroup($this->Group, $arr['group_project_id'], $arr);
124 return $this->projectGroups;
131 // c-file-style: "bsd"