4 * Copyright 1999-2001 (c) VA Linux Systems
5 * Copyright 2009, Roland Mas
7 * This file is part of GForge.
9 * GForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * GForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
24 require (dirname(__FILE__).'/../www/env.inc.php');
25 require_once $gfcommon.'include/pre.php';
26 require $gfcommon.'include/cron_utils.php';
32 Rebuild the trove_agg table, which saves us
33 from doing really expensive queries in trove
34 each time of the trove map is viewed
40 db_query_params ('DELETE FROM trove_agg',
43 db_query_params ('INSERT INTO trove_agg
44 (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
46 LEFT JOIN project_weekly_metric USING (group_id), trove_group_link tgl
47 WHERE tgl.group_id=g.group_id
51 ORDER BY trove_cat_id ASC, ranking ASC)',
59 Calculate the number of projects under each category
61 Do this by first running an aggregate query in the database,
62 then putting that into two associative arrays.
64 Start at the top of the trove tree and recursively go down
65 the tree, building a third associative array which contains
66 the count of projects under each category
68 Then iterate through that third array and insert the results into the
69 database inside of a transaction
76 $res = db_query_params ('SELECT trove_cat.trove_cat_id,trove_cat.parent
78 WHERE trove_cat.trove_cat_id!=0
79 GROUP BY trove_cat.trove_cat_id,trove_cat.parent',
81 $rows=db_numrows($res);
83 for ($i=0; $i<$rows; $i++) {
84 $parent_list[db_result($res,$i,'parent')][]=db_result($res,$i,'trove_cat_id');
87 $res = db_query_params ('SELECT trove_cat.trove_cat_id,trove_cat.parent,count(groups.group_id) AS count
88 FROM trove_cat LEFT JOIN trove_group_link ON
89 trove_cat.trove_cat_id=trove_group_link.trove_cat_id
91 groups.group_id=trove_group_link.group_id
92 WHERE (groups.status=$1 OR groups.status IS NULL)
93 AND (groups.type_id=1 OR groups.status IS NULL)
94 AND (groups.is_public=1 OR groups.is_public IS NULL)
95 GROUP BY trove_cat.trove_cat_id,trove_cat.parent',
98 $rows = db_numrows($res);
100 for ($i=0; $i<$rows; $i++) {
101 $cat_counts[db_result($res,$i,'trove_cat_id')][0]=db_result($res,$i,'parent');
102 $cat_counts[db_result($res,$i,'trove_cat_id')][1]=db_result($res,$i,'count');
107 function get_trove_sub_projects($cat_id) {
108 global $cat_counts,$sum_totals,$parent_list;
110 // Number of groups that were in this trove_cat
111 $count=isset($cat_counts[$cat_id][1]) ? $cat_counts[$cat_id][1] : 0;
113 //number of children of this trove_cat
114 $rows=count( @$parent_list[$cat_id] );
116 for ($i=0; $i<$rows; $i++) {
117 $count += get_trove_sub_projects( $parent_list[$cat_id][$i] );
119 $sum_totals["$cat_id"]=$count;
123 //start the recursive function at the top of the trove tree
124 $res2 = db_query_params ('SELECT trove_cat_id FROM trove_cat WHERE parent=0',
127 for ($i=0; $i< db_numrows($res2); $i++) {
128 get_trove_sub_projects( db_result($res2,$i,0) );
132 db_query_params ('DELETE FROM trove_treesums',
137 while (list($k,$v) = each($sum_totals)) {
138 $res = db_query_params ('INSERT INTO trove_treesums (trove_cat_id,subprojects)
142 if (!$res || db_affected_rows($res)!=1) {
145 // $err .= "<tr><td>$k</td><td>$v</td></tr>\n";
148 //$err .= "</table>";
153 $err .= "Error: ".db_error();