3 * FusionForge document manager
5 * Copyright 2000, Quentin Cregan/Sourceforge
6 * Copyright 2002-2003, Tim Perdue/GForge, LLC
7 * Copyright 2009, Roland Mas
8 * Copyright 2010, Franck Villaume - Capgemini
9 * http://fusionforge.org
11 * This file is part of FusionForge.
13 * FusionForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published
15 * by the Free Software Foundation; either version 2 of the License,
16 * or (at your option) any later version.
18 * FusionForge is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with FusionForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 require_once $gfcommon.'include/Error.class.php';
35 class DocumentGroupFactory extends Error {
37 * This variable holds the document groups.
42 * This variable holds the document groups for reading them in nested form.
54 * @return boolean success.
56 function DocumentGroupFactory(&$Group) {
59 if (!$Group || !is_object($Group)) {
60 $this->setError(_('DocumentGroupFactory:: Invalid Project'));
63 if ($Group->isError()) {
64 $this->setError('DocumentGroupFactory::'.' '.$Group->getErrorMessage());
67 $this->Group =& $Group;
73 * getNested - Return an array of DocumentGroup objects arranged for nested views.
75 * @param int The stateid of DocumentGroup.
76 * @return array The array of DocumentGroup.
78 function &getNested($stateid = 1) {
79 if ($this->nested_groups) {
80 return $this->nested_groups;
83 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid=$2 ORDER BY groupname ASC',
84 array($this->Group->getID(), $stateid));
85 $rows = db_numrows($result);
88 $this->setError(_('No Document Directory Found').' '.db_error());
91 while ($arr = db_fetch_array($result)) {
92 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
96 // Build the nested array
97 $count = count($this->flat_groups);
98 for ($i=0; $i < $count; $i++) {
99 $this->nested_groups["".$this->flat_groups[$i]->getParentID()][] =& $this->flat_groups[$i];
102 return $this->nested_groups;
106 * getDocumentGroups - Return an array of DocumentGroup objects.
108 * @param int The stateid of DocumentGroups
109 * @return array The array of DocumentGroup.
111 function &getDocumentGroups($stateid = 1) {
112 if ($this->flat_groups) {
113 return $this->flat_groups;
116 $this->flat_groups = array () ;
118 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid=$2 ORDER BY groupname ASC',
119 array($this->Group->getID(), $stateid));
120 $rows = db_numrows($result);
122 if (!$result || $rows < 1) {
123 $this->setError(_('No Document Directory Found').' '.db_error());
125 while ($arr = db_fetch_array($result)) {
126 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
130 return $this->flat_groups;
136 // c-file-style: "bsd"