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)) {
39 $this->setError(_('Invalid Project'));
42 if ($Group->isError()) {
43 $this->setError(sprintf(_('Error: %s'), $Group->getErrorMessage()));
46 $this->Group =& $Group;
50 * showSelectNestedGroups - Display the tree of document groups inside a <select> tag
52 * @param array Array of groups.
53 * @param string The name that will be assigned to the input
54 * @param bool Allow selection of "None"
55 * @param int The ID of the group that should be selected by default (if any)
56 * @param array Array of IDs of groups that should not be displayed
57 * @return string html select box code
59 function showSelectNestedGroups($group_arr, $select_name, $allow_none = true, $selected_id = 0, $dont_display = array()) {
60 // Build arrays for calling html_build_select_box_from_arrays()
62 $text_array = array();
65 // First option to be displayed
67 $text_array[] = "(None)";
70 // Recursively build the document group tree
71 $this->buildArrays($group_arr, $id_array, $text_array, $dont_display);
73 echo html_build_select_box_from_arrays($id_array, $text_array, $select_name, $selected_id, false);
77 * buildArrays - Build the arrays to call html_build_select_box_from_arrays()
79 * @param array Array of groups.
80 * @param array Reference to the array of ids that will be build
81 * @param array Reference to the array of group names
82 * @param array Array of IDs of groups that should not be displayed
83 * @param int The ID of the parent whose childs are being showed (0 for root groups)
84 * @param int The current level
86 function buildArrays($group_arr, &$id_array, &$text_array, &$dont_display, $parent = 0, $level = 0) {
87 if (!is_array($group_arr) || !array_key_exists("$parent", $group_arr)) return;
89 $child_count = count($group_arr["$parent"]);
90 for ($i = 0; $i < $child_count; $i++) {
91 $doc_group =& $group_arr["$parent"][$i];
93 // Should we display this element?
94 if (in_array($doc_group->getID(), $dont_display)) continue;
96 $margin = str_repeat("--", $level);
98 $id_array[] = $doc_group->getID();
99 $text_array[] = $margin.$doc_group->getName();
101 // Show childs (if any)
102 $this->buildArrays($group_arr, $id_array, $text_array, $dont_display, $doc_group->getID(), $level+1);
109 // c-file-style: "bsd"