Index: playlist/station_playlist.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/playlist/station_playlist.module,v
retrieving revision 1.12
diff -u -p -r1.12 station_playlist.module
--- playlist/station_playlist.module	14 Aug 2007 15:56:32 -0000	1.12
+++ playlist/station_playlist.module	10 Oct 2007 17:53:34 -0000
@@ -7,6 +7,10 @@ if (module_exists('views')) {
   require_once(drupal_get_path('module', 'station_playlist') .'/views_defaults.inc');
 }
 
+// Number of seconds in a day.
+define('STATION_PLAYLIST_DAY', 60 * 60 * 24);
+// Number of seconds in a week.
+define('STATION_PLAYLIST_WEEK', STATION_PLAYLIST_DAY * 7);
 
 /**
  * Display help and module information
@@ -32,7 +36,12 @@ function station_playlist_menu($may_cach
       'access' => user_access('administer site configuration'),
       'type' => MENU_LOCAL_TASK
     );
-
+    $items[] = array(
+      'path' => 'station/playlists/popular',
+      'title' => t("What's hot"),
+      'callback' => 'station_playlist_popular',
+      'access' => user_access('access content'),
+    );
     $items[] = array(
       'path' => 'station/autocomplete/playlist',
       'title' => t('Playlist Autocomplete'),
@@ -85,6 +94,33 @@ function station_playlist_admin_settings
     '#default_value' => variable_get('station_playlist_program_dateformat', 'F j, Y'),
     '#description' => t("The playlist's date is also displayed on the the program node. This setting lets you control how it is formatted."),
   );
+  
+  $times = array(
+    4 * STATION_PLAYLIST_WEEK,
+    3 * STATION_PLAYLIST_WEEK,
+    2 * STATION_PLAYLIST_WEEK,
+    1 * STATION_PLAYLIST_WEEK,
+    6 * STATION_PLAYLIST_DAY,
+    5 * STATION_PLAYLIST_DAY,
+    4 * STATION_PLAYLIST_DAY,
+    3 * STATION_PLAYLIST_DAY,
+    2 * STATION_PLAYLIST_DAY,
+    1 * STATION_PLAYLIST_DAY,
+  );
+  $age_options = drupal_map_assoc($times, 'format_interval');
+  $form['popular'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Popular list'),
+    '#tree' => FALSE,
+  );
+  $form['popular']['station_playlist_popular_range'] = array(
+    '#type' => 'select',
+    '#title' => t('Show since'),
+    '#default_value' => variable_get('station_playlist_popular_range', 1 * STATION_PLAYLIST_WEEK),
+    '#options' => $age_options,
+    '#description' => t("Show the most played albums for this length of time."),
+  );
+  
   $form['module_cvs_id'] = array(
     '#type' => 'item',
     '#value' => '<pre>'. STATION_PLAYLIST_CVS_ID .'</pre>',
@@ -549,3 +585,19 @@ function station_playlist_autocomplete($
   print drupal_to_js($matches);
   exit();
 }
+
+/**
+ * Display a page of most popular albums.
+ */
+function station_playlist_popular() {
+  $since = time() - variable_get('station_playlist_popular_range', 1 * STATION_PLAYLIST_WEEK);
+  $sql = 'SELECT spt.artist, spt.album, COUNT(*) AS play_count FROM {node} n INNER JOIN {station_playlist} sp ON n.nid = sp.nid INNER JOIN {station_playlist_track} spt ON sp.nid = spt.nid WHERE sp.timestamp >= %d GROUP BY spt.album, spt.title HAVING COUNT(*) > 1 ORDER BY play_count DESC';
+  //$result = db_queryd($sql, array($since));
+  $result = db_query_range($sql, array($since), 0, 30);
+  $rows = array();
+  while ($item = db_fetch_array($result)) {
+    $rows[] = $item;
+  }
+  $header = array(t('Artist'), t('Album'), t('Play count'));
+  return theme('table', $header, $rows);
+}
\ No newline at end of file
