function &get_section_usage_rows(&$f_usage_rows, &$f_topic_starts_rows) { $section_rows = array(); $row_count = sizeof($f_usage_rows); $j = 0; $section_post_count = 0; $section_topic_starts = 0; $section_watch_count = 0; $last_section_id = $row_count > 0 ? $f_usage_rows[0]['parent_id'] : -999; $forum_cats = get_root_categories_rows(); $forum_cats_array = array(); foreach ($forum_cats as $forum_cat) { $forum_cats_array[$forum_cat['forum_id']] = $forum_cat['forum_id']; } for ($i = 0; $i < $row_count; $i++) { /* If the section id has changed, add new row to $section_rows and reset count variables. Otherwise, simply update section data */ $cur_section_id = $f_usage_rows[$i]['parent_id']; // Mighty Gorgon: with the new category system we may just check if the parent is 0! $cur_cat_root_parent = in_array($f_usage_rows[$i]['parent_id'], $forum_cats_array) ? true : false; $cat_changed = $cur_section_id == $last_section_id ? false : true; if ($cur_cat_root_parent && $cat_changed) { $section_rows[$j++] = array('section_id' => $last_section_id, 'section_post_count' => $section_post_count, 'section_topic_starts' => $section_topic_starts, 'section_watch_count' => $section_watch_count); $section_post_count = 0; $section_topic_starts = 0; $section_watch_count = 0; $last_section_id = $cur_section_id; } $section_post_count += $f_usage_rows[$i]['forum_post_count']; $section_topic_starts += get_forum_topic_starts($f_topic_starts_rows, $f_usage_rows[$i]['forum_id']); $section_watch_count += $f_usage_rows[$i]['watch_count']; } /* Make sure we include the last section */ $section_rows[$j++] = array('section_id' => $last_section_id, 'section_post_count' => $section_post_count, 'section_topic_starts' => $section_topic_starts, 'section_watch_count' => $section_watch_count); /* Return results */ return $section_rows; }
$section_usage_rows =& get_section_usage_rows($forum_usage_rows, $forum_topic_starts_rows); /* Set the file handles to include bb_usage_stats.tpl */ $template->set_filenames(array('bb_usage_stats_template' => 'bb_usage_stats.tpl')); $unpruned_post_count = get_unpruned_post_count($profiledata['user_id']); $max_columns = 7; if (($viewoptions & BBUS_VIEWOPTION_PCTUTUP_COLUMN_VISIBLE) != 0) { $max_columns++; } /* If any forum usage results were returned: */ if ($forum_usage_rows) { $prscale = isset($_POST['prscale']) ? $_POST['prscale'] : $config[BBUS_CONFIGPROP_PRSCALE_NAME]; $trscale = isset($_POST['trscale']) ? $_POST['trscale'] : $config[BBUS_CONFIGPROP_TRSCALE_NAME]; /* Pass results on to template... */ $last_cat_id = -1; for ($i = 0; $i < sizeof($forum_usage_rows); $i++) { $forum_topic_starts =& get_forum_topic_starts($forum_topic_starts_rows, $forum_usage_rows[$i]['forum_id']); // The *_per_day calculations assume $memberdays has already been calculated in usercp_viewprofile.php $forum_post_rate = sprintf("%01.2f", $forum_usage_rows[$i]['forum_post_count'] / $memberdays * $prscale); $forum_topic_rate = sprintf("%01.2f", $forum_topic_starts / $memberdays * $trscale); /* If the section id has changed, set it. */ $cur_cat_id = $forum_usage_rows[$i]['parent_id']; // Mighty Gorgon: with the new category system we may just check if the parent is 0! $cur_cat_root_parent = in_array($forum_usage_rows[$i]['parent_id'], $forum_cats_array) ? true : false; $cat_changed = $cur_cat_id == $last_cat_id ? false : true; if ($cur_cat_root_parent && $cat_changed) { $section_row =& get_section_usage_row($section_usage_rows, $cur_cat_id); /* Avoid Div By Zero */ if ($profiledata['user_posts'] <= 0) { $section_post_pctutp = sprintf("%01.2f", 0); } else { $section_post_pctutp = sprintf("%01.2f", $section_row['section_post_count'] / $profiledata['user_posts'] * 100);