only show songs for which the current user has songs indexed

This commit is contained in:
Robin Appelman 2011-07-26 22:21:28 +02:00
parent d6d38ac3fa
commit 344b7f548b
2 changed files with 15 additions and 10 deletions

View File

@ -67,10 +67,12 @@ if($arguments['action']){
$artists=OC_MEDIA_COLLECTION::getArtists(); $artists=OC_MEDIA_COLLECTION::getArtists();
foreach($artists as &$artist){ foreach($artists as &$artist){
$artist['albums']=OC_MEDIA_COLLECTION::getAlbums($artist['artist_id']); $artist['albums']=OC_MEDIA_COLLECTION::getAlbums($artist['artist_id']);
$artistHasSongs=false;
foreach($artist['albums'] as &$album){ foreach($artist['albums'] as &$album){
$album['songs']=OC_MEDIA_COLLECTION::getSongs($artist['artist_id'],$album['album_id']); $album['songs']=OC_MEDIA_COLLECTION::getSongs($artist['artist_id'],$album['album_id']);
} }
} }
echo json_encode($artists); echo json_encode($artists);
break; break;
case 'scan': case 'scan':

View File

@ -123,13 +123,14 @@ class OC_MEDIA_COLLECTION{
if(!$exact and $search!='%'){ if(!$exact and $search!='%'){
$search="%$search%"; $search="%$search%";
} }
$query=OC_DB::prepare("SELECT * FROM *PREFIX*media_artists WHERE artist_name LIKE ?"); $query=OC_DB::prepare("SELECT DISTINCT *PREFIX*media_artists.artist_name AS name , *PREFIX*media_artists.artist_id AS id FROM *PREFIX*media_artists
$artists=$query->execute(array($search))->fetchAll(); INNER JOIN *PREFIX*media_songs ON *PREFIX*media_artists.artist_id=*PREFIX*media_songs.song_artist WHERE artist_name LIKE ? AND *PREFIX*media_songs.song_user=?");
if(is_array($artists)){ $artists=$query->execute(array($search,OC_USER::getUser()))->fetchAll();
return $artists; $result=array();
}else{ foreach($artists as $artist){
return array(); $result[$artist['id']]=array('artist_name'=>$artist['name'],'artist_id'=>$artist['id']);
} }
return $result;
} }
/** /**
@ -175,12 +176,14 @@ class OC_MEDIA_COLLECTION{
} }
$query=OC_DB::prepare($cmd); $query=OC_DB::prepare($cmd);
$albums=$query->execute($params)->fetchAll(); $albums=$query->execute($params)->fetchAll();
if(is_array($albums)){ $result=array();
return $albums; foreach($albums as $album){
}else{ if(count(self::getSongs($album['album_artist'],$album['album_id']))){
return array(); $result[$album['album_id']]=$album;
} }
} }
return $result;
}
/** /**
* Add an album to the database * Add an album to the database