3 * FusionForge project manager
5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/GForge, LLC
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.'pm/ProjectGroup.class.php';
29 class ProjectGroupFactory extends Error {
39 * The projectGroups array.
41 * @var array projectGroups.
48 * @param Group $Group The Group object to which this ProjectGroupFactory is associated.
49 * @return \ProjectGroupFactory
51 function __construct(&$Group) {
53 if (!$Group || !is_object($Group)) {
54 $this->setError(_('No Valid Group Object'));
57 if ($Group->isError()) {
58 $this->setError('ProjectGroup:: '.$Group->getErrorMessage());
61 if (!$Group->usesPM()) {
62 $this->setError(sprintf(_('%s does not use the Project Management tool'),
63 $Group->getPublicName()));
66 $this->Group =& $Group;
70 * getGroup - get the Group object this ProjectGroupFactory is associated with.
72 * @return Group The Group object.
74 function &getGroup() {
78 function &getAllProjectGroupIds() {
80 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_id=$1 ORDER BY group_project_id',
81 array ($this->Group->getID())) ;
85 while ($arr = db_fetch_array($res)) {
86 $result[] = $arr['group_project_id'] ;
92 * getProjectGroups - get an array of ProjectGroup objects.
94 * @return ProjectGroups[] The array of ProjectGroups.
96 function getProjectGroups() {
97 if ($this->projectGroups) {
98 return $this->projectGroups;
101 $this->projectGroups = array () ;
102 $ids = $this->getAllProjectGroupIds() ;
104 foreach ($ids as $id) {
105 if (forge_check_perm ('pm', $id, 'read')) {
106 $this->projectGroups[] = new ProjectGroup($this->Group, $id);
109 return $this->projectGroups;
116 // c-file-style: "bsd"