summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/flag.php11
-rw-r--r--lib/class/album.class.php28
-rw-r--r--lib/class/artist.class.php26
-rw-r--r--lib/class/database_object.abstract.php21
-rw-r--r--lib/class/flag.class.php48
-rw-r--r--lib/class/tag.class.php24
6 files changed, 59 insertions, 99 deletions
diff --git a/admin/flag.php b/admin/flag.php
index bc5d9474..20b7524d 100644
--- a/admin/flag.php
+++ b/admin/flag.php
@@ -1,7 +1,7 @@
<?php
/*
- Copyright (c) 2001 - 2007 Ampache.org
+ Copyright (c) Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
@@ -18,7 +18,6 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
require '../lib/init.php';
if (!Access::check('interface','100')) {
@@ -291,9 +290,17 @@ switch ($_REQUEST['action']) {
} // end else
show_confirmation(_('Songs Enabled'),_('The requested song(s) have been enabled'),return_referer());
break;
+ case 'show_disabled':
+ $disabled = Flag::get_disabled();
+ Browse::set_type('song');
+ Browse::set_static_content(1);
+ Browse::save_objects($disabled);
+ Browse::show_objects($disabled);
+ break;
default:
case 'show_flagged':
$flagged = Flag::get_all();
+ Flag::build_cache($flagged);
Browse::set_type('flagged');
Browse::set_static_content(1);
Browse::save_objects($flagged);
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index ad0f6ef5..184842b6 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -59,7 +59,7 @@ class Album extends database_object {
$this->id = intval($id);
/* Get the information from the db */
- $info = $this->_get_info();
+ $info = $this->get_info();
// Foreach what we've got
foreach ($info as $key=>$value) {
@@ -111,32 +111,6 @@ class Album extends database_object {
} // build_cache
/**
- * _get_info
- * This is a private function that pulls the album
- * from the database
- */
- private function _get_info() {
-
- $id = intval($this->id);
-
- if (parent::is_cached('album',$id)) {
- return parent::get_from_cache('album',$id);
- }
-
- // Just get the album information
- $sql = "SELECT * FROM `album` WHERE `id`='$id'";
- $db_results = Dba::query($sql);
-
- $results = Dba::fetch_assoc($db_results);
-
- // Cache the object
- parent::add_to_cache('album',$id,$results);
-
- return $results;
-
- } // _get_info
-
- /**
* _get_extra_info
* This pulls the extra information from our tables, this is a 3 table join, which is why we don't normally
* do it
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index f5591018..f55fd999 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -48,7 +48,7 @@ class Artist extends database_object {
$this->id = intval($id);
/* Get the information from the db */
- $info = $this->_get_info();
+ $info = $this->get_info();
foreach ($info as $key=>$value) {
$this->$key = $value;
@@ -93,30 +93,6 @@ class Artist extends database_object {
} // build_cache
/**
- * _get_info
- * get's the vars for $this out of the database taken from the object
- */
- private function _get_info() {
-
- $id = intval($this->id);
-
- if (parent::is_cached('artist',$id)) {
- return parent::get_from_cache('artist',$id);
- }
-
- /* Grab the basic information from the catalog and return it */
- $sql = "SELECT * FROM artist WHERE id='$id'";
- $db_results = Dba::query($sql);
-
- $results = Dba::fetch_assoc($db_results);
-
- parent::add_to_cache('artist',$id,$results);
-
- return $results;
-
- } // _get_info
-
- /**
* get_from_name
* This gets an artist object based on the artist name
*/
diff --git a/lib/class/database_object.abstract.php b/lib/class/database_object.abstract.php
index 871232ea..2005da55 100644
--- a/lib/class/database_object.abstract.php
+++ b/lib/class/database_object.abstract.php
@@ -31,6 +31,27 @@ abstract class database_object {
// Statistics for debugging
public static $cache_hit = 0;
+ public function get_info($id,$table_name='') {
+
+ $table_name = $table_name ? Dba::escape($table_name) : Dba::escape(strtolower(get_class($this)));
+
+ if (self::is_cached($table_name,$id)) {
+ return self::get_from_cache($table_name,$id);
+ }
+
+ $sql = "SELECT * FROM `$table_name` WHERE `id`='$id'";
+ $db_results = Dba::query($sql);
+
+ if (!$db_results) { return array(); }
+
+ $row = Dba::fetch_assoc($db_results);
+
+ self::add_to_cache($table_name,$id,$row);
+
+ return $row;
+
+ } // get_info
+
/**
* is_cached
* this checks the cache to see if the specified object is there
diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php
index 9cc7c1a8..ba2480f8 100644
--- a/lib/class/flag.class.php
+++ b/lib/class/flag.class.php
@@ -1,7 +1,7 @@
<?php
/*
- Copyright 2001 - 2007 Ampache.org
+ Copyright Ampache.org
All Rights Reserved
This program is free software; you can redistribute it and/or
@@ -24,7 +24,7 @@
* Flag Class
* This handles flagging of songs, albums and artists
*/
-class Flag {
+class Flag extends database_object {
public $id;
public $user;
@@ -45,7 +45,7 @@ class Flag {
*/
public function __construct($flag_id) {
- $info = $this->_get_info($flag_id);
+ $info = $this->get_info($flag_id,'flagged');
foreach ($info as $key=>$value) {
$this->$key = $value;
@@ -56,21 +56,22 @@ class Flag {
} // Constructor
/**
- * _get_info
- * Private function for getting the information for this object from the database
+ * build_cache
+ * This takes an array of ids and builds up a nice little cache
+ * for us
*/
- private function _get_info($flag_id) {
+ public static function build_cache($ids) {
- $id = Dba::escape($flag_id);
+ $idlist = '(' . implode(',',$ids) . ')';
- $sql = "SELECT * FROM `flagged` WHERE `id`='$id'";
- $db_results = Dba::query($sql);
+ $sql = "SELECT * FROM `flagged` WHERE `id` IN $idlist";
+ $db_results = Dba::query($sql);
- $results = Dba::fetch_assoc($db_results);
-
- return $results;
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('flagged',$row['id'],$row);
+ }
- } // _get_info
+ } // build_cache
/**
* get_recent
@@ -95,19 +96,24 @@ class Flag {
} // get_recent
/**
- * get_total
- * Returns the total number of flagged objects
+ * get_disabled
+ * This returns all of the songs that have been disabled, this is
+ * a form of being flagged
*/
- function get_total() {
+ public static function get_disabled() {
- $sql = "SELECT COUNT(id) FROM flagged";
- $db_results = mysql_query($sql, dbh());
+ $sql = "SELECT `id` FROM `song` WHERE `enabled`='0'";
+ $db_results = Dba::query($sql);
- $results = mysql_fetch_row($db_results);
+ $results = array();
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return $results['0'];
+ return $results;
- } // get_total
+ } // get_disabled
/**
* get_all
diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php
index 3499cd94..22f4ea4a 100644
--- a/lib/class/tag.class.php
+++ b/lib/class/tag.class.php
@@ -71,30 +71,6 @@ class Tag extends database_object {
} // construct_from_name
/**
- * get_info
- * This takes the id and returns an array of information, checks the cache
- * to see what's up
- */
- private function get_info($id) {
-
- $id = intval($id);
-
- if (parent::is_cached('tag',$id)) {
- return parent::get_from_cache('tag',$id);
- }
-
- $sql = "SELECT * FROM `tag` WHERE `id`='$id'";
- $db_results = Dba::query($sql);
-
- $results = Dba::fetch_assoc($db_results);
-
- parent::add_to_cache('tag',$id,$results);
-
- return $results;
-
- } // get_info
-
- /**
* build_cache
* This takes an array of object ids and caches all of their information
* in a single query, cuts down on the connections