2015-08-31 16:19:23 +02:00
|
|
|
<?php
|
|
|
|
|
2015-10-24 03:22:14 +02:00
|
|
|
namespace Poniverse\Ponyfm\Commands;
|
2015-08-31 16:19:23 +02:00
|
|
|
|
2015-10-24 03:22:14 +02:00
|
|
|
use Poniverse\Ponyfm\Playlist;
|
2015-08-31 16:19:23 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
class DeletePlaylistCommand extends CommandBase
|
|
|
|
{
|
|
|
|
private $_playlistId;
|
|
|
|
private $_playlist;
|
|
|
|
|
|
|
|
function __construct($playlistId)
|
|
|
|
{
|
|
|
|
$this->_playlistId = $playlistId;
|
|
|
|
$this->_playlist = Playlist::find($playlistId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
return $this->_playlist && $user != null && $this->_playlist->user_id == $user->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
* @return CommandResponse
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
foreach ($this->_playlist->pins as $pin) {
|
|
|
|
$pin->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_playlist->delete();
|
|
|
|
|
|
|
|
return CommandResponse::succeed();
|
|
|
|
}
|
|
|
|
}
|