CC-4095: Media Library -> Playlist: dj user can delete the playlist owned by

others on some situation.

- fixed
This commit is contained in:
James 2012-07-10 17:09:21 -04:00
parent d90d83200e
commit 39506740eb
3 changed files with 37 additions and 22 deletions

View file

@ -802,12 +802,33 @@ class Application_Model_Playlist {
* Delete playlists that match the ids..
* @param array $p_ids
*/
public static function DeletePlaylists($p_ids)
public static function DeletePlaylists($p_ids, $p_userId)
{
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
$leftOver = self::playlistsNotOwnedByUser($p_ids, $p_userId);
if(count($leftOver) == 0){
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
}else{
throw new PlaylistNoPermissionException;
}
}
// This function returns that are not owen by $p_user_id among $p_ids
private static function playlistsNotOwnedByUser($p_ids, $p_userId){
$ownedByUser = CcPlaylistQuery::create()->filterByDbCreatorId($p_userId)->find()->getData();
$selectedPls = $p_ids;
$ownedPls = array();
foreach($ownedByUser as $pl){
if( in_array($pl->getDbId(), $selectedPls) ){
$ownedPls[] = $pl->getDbId();
}
}
$leftOvers = array_diff($selectedPls, $ownedPls);
return $leftOvers;
}
} // class Playlist
class PlaylistNotFoundException extends Exception {}
class PlaylistNoPermissionException extends Exception {}
class PlaylistOutDatedException extends Exception {}