CC-5450 : Refactor Media Management

fixing up services so controllers will just use one instance.
This commit is contained in:
Naomi 2013-11-27 18:21:22 -05:00
parent 152f44e093
commit cf34a030de
1 changed files with 12 additions and 23 deletions

View File

@ -18,14 +18,15 @@ class PlaylistController extends Zend_Controller_Action
->addActionContext('shuffle', 'json') ->addActionContext('shuffle', 'json')
->addActionContext('clear', 'json') ->addActionContext('clear', 'json')
->initContext(); ->initContext();
$this->mediaService = new Application_Service_MediaService();
$this->playlistService = new Application_Service_PlaylistService();
} }
private function getPlaylist() { private function getPlaylist() {
$mediaService = new Application_Service_MediaService();
$playlist = $mediaService->getSessionMediaObject();
return $playlist; return $this->mediaService->getSessionMediaObject();
} }
private function createUpdateResponse($obj) private function createUpdateResponse($obj)
@ -61,9 +62,7 @@ class PlaylistController extends Zend_Controller_Action
$playlist = new Playlist(); $playlist = new Playlist();
$playlist->save(); $playlist->save();
$mediaService = new Application_Service_MediaService(); $this->mediaService->setSessionMediaObject($playlist);
$mediaService->setSessionMediaObject($playlist);
$this->createFullResponse($playlist); $this->createFullResponse($playlist);
} }
@ -76,11 +75,9 @@ class PlaylistController extends Zend_Controller_Action
{ {
try { try {
$playlist = $this->getPlaylist(); $playlist = $this->getPlaylist();
$playlistService = new Application_Service_PlaylistService();
$playlistService->deletePlaylist($playlist);
$mediaService->setSessionMediaObject(null); $this->playlistService->deletePlaylist($playlist);
$this->mediaService->setSessionMediaObject(null);
$this->view->html = $this->view->render('playlist/none.phtml'); $this->view->html = $this->view->render('playlist/none.phtml');
} }
@ -99,9 +96,7 @@ class PlaylistController extends Zend_Controller_Action
try { try {
$playlist = $this->getPlaylist(); $playlist = $this->getPlaylist();
$playlistService = new Application_Service_PlaylistService(); $this->playlistService->addMedia($playlist, $ids, true);
$playlistService->addMedia($playlist, $ids, true);
$this->createUpdateResponse($playlist); $this->createUpdateResponse($playlist);
} }
catch (Exception $e) { catch (Exception $e) {
@ -114,9 +109,7 @@ class PlaylistController extends Zend_Controller_Action
try { try {
$playlist = $this->getPlaylist(); $playlist = $this->getPlaylist();
$playlistService = new Application_Service_PlaylistService(); $this->playlistService->clearPlaylist($playlist);
$playlistService->clearPlaylist($playlist);
$this->createUpdateResponse($playlist); $this->createUpdateResponse($playlist);
} }
catch (Exception $e) { catch (Exception $e) {
@ -129,9 +122,7 @@ class PlaylistController extends Zend_Controller_Action
try { try {
$playlist = $this->getPlaylist(); $playlist = $this->getPlaylist();
$playlistService = new Application_Service_PlaylistService(); $this->playlistService->shufflePlaylist($playlist);
$playlistService->shufflePlaylist($playlist);
$this->createUpdateResponse($playlist); $this->createUpdateResponse($playlist);
} }
catch (Exception $e) { catch (Exception $e) {
@ -148,9 +139,7 @@ class PlaylistController extends Zend_Controller_Action
try { try {
$playlist = $this->getPlaylist(); $playlist = $this->getPlaylist();
$playlistService = new Application_Service_PlaylistService(); $this->playlistService->savePlaylist($playlist, $info);
$playlistService->savePlaylist($playlist, $info);
$this->createUpdateResponse($playlist); $this->createUpdateResponse($playlist);
} }
catch (Exception $e) { catch (Exception $e) {