3 * Copyright (C) 2008-2009 Alcatel-Lucent
5 * This file is part of FusionForge.
7 * FusionForge is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License,
10 * or (at your option) any later version.
12 * FusionForge is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with FusionForge; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * Standard Alcatel-Lucent disclaimer for contributing to open source
26 * "The Tag Cloud ("Contribution") has not been tested and/or
27 * validated for release as or in products, combinations with products or
28 * other commercial use. Any use of the Contribution is entirely made at
29 * the user's own responsibility and the user can not rely on any features,
30 * functionalities or performances Alcatel-Lucent has attributed to the
33 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
34 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
36 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
37 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
39 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
41 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
47 $CLASS_PREFIX = 'tag';
48 $SELECTED_STYLE = 'style="text-decoration:overline underline;"';
51 * tag_cloud() - This function displays a tag cloug with the tags defined by projects.
52 * The size of each tag depends of its frequency.
53 * Each tag is a link to display a list of projects where the tag is defined.
54 * Delta between two font sizes is constant :
55 * function is F(count) = size = A * count + B
64 * A = (Smax - Smin) / (Cmax - Cmin)
66 * If Smin = 1 then Smax = number of size = N
68 * A = (N - 1) / (Cmax - Cmin)
70 * F(count) = size = A * count + 1 - A * Cmin
71 * => size = 1 + (count - Cmin) * A
73 * @param array selected tag, max tag displayed, number of sizes available,
74 * class prefix for css class, style for selected tag
76 function tag_cloud($params = '') {
80 global $SELECTED_STYLE;
82 if (! is_array($params)) $parames = array();
83 if (! isset($params['selected'])) {
84 $params['selected'] = '';
86 if (! isset($params['nb_max'])) {
87 $params['nb_max'] = $NB_MAX;
89 if (! isset($params['nb_size'])) {
90 $params['nb_size'] = $NB_SIZE;
92 if (! isset($params['class_prefix'])) {
93 $params['class_prefix'] = $CLASS_PREFIX;
95 if (! isset($params['selected_style'])) {
96 $params['selected_style'] = $SELECTED_STYLE;
101 $res = db_query("SELECT name,count(*) AS count
102 FROM project_tags, groups
103 WHERE project_tags.group_id = groups.group_id
104 AND status = 'A' AND is_public=1 AND type_id=1 AND register_time > 0
105 GROUP BY name ORDER BY count DESC");
106 if (db_numrows($res) > 0) {
110 // Search upper and lower tag frequencies; stop when maximum tag number to display is reached
111 while ($row = db_fetch_array($res)) {
112 $tag_count[$row['name']] = $row['count'];
113 if ($count_min == 0 || $row['count'] < $count_min) $count_min = $row['count'];
114 if ($row['count'] > $count_max) $count_max = $row['count'];
115 if ($nb >= $params['nb_max']) break;
119 // Compute 'A' parameter of the function
120 if ($count_max != $count_min) // else we have a division by zero
122 $a = ($params['nb_size'] - 1) / ($count_max - $count_min);
125 // Set value 0 for 'A' parameter just for initialised variable
126 // but it's not realy necessary because if $count_max == $count_min
127 // then $count - $count_min = 0 (see below)
131 ksort($tag_count, SORT_STRING);
132 foreach ($tag_count as $name => $count) {
133 $size = intval(1 + ($count - $count_min) * $a);
134 $return .= '<a href="/softwaremap/tag_cloud.php?tag='
136 . '" class="' . $params['class_prefix'] . $size . '" '
137 . (($name == $params['selected']) ? $params['selected_style'] : '' )
138 . '>' . htmlspecialchars($name) . '</a> ';
146 * list_project_tag() - Returns the list of the tags defined by the project.
147 * Each tag is a link to display a list of projects
148 * where the tag is defined.
150 * @param int Group ID
152 function list_project_tag($group_id) {
153 $req = 'SELECT name FROM project_tags WHERE group_id = $1';
154 $res = db_query_params($req, array($group_id));
155 $nb_tag = db_numrows($res);
159 while ($row = db_fetch_array($res)) {
160 $return .= '<a href="/softwaremap/tag_cloud.php?tag='
161 . urlencode($row['name'])
162 . '">' . htmlspecialchars($row['name']) . '</a>' . (($idx < $nb_tag) ? ', ' : '');