summaryrefslogtreecommitdiffstats
path: root/lib/class
diff options
context:
space:
mode:
Diffstat (limited to 'lib/class')
-rw-r--r--lib/class/ajax.class.php2
-rw-r--r--lib/class/art.class.php65
-rw-r--r--lib/class/artist.class.php47
-rw-r--r--lib/class/browse.class.php2
-rw-r--r--lib/class/catalog.class.php2
-rw-r--r--lib/class/query.class.php71
6 files changed, 134 insertions, 55 deletions
diff --git a/lib/class/ajax.class.php b/lib/class/ajax.class.php
index 1b69e17a..a1059e2e 100644
--- a/lib/class/ajax.class.php
+++ b/lib/class/ajax.class.php
@@ -93,7 +93,7 @@ class Ajax {
else {
$ajax_string = "ajaxPut('$url',$source_txt)";
}
-
+
return $ajax_string;
} // action
diff --git a/lib/class/art.class.php b/lib/class/art.class.php
index b2829198..d7066a11 100644
--- a/lib/class/art.class.php
+++ b/lib/class/art.class.php
@@ -534,18 +534,43 @@ class Art extends database_object {
$db_results = Dba::write($sql);
} // clean
+ public function checkOrderDB($method, $gatherAll) {
+
+ if( !($gatherAll) ) {
+ return true;
+ }
+
+ $config = Config::get('art_order');
+ $config = array($config);
+ $art_order = array();
+
+
+ for( $i = 0; $i < sizeof($config[0]); $i++) {
+ $art_order[$config[0][$i]] = $i;
+ }
+
+ $sql = 'SELECT object_id FROM image WHERE object_id = ' . $this->uid;
+ debug_event('Art', $sql, 6);
+ $db_results = Dba::read($sql);
+
+ if( $art_order['db'] < $art_order[$method] && (Dba::num_rows($db_results) != 0) ) {
+ return false;
+ } else {
+ return true;
+ }
+ }
/**
* gather
* This tries to get the art in question
*/
- public function gather($options = array(), $limit = false) {
+ public function gather($options = array(), $limit = false, $gatherAll = false) {
// Define vars
$results = array();
switch ($this->type) {
case 'album':
- $allowed_methods = array('db','lastfm','folder','amazon','google','musicbrainz','tags');
+ $allowed_methods = array('lastfm','folder','amazon','google','musicbrainz','tag');
break;
case 'artist':
$allowed_methods = array();
@@ -561,38 +586,38 @@ class Art extends database_object {
/* If it's not set */
if (empty($config)) {
// They don't want art!
- debug_event('Art', 'art_order is empty, skipping art gathering', 3);
return array();
}
elseif (!is_array($config)) {
$config = array($config);
}
- debug_event('Art','Searching using:' . print_r($config, true), 3);
+ debug_event('Art','Searching using:' . print_r($config, true),3);
foreach ($config as $method) {
$data = array();
- if (!in_array($method, $allowed_methods)) {
- debug_event('Art', "$method not in allowed_methods, skipping", 3);
- continue;
- }
+ debug_event('Art',"method used " .$method_name,3);
$method_name = "gather_" . $method;
-
if (in_array($method_name, $methods)) {
- debug_event('Art', "Method used: $method_name", 3);
// Some of these take options!
switch ($method_name) {
case 'gather_amazon':
- $data = $this->{$method_name}($limit, $options['keyword']);
+ if($this->checkOrderDB($method,$gatherAll)) {
+ $data = $this->{$method_name}($limit, $options['keyword']);
+ }
break;
case 'gather_lastfm':
- $data = $this->{$method_name}($limit, $options);
+ if($this->checkOrderDB($method,$gatherAll)) {
+ $data = $this->{$method_name}($limit, $options);
+ }
break;
default:
- $data = $this->{$method_name}($limit);
+ if($this->checkOrderDB($method,$gatherAll)) {
+ $data = $this->{$method_name}($limit);
+ }
break;
}
@@ -604,9 +629,6 @@ class Art extends database_object {
}
} // if the method exists
- else {
- debug_event("Art", "$method_name not defined", 1);
- }
} // end foreach
@@ -620,17 +642,6 @@ class Art extends database_object {
///////////////////////////////////////////////////////////////////////
/**
- * gather_db
- * This function retrieves art that's already in the database
- */
- public function gather_db($limit = null) {
- if ($this->get_db()) {
- return array('db' => true);
- }
- return array();
- }
-
- /**
* gather_musicbrainz
* This function retrieves art based on MusicBrainz' Advanced
* Relationships
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index f7638b94..02a7c7b7 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -32,6 +32,7 @@ class Artist extends database_object {
public $albums;
public $prefix;
public $mbid; // MusicBrainz ID
+ public $catalog_id;
// Constructed vars
public $_fake = false; // Set if construct_from_array() used
@@ -41,11 +42,12 @@ class Artist extends database_object {
* Artist class, for modifing a artist
* Takes the ID of the artist and pulls the info from the db
*/
- public function __construct($id='') {
+ public function __construct($id='',$catalog_init=0) {
/* If they failed to pass in an id, just run for it */
if (!$id) { return false; }
+ $this->catalog_id = $catalog_init;
/* Get the information from the db */
$info = $this->get_info($id);
@@ -93,8 +95,9 @@ class Artist extends database_object {
// If we need to also pull the extra information, this is normally only used when we are doing the human display
if ($extra) {
- $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " .
- "WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`";
+ $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`";
+
+ debug_event("Artist", "build_cache sql: " . $sql, "6");
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
@@ -130,12 +133,19 @@ class Artist extends database_object {
* gets the album ids that this artist is a part
* of
*/
- public function get_albums() {
+ public function get_albums($catalog) {
+
+ if($catalog) {
+ $catalog_join = "LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
+ $catalog_where = "AND `catalog`.`id` = '$catalog'";
+ }
$results = array();
- $sql = "SELECT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` " .
- "WHERE `song`.`artist`='$this->id' GROUP BY `album`.`id` ORDER BY `album`.`name`,`album`.`disk`,`album`.`year`";
+ $sql = "SELECT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` $catalog_join " .
+ "WHERE `song`.`artist`='$this->id' $catalog_where GROUP BY `album`.`id` ORDER BY `album`.`name`,`album`.`disk`,`album`.`year`";
+
+ debug_event("Artist", "$sql", "6");
$db_results = Dba::read($sql);
while ($r = Dba::fetch_assoc($db_results)) {
@@ -186,16 +196,21 @@ class Artist extends database_object {
* _get_extra info
* This returns the extra information for the artist, this means totals etc
*/
- private function _get_extra_info() {
+ private function _get_extra_info($catalog=FALSE) {
// Try to find it in the cache and save ourselves the trouble
- if (parent::is_cached('artist_extra',$this->id)) {
+ if (parent::is_cached('artist_extra',$this->id) ) {
$row = parent::get_from_cache('artist_extra',$this->id);
}
else {
$uid = Dba::escape($this->id);
- $sql = "SELECT `song`.`artist`,COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " .
- "WHERE `song`.`artist`='$uid' GROUP BY `song`.`artist`";
+ $sql = "SELECT `song`.`artist`,COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` WHERE `song`.`artist`='$uid' ";
+ if ($catalog) {
+ $sql .= "AND (`song`.`catalog` = '$catalog') ";
+ }
+
+ $sql .= "GROUP BY `song`.`artist`";
+
$db_results = Dba::read($sql);
$row = Dba::fetch_assoc($db_results);
parent::add_to_cache('artist_extra',$row['artist'],$row);
@@ -227,11 +242,15 @@ class Artist extends database_object {
// If this is a fake object, we're done here
if ($this->_fake) { return true; }
- $this->f_name_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->id . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>";
- $this->f_link = Config::get('web_path') . '/artists.php?action=show&amp;artist=' . $this->id;
-
+ if ($this->catalog_id) {
+ $this->f_name_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;catalog=" . $this->catalog_id . "&amp;artist=" . $this->id . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>";
+ $this->f_link = Config::get('web_path') . '/artists.php?action=show&amp;catalog=' . $this->catalog_id . '&amp;artist=' . $this->id;
+ } else {
+ $this->f_name_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->id . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>";
+ $this->f_link = Config::get('web_path') . '/artists.php?action=show&amp;artist=' . $this->id;
+ }
// Get the counts
- $extra_info = $this->_get_extra_info();
+ $extra_info = $this->_get_extra_info($this->catalog_id);
//Format the new time thingy that we just got
$min = sprintf("%02d",(floor($extra_info['time']/60)%60));
diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php
index 5feaefde..8e6eba11 100644
--- a/lib/class/browse.class.php
+++ b/lib/class/browse.class.php
@@ -110,6 +110,8 @@ class Browse extends Query {
}
elseif ($filter_value = $this->get_filter('starts_with')) {
$match = ' (' . $filter_value . ')';
+ } elseif ($filter_value = $this->get_filter('catalog')) {
+ $match = '(' . $filter_value . ')';
}
$type = $this->get_type();
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index f823d01d..4c4e0768 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -680,7 +680,7 @@ class Catalog extends database_object {
);
// Return results
- $results = $art->gather($options, 1);
+ $results = $art->gather($options,1,true);
if (count($results)) {
// Pull the string representation from the source
diff --git a/lib/class/query.class.php b/lib/class/query.class.php
index 65ee0dc7..3a9476f9 100644
--- a/lib/class/query.class.php
+++ b/lib/class/query.class.php
@@ -25,9 +25,11 @@
* This handles all of the sql/filtering for the ampache database
* this was seperated out from browse to accomodate Dynamic Playlists
*/
+
class Query {
public $id;
+ public $catalog;
protected $_state = array();
protected $_cache;
@@ -41,7 +43,7 @@ class Query {
*/
public function __construct($id = null) {
$sid = Dba::escape(session_id());
-
+
if (is_null($id)) {
$this->reset();
$data = Dba::escape(serialize($this->_state));
@@ -50,6 +52,7 @@ class Query {
"VALUES('$sid', '$data')";
$db_results = Dba::write($sql);
$this->id = Dba::insert_id();
+
return true;
}
@@ -88,7 +91,8 @@ class Query {
'show_art',
'starts_with',
'exact_match',
- 'alpha_match'
+ 'alpha_match',
+ 'catalog'
),
'artist' => array(
'add_lt',
@@ -98,7 +102,8 @@ class Query {
'exact_match',
'alpha_match',
'starts_with',
- 'tag'
+ 'tag',
+ 'catalog'
),
'song' => array(
'add_lt',
@@ -108,7 +113,8 @@ class Query {
'exact_match',
'alpha_match',
'starts_with',
- 'tag'
+ 'tag',
+ 'catalog'
),
'live_stream' => array(
'alpha_match',
@@ -223,6 +229,7 @@ class Query {
}
break;
case 'artist':
+ case 'catalog':
case 'album':
$this->_state['filter'][$key] = $value;
break;
@@ -509,6 +516,11 @@ class Query {
} // set_offset
+ public function set_catalog( $catalog_number ) {
+ $this->catalog = $catalog_number;
+ debug_event("Catalog", "set catalog id: " . $this->catalog, "5");
+ }
+
/**
* set_select
* This appends more information to the select part of the SQL
@@ -684,7 +696,11 @@ class Query {
$sql = "SELECT %%SELECT%% FROM `album` ";
break;
case 'artist':
- $this->set_select("DISTINCT(`artist`.`id`)");
+ $this->set_select("`artist`.`id`");
+ $sql = "SELECT %%SELECT%% FROM `artist` ";
+ break;
+ case 'catalog':
+ $this->set_select("`artist`.`name`");
$sql = "SELECT %%SELECT%% FROM `artist` ";
break;
case 'user':
@@ -761,11 +777,12 @@ class Query {
if (!is_array($this->_state['filter'])) {
return '';
}
-
+
$sql = "WHERE 1=1 AND ";
foreach ($this->_state['filter']
as $key => $value) {
+
$sql .= $this->sql_filter($key, $value);
}
@@ -862,9 +879,13 @@ class Query {
$having_sql = $this->get_having_sql();
$order_sql = $this->get_sort_sql();
$limit_sql = $limit ? $this->get_limit_sql() : '';
-
- $final_sql = $sql . $join_sql . $filter_sql . $having_sql . $order_sql . $limit_sql;
-
+ $final_sql = $sql . $join_sql . $filter_sql . $having_sql;
+
+ if( $this->get_type() == 'artist' ) {
+ $final_sql .= " GROUP BY `" . $this->get_type() . "`.`name` ";
+ }
+ $final_sql .= $order_sql . $limit_sql;
+ debug_event("Catalog", "catalog sql: " . $final_sql, "6");
return $final_sql;
} // get_sql
@@ -912,6 +933,7 @@ class Query {
$filter_sql = '';
switch ($this->get_type()) {
+
case 'song':
switch($filter) {
case 'tag':
@@ -931,6 +953,9 @@ class Query {
break;
case 'starts_with':
$filter_sql = " `song`.`title` LIKE '" . Dba::escape($value) . "%' AND ";
+ if( $this->catalog != 0 ) {
+ $filter_sql .= " `song`.`catalog` = '" . $this->catalog . "' AND ";
+ }
break;
case 'unplayed':
$filter_sql = " `song`.`played`='0' AND ";
@@ -954,9 +979,9 @@ class Query {
$filter_sql = " `song`.`update_time` <= '" . Dba::escape($value) . "' AND ";
break;
case 'catalog':
- $catalogs = $GLOBALS['user']->get_catalogs();
- if (!count($catalogs)) { break; }
- $filter_sql .= " `song`.`catalog` IN (" . implode(',',$GLOBALS['user']->get_catalogs()) . ") AND ";
+ if($value != 0) {
+ $filter_sql = " `song`.`catalog` = '$value' AND ";
+ }
break;
default:
// Rien a faire
@@ -972,7 +997,11 @@ class Query {
$filter_sql = " `album`.`name` LIKE '%" . Dba::escape($value) . "%' AND ";
break;
case 'starts_with':
+ $this->set_join('left', '`song`', '`album`.`id`', '`song`.`album`', 100);
$filter_sql = " `album`.`name` LIKE '" . Dba::escape($value) . "%' AND ";
+ if( $this->catalog != 0 ) {
+ $filter_sql .= "`song`.`catalog` = '" . $this->catalog . "' AND ";
+ }
break;
case 'artist':
$filter_sql = " `artist`.`id` = '". Dba::escape($value) . "' AND ";
@@ -985,6 +1014,13 @@ class Query {
$this->set_join('left', '`song`', '`song`.`album`', '`album`.`id`', 100);
$filter_sql = " `song`.`addition_time` >= '" . Dba::escape($value) . "' AND ";
break;
+ case 'catalog':
+ if($value != 0) {
+ $this->set_join('left','`song`','`album`.`id`','`song`.`album`', 100);
+ $this->set_join('left','`catalog`','`song`.`catalog`','`catalog`.`id`', 100);
+ $filter_sql = " (`song`.`catalog` = '$value') AND ";
+ }
+ break;
case 'update_lt':
$this->set_join('left', '`song`', '`song`.`album`', '`album`.`id`', 100);
$filter_sql = " `song`.`update_time` <= '" . Dba::escape($value) . "' AND ";
@@ -1000,6 +1036,13 @@ class Query {
break;
case 'artist':
switch($filter) {
+ case 'catalog':
+ if($value != 0) {
+ $this->set_join('left','`song`','`artist`.`id`','`song`.`artist`', 100);
+ $this->set_join('left','`catalog`','`song`.`catalog`','`catalog`.`id`', 100);
+ $filter_sql = " (`catalog`.`id` = '$value') AND ";
+ }
+ break;
case 'exact_match':
$filter_sql = " `artist`.`name` = '" . Dba::escape($value) . "' AND ";
break;
@@ -1007,7 +1050,11 @@ class Query {
$filter_sql = " `artist`.`name` LIKE '%" . Dba::escape($value) . "%' AND ";
break;
case 'starts_with':
+ $this->set_join('left', '`song`', '`artist`.`id`', '`song`.`artist`', 100);
$filter_sql = " `artist`.`name` LIKE '" . Dba::escape($value) . "%' AND ";
+ if( $this->catalog != 0 ) {
+ $filter_sql .= "`song`.`catalog` = '" . $this->catalog . "' AND ";
+ }
break;
case 'add_lt':
$this->set_join('left', '`song`', '`song`.`artist`', '`artist`.`id`', 100);