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 * Copyright 2012, Franck Villaume - TrivialDev
10 * http://fusionforge.org
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 require_once $gfcommon.'include/Error.class.php';
34 class DocumentGroupFactory extends Error {
36 * This variable holds the document groups.
41 * This variable holds the document groups for reading them in nested form.
53 * @return boolean success.
55 function DocumentGroupFactory(&$Group) {
58 if (!$Group || !is_object($Group)) {
59 $this->setError(_('DocumentGroupFactory:: Invalid Project'));
62 if ($Group->isError()) {
63 $this->setError('DocumentGroupFactory::'.' '.$Group->getErrorMessage());
66 $this->Group =& $Group;
72 * getNested - Return an array of DocumentGroup objects arranged for nested views.
74 * @param int The stateid of DocumentGroup : default is public (1).
75 * @return array The array of DocumentGroup.
77 function &getNested($stateid = 1) {
78 if ($this->nested_groups) {
79 return $this->nested_groups;
82 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid=$2 ORDER BY groupname ASC',
83 array($this->Group->getID(), $stateid));
84 $rows = db_numrows($result);
87 $this->setError(_('No Documents Folder Found').' '.db_error());
90 while ($arr = db_fetch_array($result)) {
91 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
95 // Build the nested array
96 $count = count($this->flat_groups);
97 for ($i=0; $i < $count; $i++) {
98 $this->nested_groups["".$this->flat_groups[$i]->getParentID()][] =& $this->flat_groups[$i];
100 return $this->nested_groups;
104 * getDocumentGroups - Return an array of DocumentGroup objects.
106 * @param int The stateid of DocumentGroups : default is public (1).
107 * @return array The array of DocumentGroup.
109 function &getDocumentGroups($stateid = 1) {
110 if ($this->flat_groups) {
111 return $this->flat_groups;
114 $this->flat_groups = array();
116 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid=$2 ORDER BY groupname ASC',
117 array($this->Group->getID(), $stateid));
118 $rows = db_numrows($result);
120 if (!$result || $rows < 1) {
121 $this->setError(_('No Documents Folder Found').' '.db_error());
123 while ($arr = db_fetch_array($result)) {
124 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
128 return $this->flat_groups;
134 // c-file-style: "bsd"