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