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.
56 function __construct(&$Group) {
59 if (!$Group || !is_object($Group)) {
62 if ($Group->isError()) {
63 $this->setError('DocumentGroupFactory::'.' '.$Group->getErrorMessage());
66 $this->Group =& $Group;
70 * getNested - Return an array of DocumentGroup objects arranged for nested views.
72 * @param int The stateid of DocumentGroup : default is public (1).
73 * @return array The array of DocumentGroup.
75 function &getNested($stateid = 1) {
76 if ($this->nested_groups) {
77 return $this->nested_groups;
80 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid=$2 ORDER BY groupname ASC',
81 array($this->Group->getID(), $stateid));
84 $this->setError(_('No Documents Folder Found').' '.db_error());
87 while ($arr = db_fetch_array($result)) {
88 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
92 // Build the nested array
93 $count = count($this->flat_groups);
94 for ($i=0; $i < $count; $i++) {
95 $this->nested_groups["".$this->flat_groups[$i]->getParentID()][] =& $this->flat_groups[$i];
97 return $this->nested_groups;
101 * getDocumentGroups - Return an array of DocumentGroup objects.
103 * @param int The stateid of DocumentGroups : default is public (1).
104 * @return array The array of DocumentGroup.
106 function &getDocumentGroups($stateid = 1) {
107 if ($this->flat_groups) {
108 return $this->flat_groups;
111 $this->flat_groups = array();
113 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid=$2 ORDER BY groupname ASC',
114 array($this->Group->getID(), $stateid));
115 $rows = db_numrows($result);
117 if (!$result || $rows < 1) {
118 $this->setError(_('No Documents Folder Found').' '.db_error());
120 while ($arr = db_fetch_array($result)) {
121 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
125 return $this->flat_groups;
131 // c-file-style: "bsd"