3 * Copyright (C) 2008-2009 Alcatel-Lucent
5 * This file is part of FusionForge. FusionForge is free software;
6 * you can redistribute it and/or modify it under the terms of the
7 * GNU General Public License as published by the Free Software
8 * Foundation; either version 2 of the Licence, or (at your option)
11 * FusionForge is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Standard Alcatel-Lucent disclaimer for contributing to open source
24 * "The Tag Cloud ("Contribution") has not been tested and/or
25 * validated for release as or in products, combinations with products or
26 * other commercial use. Any use of the Contribution is entirely made at
27 * the user's own responsibility and the user can not rely on any features,
28 * functionalities or performances Alcatel-Lucent has attributed to the
31 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
32 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
33 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
34 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
35 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
36 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
37 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
38 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
39 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
45 $CLASS_PREFIX = 'tag';
46 $SELECTED_STYLE = 'style="text-decoration:overline underline;"';
49 * tag_cloud() - This function displays a tag cloug with the tags defined by projects.
50 * The size of each tag depends of its frequency.
51 * Each tag is a link to display a list of projects where the tag is defined.
52 * Delta between two font sizes is constant :
53 * function is F(count) = size = A * count + B
62 * A = (Smax - Smin) / (Cmax - Cmin)
64 * If Smin = 1 then Smax = number of size = N
66 * A = (N - 1) / (Cmax - Cmin)
68 * F(count) = size = A * count + 1 - A * Cmin
69 * => size = 1 + (count - Cmin) * A
71 * @param array selected tag, max tag displayed, number of sizes available,
72 * class prefix for css class, style for selected tag
74 function tag_cloud($params = '') {
78 global $SELECTED_STYLE;
80 if (! is_array($params)) $parames = array();
81 if (! isset($params['selected'])) {
82 $params['selected'] = '';
84 if (! isset($params['nb_max'])) {
85 $params['nb_max'] = $NB_MAX;
87 if (! isset($params['nb_size'])) {
88 $params['nb_size'] = $NB_SIZE;
90 if (! isset($params['class_prefix'])) {
91 $params['class_prefix'] = $CLASS_PREFIX;
93 if (! isset($params['selected_style'])) {
94 $params['selected_style'] = $SELECTED_STYLE;
99 // count tag occurrence
100 $res = db_query_params ('SELECT project_tags.name,project_tags.group_id
101 FROM project_tags, groups
102 WHERE project_tags.group_id = groups.group_id
103 AND groups.status = $1 AND groups.type_id=1 AND groups.register_time > 0',
105 $tag_count = array();
106 while ($row = db_fetch_array($res)) {
107 if (forge_check_perm ('project_read', $row['group_id'])) {
108 $tagname = $row['name'];
109 if (!isset ($tag_count[$tagname])) {
110 $tag_count[$tagname] = 0;
112 $tag_count[$tagname]++;
116 // order tags by popularity
117 $count_to_tags = array();
118 foreach ($tag_count as $name => $count) {
119 if (!isset($count_to_tags[$count])) {
120 $count_to_tags[$count] = array();
122 $count_to_tags[$count][] = $name;
125 $available_counts = array_keys($count_to_tags);
126 rsort ($available_counts, SORT_NUMERIC);
128 if (count($tag_count) > 0) {
132 foreach ($available_counts as $count) {
133 if ($count_min == 0 || $count < $count_min) $count_min = $count;
134 if ($count > $count_max) $count_max = $count;
135 $nb = $nb + count($count_to_tags[$count]);
136 if ($params['nb_max'] && $nb >= $params['nb_max']) break; // no limit if nb_max == 0
139 // Compute 'A' parameter of the function
140 if ($count_max != $count_min) // else we have a division by zero
142 $a = ($params['nb_size'] - 1) / ($count_max - $count_min);
145 // Set value 0 for 'A' parameter just for initialised variable
146 // but it's not realy necessary because if $count_max == $count_min
147 // then $count - $count_min = 0 (see below)
151 ksort($tag_count, SORT_STRING);
152 foreach ($tag_count as $name => $count) {
153 if ($count < $count_min) continue;
154 $size = intval(1 + ($count - $count_min) * $a);
155 $return .= '<a href="/softwaremap/tag_cloud.php?tag='
157 . '" class="' . $params['class_prefix'] . $size . '" '
158 . (($name == $params['selected']) ? $params['selected_style'] : '' )
159 . '>' . htmlspecialchars($name) . '</a> ';
167 * list_project_tag() - Returns the list of the tags defined by the project.
168 * Each tag is a link to display a list of projects
169 * where the tag is defined.
171 * @param int Group ID
173 function list_project_tag($group_id) {
174 $req = 'SELECT name FROM project_tags WHERE group_id = $1';
175 $res = db_query_params($req, array($group_id));
176 $nb_tag = db_numrows($res);
180 while ($row = db_fetch_array($res)) {
181 $return .= '<a href="/softwaremap/tag_cloud.php?tag='
182 . urlencode($row['name'])
183 . '">' . htmlspecialchars($row['name']) . '</a>' . (($idx < $nb_tag) ? ', ' : '');
193 // c-file-style: "bsd"