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. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 require_once $gfcommon.'include/Error.class.php';
33 class DocumentGroupFactory extends Error {
35 * This variable holds the document groups.
40 * This variable holds the document groups for reading them in nested form.
52 * @return boolean success.
54 function DocumentGroupFactory(&$Group) {
57 if (!$Group || !is_object($Group)) {
58 $this->setError(_('DocumentGroupFactory:: Invalid Project'));
61 if ($Group->isError()) {
62 $this->setError('DocumentGroupFactory::'.' '.$Group->getErrorMessage());
65 $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));
83 $rows = db_numrows($result);
86 $this->setError(_('No Documents Folder Found').' '.db_error());
89 while ($arr = db_fetch_array($result)) {
90 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
94 // Build the nested array
95 $count = count($this->flat_groups);
96 for ($i=0; $i < $count; $i++) {
97 $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"