From 24988616b3289ce5c64571dad73f2576f87a6185 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Wed, 22 Aug 2012 14:03:11 -0400 Subject: [PATCH] CC-1665: Scheduled stream rebroadcasting and recording -current Library session object should not be stored as a property of the Controller class. -fixed --- .../controllers/LibraryController.php | 79 ++++++++++++++++--- .../controllers/PlaylistController.php | 16 ++-- 2 files changed, 76 insertions(+), 19 deletions(-) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index a23f2f1a7..3734b1573 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -8,7 +8,6 @@ class LibraryController extends Zend_Controller_Action { protected $obj_sess = null; - protected $search_sess = null; public function init() { @@ -23,8 +22,6 @@ class LibraryController extends Zend_Controller_Action ->addActionContext('set-num-entries', 'json') ->initContext(); - $this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); - $this->search_sess = new Zend_Session_Namespace("search"); } public function indexAction() @@ -59,32 +56,90 @@ class LibraryController extends Zend_Controller_Action try { - if (isset($this->obj_sess->id)) { - Logging::info($this->obj_sess->type); + $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); + //Application_Model_Library::changePlaylist(null, null); + if (isset($obj_sess->id)) { + Logging::info($obj_sess->type); $objInfo = Application_Model_Library::getObjInfo($this->obj_sess->type); - Logging::info($this->obj_sess->id); - $obj = new $objInfo['className']($this->obj_sess->id); + Logging::info($obj_sess->id); + $obj = new $objInfo['className']($obj_sess->id); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); if ($isAdminOrPM || $obj->getCreatorId() == $userInfo->id) { $this->view->obj = $obj; - if ($this->obj_sess->type == "block") { + if ($obj_sess->type == "block") { $form = new Application_Form_SmartBlockCriteria(); - $form->startForm($this->obj_sess->id); + $form->startForm($obj_sess->id); $this->view->form = $form; } } $formatter = new LengthFormatter($obj->getLength()); $this->view->length = $formatter->format(); - $this->view->type = $this->obj_sess->type; + $this->view->type = $obj_sess->type; } } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($this->obj_sess->type); + $this->playlistNotFound($obj_sess->type); } catch (Exception $e) { - $this->playlistUnknownError($e); + $this->playlistNotFound($obj_sess->type); + //$this->playlistUnknownError($e); + } + } + + private function playlistNotFound($p_type) + { + $this->view->error = "{$p_type} not found"; + + Logging::info("{$p_type} not found"); + Application_Model_Library::changePlaylist(null, $p_type); + $this->createFullResponse(null); + } + + private function playlistUnknownError($e) + { + $this->view->error = "Something went wrong."; + + Logging::info("{$e->getFile()}"); + Logging::info("{$e->getLine()}"); + Logging::info("{$e->getMessage()}"); + } + + private function createFullResponse($obj = null, $isJson = false) + { + $isBlock = false; + $viewPath = 'playlist/playlist.phtml'; + if ($obj instanceof Application_Model_Block) { + $isBlock = true; + $viewPath = 'playlist/smart-block.phtml'; + } + + if (isset($obj)) { + $formatter = new LengthFormatter($obj->getLength()); + $this->view->length = $formatter->format(); + + if ($isBlock) { + $form = new Application_Form_SmartBlockCriteria(); + $form->removeDecorator('DtDdWrapper'); + $form->startForm($obj->getId()); + + $this->view->form = $form; + $this->view->obj = $obj; + $this->view->id = $obj->getId(); + if ($isJson) { + return $this->view->render($viewPath); + } else { + $this->view->html = $this->view->render($viewPath); + } + } else { + $this->view->obj = $obj; + $this->view->id = $obj->getId(); + $this->view->html = $this->view->render($viewPath); + unset($this->view->obj); + } + } else { + $this->view->html = $this->view->render($viewPath); } } diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 8631af34c..9e3ea0380 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -2,7 +2,6 @@ class PlaylistController extends Zend_Controller_Action { - protected $obj_sess = null; public function init() { @@ -28,7 +27,6 @@ class PlaylistController extends Zend_Controller_Action ->addActionContext('get-block-info', 'json') ->initContext(); - $this->obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); } private function getPlaylist($p_type) @@ -36,8 +34,9 @@ class PlaylistController extends Zend_Controller_Action $obj = null; $objInfo = Application_Model_Library::getObjInfo($p_type); - if (isset($this->obj_sess->id)) { - $obj = new $objInfo['className']($this->obj_sess->id); + $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); + if (isset($obj_sess->id)) { + $obj = new $objInfo['className']($obj_sess->id); $modified = $this->_getParam('modified', null); if ($obj->getLastModified("U") !== $modified) { @@ -205,14 +204,17 @@ class PlaylistController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); + + $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); + try { - Logging::info("Currently active {$type} {$this->obj_sess->id}"); - if (in_array($this->obj_sess->id, $ids)) { + Logging::info("Currently active {$type} {$obj_sess->id}"); + if (in_array($obj_sess->id, $ids)) { Logging::info("Deleting currently active {$type}"); Application_Model_Library::changePlaylist(null, $type); } else { Logging::info("Not deleting currently active {$type}"); - $obj = new $objInfo['className']($this->obj_sess->id); + $obj = new $objInfo['className']($obj_sess->id); } if (strcmp($objInfo['className'], 'Application_Model_Playlist')==0) {