3 * FusionForge Documentation 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-2014,2016, 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/FFError.class.php';
35 class DocumentGroupFactory extends FFError {
37 * This variable holds the document groups.
42 * This variable holds the document groups for reading them in nested form.
54 function __construct(&$Group) {
55 parent::__construct();
57 if (!$Group || !is_object($Group)) {
58 $this->setError(_('Invalid Project'));
61 if ($Group->isError()) {
62 $this->setError('DocumentGroupFactory::'.' '.$Group->getErrorMessage());
65 $this->Group =& $Group;
69 * getNested - Return an array of DocumentGroup objects arranged for nested views.
71 * @param array $stateid The array of stateid of DocumentGroup : default is public (1).
72 * @return array The array of DocumentGroup.
74 function &getNested($stateid = array(1)) {
75 if ($this->nested_groups) {
76 return $this->nested_groups;
79 $result = db_query_params('SELECT * FROM doc_groups WHERE group_id=$1 AND stateid = ANY ($2) ORDER BY groupname ASC',
80 array($this->Group->getID(), db_int_array_to_any_clause($stateid)));
83 $this->setError(_('No Documents Folder Found').' '.db_error());
86 while ($arr = db_fetch_array($result)) {
87 $this->flat_groups[] = new DocumentGroup($this->Group, $arr);
91 // Build the nested array
92 if (is_array($this->flat_groups)) {
93 $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 array $stateid The array of stateid of DocumentGroups : default is public (1).
107 * @return array The array of DocumentGroup.
109 function &getDocumentGroups($stateid = array(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 = ANY ($2) ORDER BY groupname ASC',
117 array($this->Group->getID(), db_int_array_to_any_clause($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"