3 * FusionForge Documentation Manager
5 * Copyright 2002 GForge, LLC
6 * Copyright 2010, Franck Villaume - Capgemini
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * Copyright 2013 Franck Villaume - TrivialDev
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.
27 require_once $gfcommon.'include/pre.php';
28 require_once $gfwww.'include/note.php';
31 * Wrap many group display related functions
33 class DocumentGroupHTML extends Error {
40 * @return \DocumentGroupHTML
42 function __construct(&$Group) {
45 if (!$Group || !is_object($Group)) {
46 $this->setError(_('No Valid Group Object'));
49 if ($Group->isError()) {
50 $this->setError(_('Error') . _(': ') . $Group->getErrorMessage());
53 $this->Group =& $Group;
57 * showSelectNestedGroups - Display the tree of document groups inside a <select> tag
59 * @param array $group_arr Array of groups.
60 * @param string $select_name The name that will be assigned to the input
61 * @param bool $allow_none Allow selection of "None"
62 * @param int $selected_id The ID of the group that should be selected by default (if any)
63 * @param array $dont_display Array of IDs of groups that should not be displayed
64 * @return string html select box code
66 function showSelectNestedGroups($group_arr, $select_name, $allow_none = true, $selected_id = 0, $dont_display = array()) {
67 // Build arrays for calling html_build_select_box_from_arrays()
69 $text_array = array();
72 // First option to be displayed
74 $text_array[] = "(None)";
77 // Recursively build the document group tree
78 $this->buildArrays($group_arr, $id_array, $text_array, $dont_display);
80 echo html_build_select_box_from_arrays($id_array, $text_array, $select_name, $selected_id, false);
84 * buildArrays - Build the arrays to call html_build_select_box_from_arrays()
86 * @param array Array of groups.
87 * @param array Reference to the array of ids that will be build
88 * @param array Reference to the array of group names
89 * @param array Array of IDs of groups that should not be displayed
90 * @param int The ID of the parent whose childs are being showed (0 for root groups)
91 * @param int The current level
93 function buildArrays($group_arr, &$id_array, &$text_array, &$dont_display, $parent = 0, $level = 0) {
94 if (!is_array($group_arr) || !array_key_exists("$parent", $group_arr)) return;
96 $child_count = count($group_arr["$parent"]);
97 for ($i = 0; $i < $child_count; $i++) {
98 $doc_group =& $group_arr["$parent"][$i];
100 // Should we display this element?
101 if (in_array($doc_group->getID(), $dont_display)) continue;
103 $margin = str_repeat("--", $level);
105 $id_array[] = $doc_group->getID();
106 $text_array[] = $margin.$doc_group->getName();
108 // Show childs (if any)
109 $this->buildArrays($group_arr, $id_array, $text_array, $dont_display, $doc_group->getID(), $level+1);
116 // c-file-style: "bsd"