3 * FusionForge Documentation Manager
5 * Copyright 2002 GForge, LLC
6 * Copyright 2010, Franck Villaume - Capgemini
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * http://fusionforge.org
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'include/pre.php';
27 require_once $gfwww.'include/note.php';
30 * Wrap many group display related functions
32 class DocumentGroupHTML extends Error {
35 function __construct(&$Group) {
38 if (!$Group || !is_object($Group)) {
41 if ($Group->isError()) {
42 $this->setError(_('Error') . _(': ') . $Group->getErrorMessage());
45 $this->Group =& $Group;
49 * showSelectNestedGroups - Display the tree of document groups inside a <select> tag
51 * @param array Array of groups.
52 * @param string The name that will be assigned to the input
53 * @param bool Allow selection of "None"
54 * @param int The ID of the group that should be selected by default (if any)
55 * @param array Array of IDs of groups that should not be displayed
56 * @return string html select box code
58 function showSelectNestedGroups($group_arr, $select_name, $allow_none = true, $selected_id = 0, $dont_display = array()) {
59 // Build arrays for calling html_build_select_box_from_arrays()
61 $text_array = array();
64 // First option to be displayed
66 $text_array[] = "(None)";
69 // Recursively build the document group tree
70 $this->buildArrays($group_arr, $id_array, $text_array, $dont_display);
72 echo html_build_select_box_from_arrays($id_array, $text_array, $select_name, $selected_id, false);
76 * buildArrays - Build the arrays to call html_build_select_box_from_arrays()
78 * @param array Array of groups.
79 * @param array Reference to the array of ids that will be build
80 * @param array Reference to the array of group names
81 * @param array Array of IDs of groups that should not be displayed
82 * @param int The ID of the parent whose childs are being showed (0 for root groups)
83 * @param int The current level
85 function buildArrays($group_arr, &$id_array, &$text_array, &$dont_display, $parent = 0, $level = 0) {
86 if (!is_array($group_arr) || !array_key_exists("$parent", $group_arr)) return;
88 $child_count = count($group_arr["$parent"]);
89 for ($i = 0; $i < $child_count; $i++) {
90 $doc_group =& $group_arr["$parent"][$i];
92 // Should we display this element?
93 if (in_array($doc_group->getID(), $dont_display)) continue;
95 $margin = str_repeat("--", $level);
97 $id_array[] = $doc_group->getID();
98 $text_array[] = $margin.$doc_group->getName();
100 // Show childs (if any)
101 $this->buildArrays($group_arr, $id_array, $text_array, $dont_display, $doc_group->getID(), $level+1);
108 // c-file-style: "bsd"