Index: modules/download_count/download_count.module =================================================================== --- modules/download_count/download_count.module (revision 9) +++ modules/download_count/download_count.module (working copy) @@ -2,6 +2,12 @@ /** * @file Download counter */ + +if (module_exists('views')) { + include_once(drupal_get_path('module', 'download_count') . '/download_count_views.inc'); +} + + /** * Implementation of hook_help() */ @@ -204,7 +210,7 @@ db_query("UPDATE {file_downloads} SET count = count+1, timestamp = %d WHERE filename = '%s'", time(), $filename); } else { - db_query("INSERT INTO {file_downloads} (filename, count, timestamp) VALUES ('%s', 1,%d)", $filename, time()); + db_query("INSERT INTO {file_downloads} (filename, count, timestamp, nid) VALUES ('%s', 1,%d, %d)", $filename, time(), $file->nid); } } else { Index: modules/download_count/download_count.install =================================================================== --- modules/download_count/download_count.install (revision 9) +++ modules/download_count/download_count.install (working copy) @@ -17,6 +17,7 @@ did serial NOT NULL, filename character varying(255) NOT NULL, count integer DEFAULT 0 NOT NULL, + nid int unsigned NOT NULL auto_increment, \"timestamp\" integer DEFAULT 0 NOT NULL )"); db_query("ALTER TABLE ONLY {file_downloads} ADD CONSTRAINT {file_downloads}_pkey PRIMARY KEY (did)"); Index: modules/download_count/download_count_views.inc =================================================================== --- modules/download_count/download_count_views.inc (revision 0) +++ modules/download_count/download_count_views.inc (revision 0) @@ -0,0 +1,39 @@ + 'file_downloads', + 'provider' => 'internal', + 'join' => array( + 'left' => array( + 'table' => 'node', + 'field' => 'nid' + ), + 'right' => array( + 'field' => 'nid' + ) + ), + 'fields' => array( + 'count' => array( + 'name' => t('Download Count: Number of Downloads'), + 'help' => t('Display the number of times a file has been downloaded'), + ), + ), + 'filters' => array( + 'count' => array( + 'name' => t('Download Count: Number of Downloads'), + 'operator' => views_handler_operator_gtlt(), + 'help' => t('This enables you to filter on the number of times a file has been downloaded.'), + ), + ), + 'sorts' => array( + 'count' => array( + 'name' => t('Download Count: Number of Downloads'), + 'help' => t('Sort by the number of times downloaded') + ), + ) + ); + + return $tables; +} +