4 * Copyright 1999-2001 (c) VA Linux Systems
5 * Copyright 2009, Roland Mas
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require (dirname(__FILE__).'/../www/env.inc.php');
24 require_once $gfcommon.'include/pre.php';
25 require $gfcommon.'include/cron_utils.php';
31 Rebuild the trove_agg table, which saves us
32 from doing really expensive queries in trove
33 each time of the trove map is viewed
39 db_query_params ('DELETE FROM trove_agg',
42 db_query_params ('INSERT INTO trove_agg
43 (SELECT tgl.trove_cat_id, g.group_id, g.group_name, g.unix_group_name, g.status, g.register_time, g.short_description, project_weekly_metric.percentile, project_weekly_metric.ranking
45 LEFT JOIN project_weekly_metric USING (group_id), trove_group_link tgl, pfo_role_setting prs
46 WHERE tgl.group_id=g.group_id
49 AND g.group_id = prs.ref_id
50 AND prs.section_name = $2
52 ORDER BY trove_cat_id ASC, ranking ASC)',
61 Calculate the number of projects under each category
63 Do this by first running an aggregate query in the database,
64 then putting that into two associative arrays.
66 Start at the top of the trove tree and recursively go down
67 the tree, building a third associative array which contains
68 the count of projects under each category
70 Then iterate through that third array and insert the results into the
71 database inside of a transaction
78 $res = db_query_params ('SELECT trove_cat.trove_cat_id,trove_cat.parent
80 WHERE trove_cat.trove_cat_id!=0
81 GROUP BY trove_cat.trove_cat_id,trove_cat.parent',
83 $rows=db_numrows($res);
85 for ($i=0; $i<$rows; $i++) {
86 $parent_list[db_result($res,$i,'parent')][]=db_result($res,$i,'trove_cat_id');
89 $res = db_query_params ('SELECT trove_cat.trove_cat_id,trove_cat.parent,count(groups.group_id) AS count
90 FROM trove_cat LEFT JOIN trove_group_link ON
91 trove_cat.trove_cat_id=trove_group_link.trove_cat_id
93 groups.group_id=trove_group_link.group_id,
95 WHERE (groups.status=$1 OR groups.status IS NULL)
96 AND (groups.type_id=1 OR groups.status IS NULL)
97 AND groups.group_id = prs.ref_id
98 AND prs.section_name = $2
100 GROUP BY trove_cat.trove_cat_id,trove_cat.parent',
104 $rows = db_numrows($res);
106 for ($i=0; $i<$rows; $i++) {
107 $cat_counts[db_result($res,$i,'trove_cat_id')][0]=db_result($res,$i,'parent');
108 $cat_counts[db_result($res,$i,'trove_cat_id')][1]=db_result($res,$i,'count');
113 function get_trove_sub_projects($cat_id) {
114 global $cat_counts,$sum_totals,$parent_list;
116 // Number of groups that were in this trove_cat
117 $count=isset($cat_counts[$cat_id][1]) ? $cat_counts[$cat_id][1] : 0;
119 //number of children of this trove_cat
120 $rows=count( @$parent_list[$cat_id] );
122 for ($i=0; $i<$rows; $i++) {
123 $count += get_trove_sub_projects( $parent_list[$cat_id][$i] );
125 $sum_totals["$cat_id"]=$count;
129 //start the recursive function at the top of the trove tree
130 $res2 = db_query_params ('SELECT trove_cat_id FROM trove_cat WHERE parent=0',
133 for ($i=0; $i< db_numrows($res2); $i++) {
134 get_trove_sub_projects( db_result($res2,$i,0) );
138 db_query_params ('DELETE FROM trove_treesums',
143 while (list($k,$v) = each($sum_totals)) {
144 $res = db_query_params ('INSERT INTO trove_treesums (trove_cat_id,subprojects)
148 if (!$res || db_affected_rows($res)!=1) {
151 // $err .= "<tr><td>$k</td><td>$v</td></tr>\n";
154 //$err .= "</table>";
159 $err .= "Error: ".db_error();