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 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
11 * http://fusionforge.org
13 * This file is part of FusionForge. FusionForge is free software;
14 * you can redistribute it and/or modify it under the terms of the
15 * GNU General Public License as published by the Free Software
16 * Foundation; either version 2 of the Licence, or (at your option)
19 * FusionForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 __construct(&$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;
71 * getNested - Return an array of DocumentGroup objects arranged for nested views.
73 * @param int The stateid of DocumentGroup : default is public (1).
74 * @return array The array of DocumentGroup.
76 function &getNested($stateid = 1) {
77 if ($this->nested_groups) {
78 return $this->nested_groups;
81 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid=$2 ORDER BY groupname ASC',
82 array($this->Group->getID(), $stateid));
85 $this->setError(_('No Documents Folder Found').' '.db_error());
88 while ($arr = db_fetch_array($result)) {
89 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
93 // Build the nested array
94 $count = count($this->flat_groups);
95 for ($i=0; $i < $count; $i++) {
96 $this->nested_groups["".$this->flat_groups[$i]->getParentID()][] =& $this->flat_groups[$i];
98 return $this->nested_groups;
102 * getDocumentGroups - Return an array of DocumentGroup objects.
104 * @param int The stateid of DocumentGroups : default is public (1).
105 * @return array The array of DocumentGroup.
107 function &getDocumentGroups($stateid = 1) {
108 if ($this->flat_groups) {
109 return $this->flat_groups;
112 $this->flat_groups = array();
114 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid=$2 ORDER BY groupname ASC',
115 array($this->Group->getID(), $stateid));
116 $rows = db_numrows($result);
118 if (!$result || $rows < 1) {
119 $this->setError(_('No Documents Folder Found').' '.db_error());
121 while ($arr = db_fetch_array($result)) {
122 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
126 return $this->flat_groups;
132 // c-file-style: "bsd"