Index: usage/project_usage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/usage/project_usage.module,v
retrieving revision 1.12
diff -u -p -r1.12 project_usage.module
--- usage/project_usage.module	26 Oct 2008 01:32:45 -0000	1.12
+++ usage/project_usage.module	26 Oct 2008 23:47:14 -0000
@@ -166,7 +166,7 @@ function project_usage_overview() {
   $headers = array(array('field' => 'n.title', 'data' => t('Project')));
 
   $joins_args = array();
-  foreach (project_usage_get_last_weeks($week_count) as $i => $week) {
+  foreach (project_usage_get_last_weeks('project', $week_count) as $i => $week) {
     // Note that "{$i}" in these query snippets are used to add a week integer
     // to the table and field aliases so we can uniquely identify each column
     // for sorting purposes.  These are not literals in the query, we need
@@ -269,7 +269,7 @@ function project_usage_project_page($nod
   $release_header = array(array('field' => 'n.title', 'data' => t('Release'), 'sort' => 'desc'));
 
   $joins_args = array();
-  foreach (project_usage_get_last_weeks($week_count) as $i => $week) {
+  foreach (project_usage_get_last_weeks('release', $week_count) as $i => $week) {
     // Note that "{$i}" in these query snippets are used to add a week integer
     // to the table and field aliases so we can uniquely identify each column
     // for sorting purposes.  These are not literals in the query, we need
@@ -636,8 +636,10 @@ function project_usage_get_weeks_since($
 }
 
 /**
- * Return an array of the N previous weeks for which we'll have data.
+ * Return an array of the N previous weeks for which we have data.
  *
+ * @param $table_suffix
+ *   Suffix of the table we want to query data from.
  * @param $count
  *   Number of weeks to return.
  *
@@ -645,13 +647,14 @@ function project_usage_get_weeks_since($
  *   An array of UNIX timestamps sorted newest to oldest. Will not include
  *   the current week.
  */
-function project_usage_get_last_weeks($count = PROJECT_USAGE_SHOW_WEEKS) {
-  $weeks = project_usage_get_weeks_since(time() - ($count * PROJECT_USAGE_WEEK));
-  // Use array_pop() to remove the current week as we won't have usage data
-  // for it.
-  array_pop($weeks);
-  // Reverse the order so it's newest to oldest.
-  return array_reverse($weeks);
+function project_usage_get_last_weeks($table_suffix, $count = PROJECT_USAGE_SHOW_WEEKS) {
+  $table = '{project_usage_week_' . $table_suffix . '}';
+  $query = db_query("SELECT DISTINCT(timestamp) FROM $table ORDER BY timestamp DESC LIMIT $count");
+  $weeks = array();
+  while ($week = db_fetch_object($query)) {
+    $weeks[] = $week->timestamp;
+  }
+  return $weeks;
 }
 
 /**
