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 object The Group object to which this ProjectGroupFactory is associated.
49 * @return boolean success.
51 function ProjectGroupFactory(&$Group) {
53 if (!$Group || !is_object($Group)) {
54 $this->setError('ProjectGroup:: 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;
72 * getGroup - get the Group object this ProjectGroupFactory is associated with.
74 * @return object The Group object.
76 function &getGroup() {
80 function &getAllProjectGroupIds() {
82 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_id=$1 ORDER BY group_project_id',
83 array ($this->Group->getID())) ;
87 while ($arr = db_fetch_array($res)) {
88 $result[] = $arr['group_project_id'] ;
94 * getProjectGroups - get an array of ProjectGroup objects.
96 * @return array The array of ProjectGroups.
98 function getProjectGroups() {
99 if ($this->projectGroups) {
100 return $this->projectGroups;
103 $this->projectGroups = array () ;
104 $ids = $this->getAllProjectGroupIds() ;
106 foreach ($ids as $id) {
107 if (forge_check_perm ('pm', $id, 'read')) {
108 $this->projectGroups[] = new ProjectGroup($this->Group, $id);
111 return $this->projectGroups;
118 // c-file-style: "bsd"