diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 852078675..7173f30b5 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -33,11 +33,11 @@ date_default_timezone_set(Application_Model_Preference::GetTimezone()); Zend_Validate::setDefaultNamespaces("Zend"); $front = Zend_Controller_Front::getInstance(); -$front->registerPlugin(new RabbitMqPlugin()); +$front->registerPlugin(new RabbitMqPlugin()); Logging::debug($_SERVER['REQUEST_URI']); -/* The bootstrap class should only be used to initialize actions that return a view. +/* The bootstrap class should only be used to initialize actions that return a view. Actions that return JSON will not use the bootstrap class! */ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { @@ -56,23 +56,25 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view->headLink()->appendStylesheet($baseUrl.'/css/redmond/jquery-ui-1.8.8.custom.css?'.filemtime($baseDir.'/css/redmond/jquery-ui-1.8.8.custom.css')); $view->headLink()->appendStylesheet($baseUrl.'/css/pro_dropdown_3.css?'.filemtime($baseDir.'/css/pro_dropdown_3.css')); - $view->headLink()->appendStylesheet($baseUrl.'/css/qtip/jquery.qtip.min.css?'.filemtime($baseDir.'/css/qtip/jquery.qtip.min.css')); + $view->headLink()->appendStylesheet($baseUrl.'/css/qtip/jquery.qtip.css?'.filemtime($baseDir.'/css/qtip/jquery.qtip.min.css')); $view->headLink()->appendStylesheet($baseUrl.'/css/styles.css?'.filemtime($baseDir.'/css/styles.css')); + } protected function _initHeadScript() { global $CC_CONFIG; - + $view = $this->getResource('view'); $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); $baseDir = dirname($_SERVER['SCRIPT_FILENAME']); - $view->headScript()->appendFile($baseUrl.'/js/libs/jquery-1.5.2.min.js?'.filemtime($baseDir.'/js/libs/jquery-1.5.2.min.js'),'text/javascript'); - $view->headScript()->appendFile($baseUrl.'/js/libs/jquery-ui-1.8.11.custom.min.js?'.filemtime($baseDir.'/js/libs/jquery-ui-1.8.11.custom.min.js'),'text/javascript'); + $view->headScript()->appendFile($baseUrl.'/js/libs/jquery-1.7.1.min.js?'.filemtime($baseDir.'/js/libs/jquery-1.7.1.min.js'),'text/javascript'); + $view->headScript()->appendFile('https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js'); $view->headScript()->appendFile($baseUrl.'/js/libs/jquery.stickyPanel.js?'.filemtime($baseDir.'/js/libs/jquery.stickyPanel.js'),'text/javascript'); - $view->headScript()->appendFile($baseUrl.'/js/qtip/jquery.qtip2.min.js?'.filemtime($baseDir.'/js/qtip/jquery.qtip2.min.js'),'text/javascript'); + $view->headScript()->appendFile($baseUrl.'/js/qtip/jquery.qtip.min.js?'.filemtime($baseDir.'/js/qtip/jquery.qtip2.min.js'),'text/javascript'); $view->headScript()->appendFile($baseUrl.'/js/jplayer/jquery.jplayer.min.js?'.filemtime($baseDir.'/js/jplayer/jquery.jplayer.min.js')); + $view->headScript()->appendScript("var baseUrl='$baseUrl/'"); //scripts for now playing bar @@ -81,7 +83,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/versiontooltip.js?'.filemtime($baseDir.'/js/airtime/dashboard/versiontooltip.js'),'text/javascript'); $view->headScript()->appendFile($baseUrl.'/js/airtime/common/common.js?'.filemtime($baseDir.'/js/airtime/common/common.js'),'text/javascript'); - + if (Application_Model_Preference::GetPlanLevel() != "disabled" && $_SERVER['REQUEST_URI'] != '/Dashboard/stream-player') { $client_id = Application_Model_Preference::GetClientId(); @@ -109,12 +111,12 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { if (APPLICATION_ENV == "development"){ global $CC_DBC; - + $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('ZFDebug'); $options = array( - 'plugins' => array('Variables', + 'plugins' => array('Variables', 'Exception', 'Memory', 'Time') @@ -126,12 +128,12 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $frontController->registerPlugin($debug); } } - + protected function _initRouter() { $front = Zend_Controller_Front::getInstance(); $router = $front->getRouter(); - + $router->addRoute( 'password-change', new Zend_Controller_Router_Route('password-change/:user_id/:token', array( diff --git a/airtime_mvc/application/configs/ACL.php b/airtime_mvc/application/configs/ACL.php index 6f0581296..e3001cffc 100644 --- a/airtime_mvc/application/configs/ACL.php +++ b/airtime_mvc/application/configs/ACL.php @@ -24,6 +24,7 @@ $ccAcl->add(new Zend_Acl_Resource('library')) ->add(new Zend_Acl_Resource('dashboard')) ->add(new Zend_Acl_Resource('preference')) ->add(new Zend_Acl_Resource('recorder')) + ->add(new Zend_Acl_Resource('showbuilder')) ->add(new Zend_Acl_Resource('auth')); /** Creating permissions */ @@ -42,6 +43,7 @@ $ccAcl->allow('G', 'index') ->allow('H', 'library') ->allow('H', 'search') ->allow('H', 'playlist') + ->allow('H', 'showbuilder') ->allow('A', 'user') ->allow('A', 'systemstatus') ->allow('A', 'preference'); diff --git a/airtime_mvc/application/configs/navigation.php b/airtime_mvc/application/configs/navigation.php index 851cae36b..8ab913804 100644 --- a/airtime_mvc/application/configs/navigation.php +++ b/airtime_mvc/application/configs/navigation.php @@ -29,6 +29,13 @@ $pages = array( 'action' => 'index', 'resource' => 'library' ), + array( + 'label' => 'Airtimeline', + 'module' => 'default', + 'controller' => 'Showbuilder', + 'action' => 'index', + 'resource' => 'showbuilder' + ), array( 'label' => 'Calendar', 'module' => 'default', @@ -67,7 +74,7 @@ $pages = array( 'action' => 'stream-setting' ), array( - 'label' => + 'label' => Application_Model_Preference::GetPlanLevel() == 'disabled'?'Support Settings':'Station Information Settings', 'module' => 'default', 'controller' => 'Preference', diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 1068c403f..ab52d2e00 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -23,28 +23,40 @@ class LibraryController extends Zend_Controller_Action $this->search_sess = new Zend_Session_Namespace("search"); } - public function indexAction() + public function indexAction() { + + $this->_helper->layout->setLayout('library'); + + $this->view->headScript()->appendFile($this->view->baseUrl('/js/airtime/library/events/library_playlistbuilder.js'),'text/javascript'); + + $this->_helper->actionStack('library', 'library'); + $this->_helper->actionStack('index', 'playlist'); + } + + public function libraryAction() { $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); + $baseDir = dirname($_SERVER['SCRIPT_FILENAME']); - $this->view->headScript()->appendFile($baseUrl.'/js/contextmenu/jjmenu.js?'.filemtime($baseDir.'/js/contextmenu/jjmenu.js'),'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/contextmenu/jquery.contextMenu.js?'.filemtime($baseDir.'/js/contextmenu/jquery.contextMenu.js'),'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.js?'.filemtime($baseDir.'/js/datatables/js/jquery.dataTables.js'),'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js?'.filemtime($baseDir.'/js/datatables/plugin/dataTables.pluginAPI.js'),'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.filemtime($baseDir.'/js/datatables/plugin/dataTables.fnSetFilteringDelay.js'),'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColVis.js?'.filemtime($baseDir.'/js/datatables/plugin/dataTables.ColVis.js'),'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColReorder.js?'.filemtime($baseDir.'/js/datatables/plugin/dataTables.ColReorder.js'),'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColReorderResize.js?'.filemtime($baseDir.'/js/datatables/plugin/dataTables.ColReorderResize.js'),'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.FixedColumns.js?'.filemtime($baseDir.'/js/datatables/plugin/dataTables.FixedColumns.js'),'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.TableTools.js?'.filemtime($baseDir.'/js/datatables/plugin/dataTables.TableTools.js'),'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/library.js?'.filemtime($baseDir.'/js/airtime/library/library.js'),'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/advancedsearch.js?'.filemtime($baseDir.'/js/airtime/library/advancedsearch.js'),'text/javascript'); $this->view->headLink()->appendStylesheet($baseUrl.'/css/media_library.css?'.filemtime($baseDir.'/css/media_library.css')); - $this->view->headLink()->appendStylesheet($baseUrl.'/css/contextmenu.css?'.filemtime($baseDir.'/css/contextmenu.css')); + $this->view->headLink()->appendStylesheet($baseUrl.'/css/jquery.contextMenu.css?'.filemtime($baseDir.'/css/jquery.contextMenu.css')); $this->view->headLink()->appendStylesheet($baseUrl.'/css/datatables/css/ColVis.css?'.filemtime($baseDir.'/css/datatables/css/ColVis.css')); $this->view->headLink()->appendStylesheet($baseUrl.'/css/datatables/css/ColReorder.css?'.filemtime($baseDir.'/css/datatables/css/ColReorder.css')); + $this->view->headLink()->appendStylesheet($baseUrl.'/css/TableTools.css?'.filemtime($baseDir.'/css/TableTools.css')); - $this->_helper->layout->setLayout('library'); $this->_helper->viewRenderer->setResponseSegment('library'); $form = new Application_Form_AdvancedSearch(); @@ -54,8 +66,6 @@ class LibraryController extends Zend_Controller_Action $this->search_sess->next_row[1] = 2; $this->view->form = $form; $this->view->md = $this->search_sess->md; - - $this->_helper->actionStack('index', 'playlist'); } public function contextMenuAction() @@ -64,186 +74,137 @@ class LibraryController extends Zend_Controller_Action $id = $this->_getParam('id'); $type = $this->_getParam('type'); + //playlist||timeline + $screen = $this->_getParam('screen'); $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); - $params = '/format/json/id/#id#/type/#type#'; - - $paramsPop = str_replace('#id#', $id, $params); - $paramsPop = str_replace('#type#', $type, $paramsPop); - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $pl_sess = $this->pl_sess; + if ($type === "audioclip") { - if($type === "au") { + $file = Application_Model_StoredFile::Recall($id); - if(isset($pl_sess->id)) { - $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/add-item'.$params, 'callback' => 'window["setSPLContent"]'), - 'title' => 'Add to Playlist'); + $menu["edit"] = array("name"=> "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); + + if ($user->isAdmin()) { + $menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete"); } - $menu[] = array('action' => array('type' => 'gourl', 'url' => '/Library/edit-file-md/id/#id#'), - 'title' => 'Edit Metadata'); - - // added for downlaod - $id = $this->_getParam('id'); - - $file_id = $this->_getParam('id', null); - $file = Application_Model_StoredFile::Recall($file_id); - $url = $file->getRelativeFileUrl($baseUrl).'/download/true'; - $menu[] = array('action' => array('type' => 'gourl', 'url' => $url), - 'title' => 'Download'); + $menu["download"] = array("name" => "Download", "url" => $url); if (Application_Model_Preference::GetUploadToSoundcloudOption()) { - $text = "Upload to SoundCloud"; - if(!is_null($file->getSoundCloudId())){ - $text = "Re-upload to SoundCloud"; - } - $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Library/upload-file-soundcloud/id/#id#', - 'callback'=>"window['addProgressIcon']('$file_id')"),'title' => $text); + + //create a menu separator + $menu["sep1"] = "-----------"; + + //create a sub menu for Soundcloud actions. + $menu["soundcloud"] = array("name" => "Soundcloud", "icon" => "soundcloud", "items" => array()); $scid = $file->getSoundCloudId(); - if($scid > 0){ - $link_to_file = $file->getSoundCloudLinkToFile(); - $menu[] = array('action' => array('type' => 'fn', - 'callback' => "window['openFileOnSoundCloud']('$link_to_file')"), - 'title' => 'View on SoundCloud'); + if (!is_null($scid)){ + $text = "Re-upload to SoundCloud"; + } + else { + $text = "Upload to SoundCloud"; + } + + $menu["soundcloud"]["items"]["upload"] = array("name" => $text, "url" => "/library/upload-file-soundcloud/id/{$id}"); + + if ($scid > 0){ + $url = $file->getSoundCloudLinkToFile(); + $menu["soundcloud"]["items"]["view"] = array("name" => "View on Soundcloud", "url" => $url); } } - - if ($user->isAdmin()) { - $menu[] = array('action' => array('type' => 'fn', - 'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"), - 'title' => 'Delete'); - } } - else if($type === "pl") { + else if ($type === "playlist") { - if(!isset($pl_sess->id) || $pl_sess->id !== $id) { - $menu[] = array('action' => - array('type' => 'ajax', - 'url' => '/Playlist/edit'.$params, - 'callback' => 'window["openDiffSPL"]'), - 'title' => 'Edit'); - } - else if(isset($pl_sess->id) && $pl_sess->id === $id) { - $menu[] = array('action' => - array('type' => 'ajax', - 'url' => '/Playlist/close'.$params, - 'callback' => 'window["noOpenPL"]'), - 'title' => 'Close'); + if ($this->pl_sess->id !== $id && $screen == "playlist") { + $menu["edit"] = array("name"=> "Edit", "icon" => "edit"); } - $menu[] = array('action' => array('type' => 'fn', - 'callback' => "window['confirmDeletePlaylist']('$paramsPop')"), - 'title' => 'Delete'); - + $menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete"); } - //returns format jjmenu is looking for. - die(json_encode($menu)); + $this->view->items = $menu; } public function deleteAction() { - $id = $this->_getParam('id'); - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $user = new Application_Model_User($userInfo->id); + //array containing id and type of media to delete. + $mediaItems = $this->_getParam('media', null); - if ($user->isAdmin()) { + $user = Application_Model_User::GetCurrentUser(); - if (!is_null($id)) { - $file = Application_Model_StoredFile::Recall($id); + $files = array(); + $playlists = array(); - if (PEAR::isError($file)) { - $this->view->message = $file->getMessage(); - return; - } - else if(is_null($file)) { - $this->view->message = "file doesn't exist"; - return; - } + $message = null; - $res = $file->delete(true); + foreach ($mediaItems as $media) { - if (PEAR::isError($res)) { - $this->view->message = $res->getMessage(); - return; - } - else { - $res = settype($res, "integer"); - $data = array("filepath" => $file->getFilePath(), "delete" => $res); - Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); - } + if ($media["type"] === "audioclip") { + $files[] = intval($media["id"]); + } + else if ($media["type"] === "playlist") { + $playlists[] = intval($media["id"]); } - - $this->view->id = $id; } - } - - public function deleteGroupAction() - { - $ids = $this->_getParam('ids'); - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $user = new Application_Model_User($userInfo->id); - if ($user->isAdmin()) { + if (count($playlists)) { + Application_Model_Playlist::DeletePlaylists($playlists); + } - if (!is_null($ids)) { - foreach ($ids as $key => $id) { - $file = Application_Model_StoredFile::Recall($id); + if (!$user->isAdmin()) { + return; + } - if (PEAR::isError($file)) { - $this->view->message = $file->getMessage(); - return; - } - else if(is_null($file)) { - $this->view->message = "file doesn't exist"; - return; - } + foreach ($files as $id) { + Logging::log("deleting file {$id}"); - $res = $file->delete(); + $file = Application_Model_StoredFile::Recall($id); - if (PEAR::isError($res)) { - $this->view->message = $res->getMessage(); - return; - } - else { - $res = settype($res, "integer"); - $data = array("filepath" => $file->getFilePath(), "delete" => $res); - Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); - } + if (isset($file)) { + try { + $res = $file->delete(true); + } + //could throw a scheduled in future exception. + catch (Exception $e) { + $message = "Could not delete some scheduled files."; } - - $this->view->ids = $ids; } } + + if (isset($message)) { + $this->view->message = $message; + } } public function contentsAction() { - $post = $this->getRequest()->getPost(); - $datatables = Application_Model_StoredFile::searchFilesForPlaylistBuilder($post); - - //format clip lengh to 1 decimal - foreach($datatables["aaData"] as &$data){ - if($data['ftype'] == 'audioclip'){ + $params = $this->getRequest()->getParams(); + $datatables = Application_Model_StoredFile::searchFilesForPlaylistBuilder($params); + + //TODO move this to the datatables row callback. + foreach ($datatables["aaData"] as &$data) { + + if ($data['ftype'] == 'audioclip'){ $file = Application_Model_StoredFile::Recall($data['id']); $scid = $file->getSoundCloudId(); - if($scid == "-2"){ - $data['track_title'] .= ''; - }else if($scid == "-3"){ - $data['track_title'] .= ''; - }else if(!is_null($scid)){ - $data['track_title'] .= ''; + + if ($scid == "-2"){ + $data['track_title'] .= ''; + } + else if ($scid == "-3"){ + $data['track_title'] .= ''; + } + else if (!is_null($scid)){ + $data['track_title'] .= ''; } } - $sec = Application_Model_Playlist::playlistTimeToSeconds($data['length']); - $data['length'] = Application_Model_Playlist::secondsToPlaylistTime($sec); } die(json_encode($datatables)); @@ -284,13 +245,13 @@ class LibraryController extends Zend_Controller_Action $id = $this->_getParam('id'); $type = $this->_getParam('type'); - if($type == "au") { + if ($type == "audioclip") { $file = Application_Model_StoredFile::Recall($id); $this->view->type = $type; $this->view->md = $file->getMetadata(); } - else if($type == "pl") { - $file = Application_Model_Playlist::Recall($id); + else if ($type == "playlist") { + $file = new Application_Model_Playlist($id); $this->view->type = $type; $this->view->md = $file->getAllPLMetaData(); $this->view->contents = $file->getContents(); @@ -308,13 +269,15 @@ class LibraryController extends Zend_Controller_Action public function getUploadToSoundcloudStatusAction(){ $id = $this->_getParam('id'); $type = $this->_getParam('type'); - if($type == "show"){ + + if ($type == "show") { $show_instance = new Application_Model_ShowInstance($id); $this->view->sc_id = $show_instance->getSoundCloudFileId(); $file = $show_instance->getRecordedFile(); $this->view->error_code = $file->getSoundCloudErrorCode(); $this->view->error_msg = $file->getSoundCloudErrorMsg(); - }else{ + } + else if ($type == "file") { $file = Application_Model_StoredFile::Recall($id); $this->view->sc_id = $file->getSoundCloudId(); $this->view->error_code = $file->getSoundCloudErrorCode(); diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index b2b8c25ad..a136bd1a9 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -7,19 +7,16 @@ class PlaylistController extends Zend_Controller_Action public function init() { $ajaxContext = $this->_helper->getHelper('AjaxContext'); - $ajaxContext->addActionContext('add-item', 'json') - ->addActionContext('delete-item', 'json') - ->addActionContext('add-group', 'json') - ->addActionContext('delete-group', 'json') + $ajaxContext->addActionContext('add-items', 'json') + ->addActionContext('move-items', 'json') + ->addActionContext('delete-items', 'json') ->addActionContext('set-fade', 'json') ->addActionContext('set-cue', 'json') - ->addActionContext('move-item', 'json') - ->addActionContext('close', 'json') ->addActionContext('new', 'json') ->addActionContext('edit', 'json') - ->addActionContext('delete-active', 'json') ->addActionContext('delete', 'json') ->addActionContext('set-playlist-fades', 'json') + ->addActionContext('get-playlist-fades', 'json') ->addActionContext('set-playlist-name', 'json') ->addActionContext('set-playlist-description', 'json') ->initContext(); @@ -29,52 +26,41 @@ class PlaylistController extends Zend_Controller_Action private function getPlaylist() { - $pl_sess = $this->pl_sess; + $pl = null; - if(isset($pl_sess->id)) { - - $pl = Application_Model_Playlist::Recall($pl_sess->id); - if($pl === FALSE) { - unset($pl_sess->id); - return false; - } - return $pl; - }else{ - return false; + if (isset($this->pl_sess->id)) { + $pl = new Application_Model_Playlist($this->pl_sess->id); } + return $pl; } private function changePlaylist($pl_id) { - $pl_sess = $this->pl_sess; - - if(isset($pl_sess->id)) { - - $pl = Application_Model_Playlist::Recall($pl_sess->id); - if($pl !== FALSE) { - $this->closePlaylist($pl); - } - } - - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - - $pl = Application_Model_Playlist::Recall($pl_id); - if($pl === FALSE) { - return FALSE; - } - $pl->lock($userInfo->id); - $pl_sess->id = $pl_id; + $this->pl_sess->id = intval($pl_id); } - private function closePlaylist($pl) + private function createUpdateResponse($pl) { - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $res = $pl->unlock($userInfo->id); + $this->view->pl = $pl; + $this->view->html = $this->view->render('playlist/update.phtml'); + $this->view->name = $pl->getName(); + $this->view->length = $pl->getLength(); + $this->view->description = $pl->getDescription(); - $pl_sess = $this->pl_sess; - unset($pl_sess->id); + unset($this->view->pl); + } - return $res; + private function createFullResponse($pl = null) + { + if (isset($pl)) { + $this->view->pl = $pl; + $this->view->id = $pl->getId(); + $this->view->html = $this->view->render('playlist/index.phtml'); + unset($this->view->pl); + } + else { + $this->view->html = $this->view->render('playlist/index.phtml'); + } } public function indexAction() @@ -87,10 +73,21 @@ class PlaylistController extends Zend_Controller_Action $this->view->headLink()->appendStylesheet($baseUrl.'/css/playlist_builder.css?'.filemtime($baseDir.'/css/playlist_builder.css')); $this->_helper->viewRenderer->setResponseSegment('spl'); - $pl = $this->getPlaylist(); - if($pl !== false){ - $this->view->pl = $pl; - } + + try { + $pl = $this->getPlaylist(); + + if (isset($pl)) { + $this->view->pl = $pl; + } + } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + } + catch (Exception $e) { + Logging::log("{$e->getMessage()}"); + } } public function newAction() @@ -99,275 +96,223 @@ class PlaylistController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $pl = new Application_Model_Playlist(); - $pl->create("Untitled Playlist"); - $pl->setPLMetaData('dc:creator', $userInfo->login); + $pl->setName("Untitled Playlist"); + $pl->setPLMetaData('dc:creator', $userInfo->id); $this->changePlaylist($pl->getId()); - - $this->view->pl = $pl; - $this->view->pl_id = $pl->getId(); - $this->view->html = $this->view->render('playlist/index.phtml'); - unset($this->view->pl); + $this->createFullResponse($pl); } public function editAction() { - $pl_id = $this->_getParam('id', null); - - if(!is_null($pl_id)) { - $this->changePlaylist($pl_id); - } - - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; - } - - $this->view->pl = $pl; - $this->view->pl_id = $pl->getId(); - $this->view->html = $this->view->render('playlist/index.phtml'); - unset($this->view->pl); - } - - public function addItemAction() - { - $id = $this->_getParam('id'); - $pos = $this->_getParam('pos', null); + $id = $this->_getParam('id', null); + Logging::log("editing playlist {$id}"); if (!is_null($id)) { - - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; - } - $res = $pl->addAudioClip($id, $pos); - - if (PEAR::isError($res)) { - $this->view->message = $res->getMessage(); - } - - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); - return; + $this->changePlaylist($id); } - $this->view->message = "a file is not chosen"; - } - public function moveItemAction() - { - $oldPos = $this->_getParam('oldPos'); - $newPos = $this->_getParam('newPos'); - - - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; - } - - $pl->moveAudioClip($oldPos, $newPos); - - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); - } - - public function deleteItemAction() - { - $positions = $this->_getParam('pos', array()); - - if (!is_array($positions)) - $positions = array($positions); - - //so the automatic updating of playlist positioning doesn't affect removal. - sort($positions); - $positions = array_reverse($positions); - - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; - } - - foreach ($positions as $pos) { - $pl->delAudioClip($pos); - } - - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); - } - - public function addGroupAction() - { - $ids = $this->_getParam('ids'); - $pos = $this->_getParam('pos', null); - - if (!is_null($ids)) { + try { $pl = $this->getPlaylist(); - if ($pl === false) { - $this->view->playlist_error = true; - return false; - } - - foreach ($ids as $key => $value) { - $res = $pl->addAudioClip($value); - if (PEAR::isError($res)) { - $this->view->message = $res->getMessage(); - break; - } - } - - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - return; - } - $this->view->message = "a file is not chosen"; - } - - public function deleteGroupAction() - { - $ids = $this->_getParam('ids', null); - - foreach ($ids as $key => $id) { - $pl = Application_Model_Playlist::Recall($id); - - if ($pl !== FALSE) { - Application_Model_Playlist::Delete($id); - $pl_sess = $this->pl_sess; - if($pl_sess->id === $id){ - unset($pl_sess->id); - } - } else { - $this->view->playlist_error = true; - return false; - } - } - - $this->view->ids = $ids; - $this->view->html = $this->view->render('playlist/index.phtml'); - } - - public function setCueAction() - { - $pos = $this->_getParam('pos'); - $pl = $this->getPlaylist(); - if ($pl === false){ - $this->view->playlist_error = true; - return false; - } - - $cueIn = $this->_getParam('cueIn', null); - $cueOut = $this->_getParam('cueOut', null); - - $response = $pl->changeClipLength($pos, $cueIn, $cueOut); - - $this->view->response = $response; - - if(!isset($response["error"])) { - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); } - } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist {$id} not found"); + $this->changePlaylist(null); + } + catch (Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); + $this->changePlaylist(null); + } - public function setFadeAction() - { - $pos = $this->_getParam('pos'); - $pl = $this->getPlaylist(); - - if($pl === false){ - $this->view->playlist_error = true; - return false; - } - - $fadeIn = $this->_getParam('fadeIn', null); - $fadeOut = $this->_getParam('fadeOut', null); - - $response = $pl->changeFadeInfo($pos, $fadeIn, $fadeOut); - $this->view->response = $response; - - if(!isset($response["error"])) { - $this->view->pl = $pl; - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); - $this->view->description = $pl->getDescription(); - - unset($this->view->pl); - } + $this->createFullResponse($pl); } public function deleteAction() { - $id = $this->_getParam('id', null); - $pl = Application_Model_Playlist::Recall($id); + $ids = $this->_getParam('ids'); + $ids = (!is_array($ids)) ? array($ids) : $ids; + $pl = null; - if ($pl !== FALSE) { + try { - Application_Model_Playlist::Delete($id); + Logging::log("Currently active playlist {$this->pl_sess->id}"); + if (in_array($this->pl_sess->id, $ids)) { + Logging::log("Deleting currently active playlist"); + $this->changePlaylist(null); + } + else { + $pl = $this->getPlaylist(); + Logging::log("Not deleting currently active playlist"); + } - $pl_sess = $this->pl_sess; - - if($pl_sess->id === $id){ - unset($pl_sess->id); - } - }else{ - $this->view->playlist_error = true; - return false; + Application_Model_Playlist::DeletePlaylists($ids); + } + catch(PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $pl = null; + } + catch(Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); } - $this->view->id = $id; - $this->view->html = $this->view->render('playlist/index.phtml'); + $this->createFullResponse($pl); } - public function deleteActiveAction() + public function addItemsAction() { - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; + $ids = $this->_getParam('ids'); + $ids = (!is_array($ids)) ? array($ids) : $ids; + $afterItem = $this->_getParam('afterItem', null); + $addType = $this->_getParam('type', 'after'); + + Logging::log("type is ".$addType); + + try { + $pl = $this->getPlaylist(); + $pl->addAudioClips($ids, $afterItem, $addType); + } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $this->createFullResponse(null); + } + catch (Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); } - Application_Model_Playlist::Delete($pl->getId()); - $pl_sess = $this->pl_sess; - unset($pl_sess->id); - - $this->view->html = $this->view->render('playlist/index.phtml'); + $this->createUpdateResponse($pl); } - public function closeAction() + public function moveItemsAction() { - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; - } - $this->closePlaylist($pl); + $ids = $this->_getParam('ids'); + $ids = (!is_array($ids)) ? array($ids) : $ids; + $afterItem = $this->_getParam('afterItem', null); - $this->view->html = $this->view->render('playlist/index.phtml'); + try { + $pl = $this->getPlaylist(); + $pl->moveAudioClips($ids, $afterItem); + } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $this->createFullResponse(null); + } + catch (Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); + } + + $this->createUpdateResponse($pl); + } + + public function deleteItemsAction() + { + $ids = $this->_getParam('ids'); + $ids = (!is_array($ids)) ? array($ids) : $ids; + + try { + $pl = $this->getPlaylist(); + $pl->delAudioClips($ids); + } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $this->createFullResponse(null); + } + catch (Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); + } + + $this->createUpdateResponse($pl); + } + + public function setCueAction() + { + $id = $this->_getParam('id'); + $cueIn = $this->_getParam('cueIn', null); + $cueOut = $this->_getParam('cueOut', null); + + try { + $pl = $this->getPlaylist(); + $response = $pl->changeClipLength($id, $cueIn, $cueOut); + + $this->view->response = $response; + + if(!isset($response["error"])) { + $this->createUpdateResponse($pl); + } + } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $this->createFullResponse(null); + } + catch (Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); + } + } + + public function setFadeAction() + { + $id = $this->_getParam('id'); + $fadeIn = $this->_getParam('fadeIn', null); + $fadeOut = $this->_getParam('fadeOut', null); + + try { + $pl = $this->getPlaylist(); + $response = $pl->changeFadeInfo($id, $fadeIn, $fadeOut); + + $this->view->response = $response; + + if (!isset($response["error"])) { + $this->createUpdateResponse($pl); + } + } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $this->createFullResponse(null); + } + catch (Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); + } + } + + public function getPlaylistFadesAction() + { + try { + $pl = $this->getPlaylist(); + $fades = $pl->getFadeInfo(0); + $this->view->fadeIn = $fades[0]; + + $fades = $pl->getFadeInfo($pl->getSize()-1); + $this->view->fadeOut = $fades[1]; + } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $this->createFullResponse(null); + } + catch (Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); + } } /** @@ -377,32 +322,23 @@ class PlaylistController extends Zend_Controller_Action **/ public function setPlaylistFadesAction() { - $request = $this->getRequest(); - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; + $fadeIn = $this->_getParam('fadeIn', null); + $fadeOut = $this->_getParam('fadeOut', null); + + try { + $pl = $this->getPlaylist(); + $pl->setPlaylistfades($fadeIn, $fadeOut); + } + catch (PlaylistNotFoundException $e) { + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $this->createFullResponse(null); + } + catch (Exception $e) { + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); } - - if($request->isPost()) { - $fadeIn = $this->_getParam('fadeIn', null); - $fadeOut = $this->_getParam('fadeOut', null); - - if($fadeIn) - $response = $pl->changeFadeInfo(0, $fadeIn, $fadeOut); - else if($fadeOut) - $response = $pl->changeFadeInfo($pl->getSize(), $fadeIn, $fadeOut); - - $this->view->response = $response; - - return; - } - - $fades = $pl->getFadeInfo(0); - $this->view->fadeIn = $fades[0]; - - $fades = $pl->getFadeInfo($pl->getSize()); - $this->view->fadeOut = $fades[1]; } public function setPlaylistNameAction() diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index efa204b03..eeb64a181 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -45,7 +45,7 @@ class ScheduleController extends Zend_Controller_Action $this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.js?'.filemtime($baseDir.'/js/datatables/js/jquery.dataTables.js'),'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js?'.filemtime($baseDir.'/js/datatables/plugin/dataTables.pluginAPI.js'),'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/fullcalendar/fullcalendar.js?'.filemtime($baseDir.'/js/fullcalendar/fullcalendar.js'),'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'/js/timepicker/jquery.ui.timepicker-0.0.6.js?'.filemtime($baseDir.'/js/timepicker/jquery.ui.timepicker-0.0.6.js'),'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/timepicker/jquery.ui.timepicker.js?'.filemtime($baseDir.'/js/timepicker/jquery.ui.timepicker.js'),'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/colorpicker/js/colorpicker.js?'.filemtime($baseDir.'/js/colorpicker/js/colorpicker.js'),'text/javascript'); //full-calendar-functions.js requires this variable, so that datePicker widget can be offset to server time instead of client time @@ -68,7 +68,7 @@ class ScheduleController extends Zend_Controller_Action $user = new Application_Model_User($userInfo->id); $this->view->isAdmin = $user->isAdmin(); $this->view->isProgramManager = $user->isUserType('P'); - + $this->view->headScript()->appendScript("var weekStart = ".Application_Model_Preference::GetWeekStartDay().";"); } diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php new file mode 100644 index 000000000..dd6134f68 --- /dev/null +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -0,0 +1,128 @@ +_helper->getHelper('AjaxContext'); + $ajaxContext->addActionContext('schedule-move', 'json') + ->addActionContext('schedule-add', 'json') + ->addActionContext('schedule-remove', 'json') + ->addActionContext('builder-feed', 'json') + ->initContext(); + } + + public function indexAction() { + + $this->_helper->layout->setLayout('builder'); + + $this->view->headScript()->appendFile($this->view->baseUrl('/js/airtime/library/events/library_showbuilder.js'),'text/javascript'); + + $this->_helper->actionStack('library', 'library'); + $this->_helper->actionStack('builder', 'showbuilder'); + } + + public function builderAction() { + + $request = $this->getRequest(); + $baseUrl = $request->getBaseUrl(); + + $this->view->headScript()->appendScript("var serverTimezoneOffset = ".date("Z")."; //in seconds"); + $this->view->headScript()->appendFile($baseUrl.'/js/timepicker/jquery.ui.timepicker.js','text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/airtime/showbuilder/builder.js','text/javascript'); + + $this->view->headLink()->appendStylesheet($baseUrl.'/css/jquery.ui.timepicker.css'); + $this->view->headLink()->appendStylesheet($baseUrl.'/css/showbuilder.css'); + + $this->_helper->viewRenderer->setResponseSegment('builder'); + } + + public function builderFeedAction() { + + $request = $this->getRequest(); + $current_time = time(); + + $starts_epoch = $request->getParam("start", $current_time); + //default ends is 24 hours after starts. + $ends_epoch = $request->getParam("end", $current_time + (60*60*24)); + + $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); + $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); + + Logging::log("showbuilder starts {$startsDT->format("Y-m-d H:i:s")}"); + Logging::log("showbuilder ends {$endsDT->format("Y-m-d H:i:s")}"); + + $showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT); + + $this->view->schedule = $showBuilder->GetItems(); + } + + public function scheduleAddAction() { + + $request = $this->getRequest(); + + $mediaItems = $request->getParam("mediaIds", null); + $scheduledIds = $request->getParam("schedIds", null); + + $json = array(); + + try { + $scheduler = new Application_Model_Scheduler(); + $scheduler->scheduleAfter($scheduledIds, $mediaItems); + + $json["message"]="success... maybe"; + } + catch (Exception $e) { + $json["message"]=$e->getMessage(); + Logging::log($e->getMessage()); + } + + $this->view->data = $json; + } + + public function scheduleRemoveAction() + { + $request = $this->getRequest(); + + $ids = $request->getParam("ids", null); + + $json = array(); + + try { + $scheduler = new Application_Model_Scheduler(); + $scheduler->removeItems($ids); + + $json["message"]="success... maybe"; + } + catch (Exception $e) { + $json["message"]=$e->getMessage(); + Logging::log($e->getMessage()); + } + + $this->view->data = $json; + } + + public function scheduleMoveAction() { + + $request = $this->getRequest(); + + $selectedItem = $request->getParam("selectedItem"); + $afterItem = $request->getParam("afterItem"); + + $json = array(); + + try { + $scheduler = new Application_Model_Scheduler(); + $scheduler->moveItem($selectedItem, $afterItem); + + $json["message"]="success... maybe"; + } + catch (Exception $e) { + $json["message"]=$e->getMessage(); + Logging::log($e->getMessage()); + } + + $this->view->data = $json; + } +} \ No newline at end of file diff --git a/airtime_mvc/application/layouts/scripts/builder.phtml b/airtime_mvc/application/layouts/scripts/builder.phtml new file mode 100644 index 000000000..e9313cd03 --- /dev/null +++ b/airtime_mvc/application/layouts/scripts/builder.phtml @@ -0,0 +1,28 @@ +doctype() ?> + + + + headTitle() ?> + headScript() ?> + headLink() ?> + + + +
+ + versionNotify() ?> + partial('partialviews/header.phtml', array("user" => $this->loggedInAs(), "is_trial"=>$this->isTrial(), "trial_remain"=> $this->trialRemaining())) ?> + +navigation()->menu()->setPartial($partial); ?> + +navigation()->menu() ?> +
+ +
+ +
layout()->library ?>
+
layout()->builder ?>
+
+ + diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index 11e6312b0..0eefb49b3 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -1,360 +1,76 @@ "", + "pos" => "", + "cliplength" => "", + "cuein" => "00:00:00", + "cueout" => "00:00:00", + "fadein" => "00:00:00", + "fadeout" => "00:00:00", + ); //using propel's phpNames. - private $categories = array("dc:title" => "DbName", "dc:creator" => "DbCreator", "dc:description" => "DbDescription", "dcterms:extent" => "length"); + private $categories = array( + "dc:title" => "DbName", + "dc:creator" => "DbCreatorId", + "dc:description" => "DbDescription", + "dcterms:extent" => "getDbLength" + ); - public function __construct() + public function __construct($id=null, $con=null) { + if (isset($id)) { + $this->pl = CcPlaylistQuery::create()->findPK($id); - } - - /** -- * Convert playlist time value to float seconds -- * -- * @param string $plt -- * playlist time value (HH:mm:ss.dddddd) -- * @return int -- * seconds -- */ - public static function playlistTimeToSeconds($plt) - { - $arr = preg_split('/:/', $plt); - if (isset($arr[2])) { - return (intval($arr[0])*60 + intval($arr[1]))*60 + floatval($arr[2]); + if (is_null($this->pl)){ + throw new PlaylistNotFoundException(); + } } - if (isset($arr[1])) { - return intval($arr[0])*60 + floatval($arr[1]); + else { + $this->pl = new CcPlaylist(); + $this->pl->setDbUTime("now", new DateTimeZone("UTC")); + $this->pl->save(); } - return floatval($arr[0]); - } - - /** -- * Convert float seconds value to playlist time format -- * -- * @param float $seconds -- * @return string -- * time in playlist time format (HH:mm:ss.d) -- */ - public static function secondsToPlaylistTime($p_seconds) - { - $seconds = $p_seconds; - $rounded = round($seconds, 1); - $info = explode('.', $rounded); - $seconds = $info[0]; - if(!isset($info[1])){ - $milliStr = 0; - }else{ - $milliStr = $info[1]; + $defaultFade = Application_Model_Preference::GetDefaultFade(); + if ($defaultFade !== "") { + $this->plItem["fadein"] = $defaultFade; + $this->plItem["fadeout"] = $defaultFade; } - $hours = floor($seconds / 3600); - $seconds -= $hours * 3600; - $minutes = floor($seconds / 60); - $seconds -= $minutes * 60; - $res = sprintf("%02d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr); - - return $res; - } - - - public static function Delete($id) - { - $pl = CcPlaylistQuery::create()->findPK($id); - if($pl === NULL) - return FALSE; - - $pl->delete(); - return TRUE; - } - - public static function deleteAll() - { - global $CC_CONFIG, $CC_DBC; - $sql = 'DELETE FROM '.$CC_CONFIG["playListTable"]; - $CC_DBC->query($sql); - } - - public static function getPlaylistCount(){ - global $CC_CONFIG, $CC_DBC; - $sql = 'SELECT count(*) as cnt FROM '.$CC_CONFIG["playListTable"]; - return $CC_DBC->GetOne($sql); + $this->con = isset($con) ? $con : Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); + $this->id = $this->pl->getDbId(); } /** - * Delete the file from all playlists. - * @param string $p_fileId - */ - public static function DeleteFileFromAllPlaylists($p_fileId) - { - CcPlaylistcontentsQuery::create()->filterByDbFileId($p_fileId)->delete(); - } - - - public static function findPlaylistByName($p_name) - { - $res = CcPlaylistQuery::create()->findByDbName($p_name); - return $res; - } - - /** - * Fetch instance of Playlist object.
- * - * @param string $id - * DB id of file - * @return Playlist|FALSE - * Return FALSE if the object doesnt exist in the DB. - */ - public static function Recall($id) { - - $pl = CcPlaylistQuery::create()->findPK($id); - if($pl === NULL) - return FALSE; - - $storedPlaylist = new Application_Model_Playlist(); - $storedPlaylist->id = $id; - $storedPlaylist->name = $pl->getDbName(); - $storedPlaylist->state = $pl->getDbState(); - $storedPlaylist->currentlyaccessing = $pl->getDbCurrentlyaccessing(); - $storedPlaylist->editedby = $pl->getDbEditedby(); - $storedPlaylist->mtime = $pl->getDbMtime(); - - return $storedPlaylist; - } - - /** - * Rename stored virtual playlist - * - * @param string $p_newname - * @return TRUE|PEAR_Error - */ - public function setName($p_newname) - { - $pl = CcPlaylistQuery::create()->findPK($this->id); - - if($pl === NULL) - return FALSE; - - $pl->setDbName($p_newname); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - $this->name = $p_newname; - return TRUE; - } - - /** - * Get mnemonic playlist name - * - * @param string $p_gunid - * global unique id of playlist - * @return string - */ - public function getName($id=NULL) - { - if (is_null($id)) { - return $this->name; - } - $pl = CcPlaylistQuery::create()->findPK($id); - if ($pl === NULL) - return FALSE; - - return $pl->getDbName(); - } - - public function setDescription($p_description) - { - $pl = CcPlaylistQuery::create()->findPK($this->id); - - if($pl === NULL) - return FALSE; - $pl->setDbDescription($p_description); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - //$this->name = $p_newname; - return TRUE; - } - - public function getDescription() - { - $pl = CcPlaylistQuery::create()->findPK($this->id); - if ($pl === NULL) - return FALSE; - - return $pl->getDbDescription(); - } - - /** - * Set state of virtual playlist - * - * @param string $p_state - * 'empty'|'incomplete'|'ready'|'edited' - * @param int $p_editedby - * user id | 'NULL' for clear editedBy field - * @return TRUE|PEAR_Error - */ - public function setState($p_state, $p_editedby=NULL) - { - $pl = CcPlaylistQuery::create()->findPK($this->id); - - if($pl === NULL) - return FALSE; - - $pl->setDbState($p_state); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - - $eb = (!is_null($p_editedby) ? $p_editedby : NULL); - $pl->setDbEditedby($eb); - - $pl->save(); - - $this->state = $p_state; - $this->editedby = $p_editedby; - return TRUE; - } - - /** - * Get storage-internal file state - * - * @param string $p_gunid - * global unique id of file - * @return string - * see install() - */ - public function getState($id=NULL) - { - if (is_null($id)) { - return $this->state; - } - - $pl = CcPlaylistQuery::create()->findPK($id); - if($pl === NULL) - return FALSE; - - return $pl->getDbState(); - } - - /** - * Returns true if virtual file is currently in use.
- * Static or dynamic call is possible. - * - * @param string $p_gunid - * optional (for static call), global unique id - * @return boolean|PEAR_Error - */ - public function isAccessed($id=NULL) - { - if (is_null($id)) { - return ($this->currentlyaccessing > 0); - } - - $pl = CcPlaylistQuery::create()->findPK($id); - if (is_null($pl)) { - return PEAR::raiseError( - "StoredPlaylist::isAccessed: invalid id ($id)", - GBERR_FOBJNEX - ); - } - - return ($pl->getDbCurrentlyaccessing() > 0); - } - - /** - * Returns id of user editing playlist - * - * @param string $p_playlistId - * playlist global unique ID - * @return int id of user editing playlist - */ - public function isEdited() { - - if($this->state === 'edited') { - return $this->editedby; - } - return FALSE; - } - -/** - * Set playlist edit flag - * - * @param string $p_playlistId - * Playlist unique ID - * @param boolean $p_val - * Set/clear of edit flag - * @param string $p_sessid - * Session id - * @param int $p_subjid - * Subject id (if sessid is not specified) - * @return boolean - * TRUE on success. - */ - - public function setEditFlag($p_subjid, $p_val=TRUE) { - - if ($p_val) { - $r = $this->setState('edited', $p_subjid); - } else { - $r = $this->setState('ready'); - } - if ($r === FALSE) { - return FALSE; - } - return TRUE; - } - - /** * Return local ID of virtual file. * * @return int @@ -363,28 +79,47 @@ class Application_Model_Playlist { return $this->id; } - private function getNextPos() { - - $res = CcPlaylistQuery::create() - ->findPK($this->id) - ->computeLastPosition(); - - if(is_null($res)) - return 0; - - return $res + 1; + /** + * Rename stored virtual playlist + * + * @param string $p_newname + */ + public function setName($p_newname) + { + $this->pl->setDbName($p_newname); + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); } - public function getSize() { + /** + * Get mnemonic playlist name + * + * @return string + */ + public function getName() + { + return $this->pl->getDbName(); + } - $res = CcPlaylistQuery::create() - ->findPK($this->id) - ->computeLastPosition(); + public function setDescription($p_description) + { + $this->pl->setDbDescription($p_description); + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); + } - if(is_null($res)) - return 0; + public function getDescription() + { + return $this->pl->getDbDescription(); + } - return $res; + public function getLastModified($format = null) { + return $this->pl->getDbMtime($format); + } + + public function getSize() { + + return $this->pl->countCcPlaylistcontentss(); } /** @@ -392,12 +127,15 @@ class Application_Model_Playlist { * @return array */ public function getContents() { + + Logging::log("Getting contents for playlist {$this->id}"); + $files = array(); $rows = CcPlaylistcontentsQuery::create() ->joinWith('CcFiles') ->orderByDbPosition() ->filterByDbPlaylistId($this->id) - ->find(); + ->find($this->con); $i = 0; $offset = 0; @@ -408,7 +146,7 @@ class Application_Model_Playlist { $files[$i]['cliplength'] = Application_Model_Playlist::secondsToPlaylistTime($clipSec); $offset += $clipSec; $files[$i]['offset'] = Application_Model_Playlist::secondsToPlaylistTime($offset); - + #For issue CC-2065 - update fade in and out values between playlst elements #modified from the db default format of 00:00:00 to the more practical #00.000000 format which is for only seconds. @@ -427,7 +165,7 @@ class Application_Model_Playlist { * will normalize the fade so that it looks like 00.000000 to the user. **/ public function normalizeFade($fade) { - + //First get rid of the first six characters 00:00: which will be added back later for db update $fade = substr($fade, 6); @@ -438,200 +176,252 @@ class Application_Model_Playlist { else while( strlen( $fade ) < 9 ) $fade .= '0'; - + //done, just need to set back the formated values return $fade; } + //aggregate column on playlistcontents cliplength column. public function getLength() { - $res = CcPlaylistQuery::create() - ->findPK($this->id) - ->computeLength(); - - if(is_null($res)) - return '00:00:00'; - - // calling two functions to format time to 1 decimal place - $sec = Application_Model_Playlist::playlistTimeToSeconds($res); - $res = Application_Model_Playlist::secondsToPlaylistTime($sec); - return $res; + $this->pl->getDbLength(); } - /** - * Create instance of a Playlist object. - * - * @param string $p_fname - * Name of the playlist - * @return Playlist - */ - public function create($p_fname=NULL) + + private function insertPlaylistElement($info) { - $this->name = !empty($p_fname) ? $p_fname : date("H:i:s"); - - $pl = new CcPlaylist(); - $pl->setDbName($this->name); - $pl->setDbState("incomplete"); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->setDbUtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - $this->id = $pl->getDbId(); - $this->setState('ready'); - - return $this; + $row = new CcPlaylistcontents(); + $row->setDbPlaylistId($this->id); + $row->setDbFileId($info["id"]); + $row->setDbPosition($info["pos"]); + $row->setDbCliplength($info["cliplength"]); + $row->setDbCuein($info["cuein"]); + $row->setDbCueout($info["cueout"]); + $row->setDbFadein($info["fadein"]); + $row->setDbFadeout($info["fadeout"]); + $row->save($this->con); } - /** - * Lock playlist for edit + /* * - * @param int $subjid - * local subject (user) id - * @param boolean $val - * if false do unlock - * @return boolean - * previous state or error object */ - public function lock($subjid, $val=TRUE) + private function buildEntry($p_item, $pos) { - if ($val && $this->isEdited() !== FALSE) { - return PEAR::raiseError( - 'Application_Model_Playlist::lock: playlist already locked' - ); + $file = CcFilesQuery::create()->findPK($p_item, $this->con); + + $entry = $this->plItem; + $entry["id"] = $file->getDbId(); + $entry["pos"] = $pos; + $entry["cliplength"] = $file->getDbLength(); + $entry["cueout"] = $file->getDbLength(); + + return $entry; + } + + /* + * @param array $p_items + * an array of audioclips to add to the playlist + * @param int|null $p_afterItem + * item which to add the new items after in the playlist, null if added to the end. + * @param string (before|after) $addAfter + * whether to add the clips before or after the selected item. + */ + public function addAudioClips($p_items, $p_afterItem=NULL, $addType = 'after') + { + $this->con->beginTransaction(); + $contentsToUpdate = array(); + + try { + + if (is_numeric($p_afterItem)) { + Logging::log("Finding playlist content item {$p_afterItem}"); + + $afterItem = CcPlaylistcontentsQuery::create()->findPK($p_afterItem); + $index = $afterItem->getDbPosition(); + Logging::log("index is {$index}"); + $pos = ($addType == 'after') ? $index + 1 : $index; + + + $contentsToUpdate = CcPlaylistcontentsQuery::create() + ->filterByDbPlaylistId($this->id) + ->filterByDbPosition($pos, Criteria::GREATER_EQUAL) + ->orderByDbPosition() + ->find($this->con); + + Logging::log("Adding to playlist"); + Logging::log("at position {$pos}"); + } + else { + + //add to the end of the playlist + if ($addType == 'after') { + $pos = $this->getSize(); + } + //add to the beginning of the playlist. + else { + $pos = 0; + + $contentsToUpdate = CcPlaylistcontentsQuery::create() + ->filterByDbPlaylistId($this->id) + ->orderByDbPosition() + ->find($this->con); + } + + $contentsToUpdate = CcPlaylistcontentsQuery::create() + ->filterByDbPlaylistId($this->id) + ->filterByDbPosition($pos, Criteria::GREATER_EQUAL) + ->orderByDbPosition() + ->find($this->con); + + Logging::log("Adding to playlist"); + Logging::log("at position {$pos}"); + } + + foreach($p_items as $ac) { + Logging::log("Adding audio file {$ac}"); + + $res = $this->insertPlaylistElement($this->buildEntry($ac, $pos)); + $pos = $pos + 1; + } + + //reset the positions of the remaining items. + for ($i = 0; $i < count($contentsToUpdate); $i++) { + $contentsToUpdate[$i]->setDbPosition($pos); + $contentsToUpdate[$i]->save($this->con); + $pos = $pos + 1; + } + + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; } - $r = $this->setEditFlag($subjid, $val); - return $r; } - /** - * Unlock playlist + * Move audioClip to the new position in the playlist * - * @return boolean - * previous state or error object + * @param array $p_items + * array of unique ids of the selected items + * @param int $p_afterItem + * unique id of the item to move the clip after */ - public function unlock($subjid) + public function moveAudioClips($p_items, $p_afterItem=NULL) { - $r = $this->lock($subjid, FALSE); - return $r; - } + $this->con->beginTransaction(); + try { - /** - * Add audio clip to the playlist - * - * @param string $p_id - * local ID of added file - * @param string $p_position - * optional, Which position in the playlist to insert the audio clip - * @param string $p_fadeIn - * optional, in time format ss.ssssss - total duration - * @param string $p_fadeOut - * optional, in time format ss.ssssss - total duration - * @param string $p_clipLength - * optional length in in time format hh:mm:ss.ssssss - - * for webstream (or for overrule length of audioclip) - * @return true|PEAR_Error - * TRUE on success - */ - public function addAudioClip($p_mediaId, $p_position=NULL, $p_fadeIn=NULL, $p_fadeOut=NULL, $p_clipLength=NULL, $p_cuein=NULL, $p_cueout=NULL) - { - //get audio clip. - $media = Application_Model_StoredFile::Recall($p_mediaId); - if (is_null($media) || PEAR::isError($media)) { - return $media; + $contentsToMove = CcPlaylistcontentsQuery::create() + ->filterByDbId($p_items, Criteria::IN) + ->orderByDbPosition() + ->find($this->con); + + $otherContent = CcPlaylistcontentsQuery::create() + ->filterByDbId($p_items, Criteria::NOT_IN) + ->filterByDbPlaylistId($this->id) + ->orderByDbPosition() + ->find($this->con); + + $pos = 0; + //moving items to beginning of the playlist. + if (is_null($p_afterItem)) { + Logging::log("moving items to beginning of playlist"); + + foreach ($contentsToMove as $item) { + Logging::log("item {$item->getDbId()} to pos {$pos}"); + $item->setDbPosition($pos); + $item->save($this->con); + $pos = $pos + 1; + } + foreach ($otherContent as $item) { + Logging::log("item {$item->getDbId()} to pos {$pos}"); + $item->setDbPosition($pos); + $item->save($this->con); + $pos = $pos + 1; + } + } + else { + Logging::log("moving items after {$p_afterItem}"); + + foreach ($otherContent as $item) { + Logging::log("item {$item->getDbId()} to pos {$pos}"); + $item->setDbPosition($pos); + $item->save($this->con); + $pos = $pos + 1; + + if ($item->getDbId() == $p_afterItem) { + foreach ($contentsToMove as $move) { + Logging::log("item {$move->getDbId()} to pos {$pos}"); + $move->setDbPosition($pos); + $move->save($this->con); + $pos = $pos + 1; + } + } + } + } + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; } - $metadata = $media->getMetadata(); - $length = $metadata['MDATA_KEY_DURATION']; - if (!is_null($p_clipLength)) { - $length = $p_clipLength; - } - - // insert at end of playlist. - if (is_null($p_position)) - $p_position = $this->getNextPos(); - - // insert default values if parameter was empty - $p_cuein = !is_null($p_cuein) ? $p_cuein : '00:00:00.000000'; - $p_cueout = !is_null($p_cueout) ? $p_cueout : $length; - - $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); - $sql = "SELECT INTERVAL '{$p_cueout}' - INTERVAL '{$p_cuein}'"; - $r = $con->query($sql); - $p_cliplength = $r->fetchColumn(0); - - $res = $this->insertPlaylistElement($this->id, $p_mediaId, $p_position, $p_cliplength, $p_cuein, $p_cueout, $p_fadeIn, $p_fadeOut); - - $pl = CcPlaylistQuery::create()->findPK($this->id); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - return TRUE; + $this->pl = CcPlaylistQuery::create()->findPK($this->id); + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); } - /** * Remove audioClip from playlist * - * @param int $position - * position of audioclip in the playlist. - * @return boolean + * @param array $p_items + * array of unique item ids to remove from the playlist.. */ - public function delAudioClip($pos) + public function delAudioClips($p_items) { - if($pos < 0 || $pos >= $this->getNextPos()) - return FALSE; - $row = CcPlaylistcontentsQuery::create() - ->filterByDbPlaylistId($this->id) - ->filterByDbPosition($pos) - ->findOne(); + $this->con->beginTransaction(); - if(is_null($row)) - return FALSE; + try { - $row->delete(); - - $pl = CcPlaylistQuery::create()->findPK($this->id); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - return $row; + CcPlaylistcontentsQuery::create() + ->findPKs($p_items) + ->delete($this->con); + + $contents = CcPlaylistcontentsQuery::create() + ->filterByDbPlaylistId($this->id) + ->orderByDbPosition() + ->find($this->con); + + //reset the positions of the remaining items. + for ($i = 0; $i < count($contents); $i++) { + $contents[$i]->setDbPosition($i); + $contents[$i]->save($this->con); + } + + $this->pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); + $this->pl->save($this->con); + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; + } } - /** - * Move audioClip to the new position in the playlist - * - * @param int $oldPos - * old positioin in playlist - * @param int $newPos - * new position in playlist - * @return mixed - */ - public function moveAudioClip($oldPos, $newPos) - { - if($newPos < 0 || $newPos >= $this->getNextPos() || $oldPos < 0 || $oldPos >= $this->getNextPos() || $oldPos === $newPos) - return FALSE; - - $row = $this->delAudioClip($oldPos); - if($row === FALSE) - return FALSE; - - $res = $this->addAudioClip($row->getDbFileId(), $newPos, $row->getDbFadein(), $row->getDbFadeout(), $row->getDbCliplength(), $row->getDbCuein(), $row->getDbCueout()); - if($res !== TRUE) - return FALSE; - - $pl = CcPlaylistQuery::create()->findPK($this->id); - $pl->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); - $pl->save(); - - return TRUE; - } public function getFadeInfo($pos) { - $row = CcPlaylistcontentsQuery::create() + Logging::log("Getting fade info for pos {$pos}"); + + $row = CcPlaylistcontentsQuery::create() ->joinWith(CcFilesPeer::OM_CLASS) ->filterByDbPlaylistId($this->id) ->filterByDbPosition($pos) @@ -656,27 +446,24 @@ class Application_Model_Playlist { * new value in ss.ssssss or extent format * @return boolean */ - public function changeFadeInfo($pos, $fadeIn, $fadeOut) + public function changeFadeInfo($id, $fadeIn, $fadeOut) { //See issue CC-2065, pad the fadeIn and fadeOut so that it is TIME compatable with the DB schema //For the top level PlayList either fadeIn or fadeOut will sometimes be Null so need a gaurd against - //setting it to nonNull for checks down below + //setting it to nonNull for checks down below $fadeIn = $fadeIn?'00:00:'.$fadeIn:$fadeIn; $fadeOut = $fadeOut?'00:00:'.$fadeOut:$fadeOut; $errArray= array(); $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); - if(is_null($pos) || $pos < 0 || $pos >= $this->getNextPos()) { - $errArray["error"]="Invalid position."; + $row = CcPlaylistcontentsQuery::create()->findPK($id); + + if (is_null($row)) { + $errArray["error"]="Playlist item does not exist."; return $errArray; } - $row = CcPlaylistcontentsQuery::create() - ->filterByDbPlaylistId($this->id) - ->filterByDbPosition($pos) - ->findOne(); - $clipLength = $row->getDbCliplength(); if(!is_null($fadeIn)) { @@ -705,21 +492,27 @@ class Application_Model_Playlist { return array("fadeIn"=>$fadeIn, "fadeOut"=>$fadeOut); } - public function getCueInfo($pos) { + public function setPlaylistfades($fadein, $fadeout) { - $row = CcPlaylistcontentsQuery::create() - ->joinWith(CcFilesPeer::OM_CLASS) - ->filterByDbPlaylistId($this->id) - ->filterByDbPosition($pos) - ->findOne(); + if (isset($fadein)) { + Logging::log("Setting playlist fade in {$fadein}"); + $row = CcPlaylistcontentsQuery::create() + ->filterByDbPlaylistId($this->id) + ->filterByDbPosition(0) + ->findOne(); - $file = $row->getCcFiles(); - $origLength = $file->getDbLength(); - $cueIn = $row->getDBCuein(); - $cueOut = $row->getDbCueout(); + $this->changeFadeInfo($row->getDbId(), $fadein, null); + } - return array($cueIn, $cueOut, $origLength); - } + if (isset($fadeout)) { + $row = CcPlaylistcontentsQuery::create() + ->filterByDbPlaylistId($this->id) + ->filterByDbPosition($this->getSize()-1) + ->findOne(); + + $this->changeFadeInfo($row->getDbId(), null, $fadeout); + } + } /** * Change cueIn/cueOut values for playlist element @@ -732,27 +525,26 @@ class Application_Model_Playlist { * new value in ss.ssssss or extent format * @return boolean or pear error object */ - public function changeClipLength($pos, $cueIn, $cueOut) + public function changeClipLength($id, $cueIn, $cueOut) { $errArray= array(); $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); - if(is_null($cueIn) && is_null($cueOut)) { + if (is_null($cueIn) && is_null($cueOut)) { $errArray["error"]="Cue in and cue out are null."; return $errArray; } - if(is_null($pos) || $pos < 0 || $pos >= $this->getNextPos()) { - $errArray["error"]="Invalid position."; - return $errArray; - } - $row = CcPlaylistcontentsQuery::create() ->joinWith(CcFilesPeer::OM_CLASS) - ->filterByDbPlaylistId($this->id) - ->filterByDbPosition($pos) + ->filterByPrimaryKey($id) ->findOne(); + if (is_null($row)) { + $errArray["error"]="Playlist item does not exist!."; + return $errArray; + } + $oldCueIn = $row->getDBCuein(); $oldCueOut = $row->getDbCueout(); $fadeIn = $row->getDbFadein(); @@ -857,40 +649,14 @@ class Application_Model_Playlist { "fadeIn"=>$fadeIn, "fadeOut"=>$fadeOut); } - /** - * Find info about clip at specified offset in playlist. - * - * @param string $offset - * current playtime (hh:mm:ss.ssssss) - * @param int $distance - * 0=current clip; 1=next clip ... - * @return array of matching clip info: - *
    - *
  • gunid string, global unique id of clip
  • - *
  • elapsed string, already played time of clip
  • - *
  • remaining string, remaining time of clip
  • - *
  • duration string, total playlength of clip
  • - *
- */ - public function getPlaylistClipAtPosition($pos) - { - - } - public function getAllPLMetaData() { $categories = $this->categories; - $row = CcPlaylistQuery::create()->findPK($this->id); $md = array(); foreach($categories as $key => $val) { - if($val === 'length') { - $md[$key] = $this->getLength(); - continue; - } - $method = 'get' . $val; - $md[$key] = $row->$method(); + $md[$key] = $this->pl->$method(); } return $md; @@ -899,152 +665,94 @@ class Application_Model_Playlist { public function getPLMetaData($category) { $cat = $this->categories[$category]; - - if($cat === 'length') { - return $this->getLength(); - } - - $row = CcPlaylistQuery::create()->findPK($this->id); $method = 'get' . $cat; - return $row->$method(); + return $this->pl->$method(); } public function setPLMetaData($category, $value) { $cat = $this->categories[$category]; - $row = CcPlaylistQuery::create()->findPK($this->id); $method = 'set' . $cat; - $row->$method($value); - $row->save(); - - return TRUE; - } - - /** - * Return array with gunids of all sub-playlists and clips used in - * the playlist - * - * @return array with hash elements: - * gunid - global id - * type - playlist | audioClip - */ - public function export() - { - - } - - /** - * Export playlist as simplified SMIL XML file. - * - * @param boolean $toString - * if false don't real export, - * return misc info about playlist only - * @return string - * XML string or hasharray with misc info - */ - public function outputToSmil($toString=TRUE) - { - + $this->pl->$method($value); + $this->pl->save($this->con); } /** - * Export playlist as M3U file. - * - * @param boolean $toString - * if false don't real export, - * return misc info about playlist only - * @return string|array - * M3U string or hasharray with misc info - */ - public function outputToM3u($toString=TRUE) +- * Convert playlist time value to float seconds +- * +- * @param string $plt +- * playlist time value (HH:mm:ss.dddddd) +- * @return int +- * seconds +- */ + public static function playlistTimeToSeconds($plt) { - - } - - - /** - * Export playlist as RSS XML file - * - * @param boolean $toString - * if false don't really export, - * return misc info about playlist only - * @return mixed - * XML string or hasharray with misc info - */ - public function outputToRss($toString=TRUE) - { - - } - - - /** - * Insert a new playlist element. - * - * @param int $plId - * id of Playlist - * @param int $fileId - * id of File - * @param string $offset - * relative offset in extent format - * @param string $clipstart - * audioClip clipstart in extent format - * @param string $clipEnd - * audioClip clipEnd in extent format - * @param string $clipLength - * audioClip playlength in extent format (?) - * @param string $acGunid - * audioClip gunid - * @param string $acLen - * audioClip length in extent format - * @param string $acTit - * audioClip title - * @param string $fadeIn - * fadeIn value in ss.ssssss or extent format - * @param string $fadeOut - * fadeOut value in ss.ssssss or extent format - - * @return array with fields: - *
    - *
  • plElId int - record id of playlistElement
  • - *
  • plElGunid string - gl.unique id of playlistElement
  • - *
  • fadeInId int - record id
  • - *
  • fadeOutId int - record id
  • - *
- */ - private function insertPlaylistElement($plId, $fileId, $pos, $clipLength, $cuein, $cueout, $fadeIn=NULL, $fadeOut=NULL) - { - $defaultFade = Application_Model_Preference::GetDefaultFade(); - - if(is_null($fadeIn)) { - if($defaultFade != "") - $fadeIn = '00:00:'.$defaultFade; - else - $fadeIn = '00:00:00'; + $arr = preg_split('/:/', $plt); + if (isset($arr[2])) { + return (intval($arr[0])*60 + intval($arr[1]))*60 + floatval($arr[2]); } - if(is_null($fadeOut)) { - if($defaultFade != "") - $fadeOut = '00:00:'.$defaultFade; - else - $fadeOut = '00:00:00'; + if (isset($arr[1])) { + return intval($arr[0])*60 + floatval($arr[1]); } - - $row = new CcPlaylistcontents(); - $row->setDbPlaylistId($plId); - $row->setDbFileId($fileId); - $row->setDbPosition($pos); - $row->save(); - - $row->setDbCliplength($clipLength); - $row->setDbCuein($cuein); - - $row->setDbCueout($cueout); - $row->setDbFadein($fadeIn); - $row->setDbFadeout($fadeOut); + return floatval($arr[0]); + } - return TRUE; + /** +- * Convert float seconds value to playlist time format +- * +- * @param float $seconds +- * @return string +- * time in playlist time format (HH:mm:ss.d) +- */ + public static function secondsToPlaylistTime($p_seconds) + { + $seconds = $p_seconds; + $rounded = round($seconds, 1); + $info = explode('.', $rounded); + $seconds = $info[0]; + if(!isset($info[1])){ + $milliStr = 0; + }else{ + $milliStr = $info[1]; + } + $hours = floor($seconds / 3600); + $seconds -= $hours * 3600; + $minutes = floor($seconds / 60); + $seconds -= $minutes * 60; + + $res = sprintf("%02d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr); + + return $res; + } + + public static function getPlaylistCount(){ + global $CC_CONFIG, $CC_DBC; + $sql = 'SELECT count(*) as cnt FROM '.$CC_CONFIG["playListTable"]; + return $CC_DBC->GetOne($sql); + } + + /** + * Delete the file from all playlists. + * @param string $p_fileId + */ + public static function DeleteFileFromAllPlaylists($p_fileId) + { + CcPlaylistcontentsQuery::create()->filterByDbFileId($p_fileId)->delete(); + } + + /** + * Delete playlists that match the ids.. + * @param array $p_ids + */ + public static function DeletePlaylists($p_ids) + { + CcPlaylistQuery::create()->findPKs($p_ids)->delete(); } } // class Playlist + +class PlaylistNotFoundException extends Exception {} +class OutDatedException extends Exception {} diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 725578348..71e1eb462 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -155,7 +155,7 @@ class Application_Model_Schedule { "nextShow"=>Application_Model_Show::GetNextShows($utcTimeNow, 1), "timezone"=> date("T"), "timezoneOffset"=> date("Z")); - + return $range; } @@ -294,6 +294,48 @@ class Application_Model_Schedule { return $rows; } + /* + * + * @param DateTime $p_startDateTime + * + * @param DateTime $p_endDateTime + * + * @return array $scheduledItems + * + */ + public static function GetScheduleDetailItems($p_startDateTime, $p_endDateTime) + { + global $CC_CONFIG, $CC_DBC; + + $sql = "SELECT DISTINCT + + showt.name AS show_name, showt.color AS show_color, + showt.background_color AS show_background_colour, showt.id AS show_id, + + si.starts AS si_starts, si.ends AS si_ends, si.time_filled AS si_time_filled, + si.record AS si_record, si.rebroadcast AS si_rebroadcast, si.id AS si_id, + + sched.starts AS sched_starts, sched.ends AS sched_ends, sched.id AS sched_id, + + ft.track_title AS file_track_title, ft.artist_name AS file_artist_name, + ft.album_title AS file_album_title, ft.length AS file_length + + FROM + ((cc_schedule AS sched JOIN cc_files AS ft ON (sched.file_id = ft.id) + RIGHT OUTER JOIN cc_show_instances AS si ON (si.id = sched.instance_id)) + JOIN cc_show AS showt ON (showt.id = si.show_id) + ) + + WHERE si.starts >= '{$p_startDateTime}' AND si.starts <= '{$p_endDateTime}' + + ORDER BY si.starts, sched.starts;"; + + Logging::log($sql); + + $rows = $CC_DBC->GetAll($sql); + return $rows; + } + public static function GetShowInstanceItems($instance_id) { global $CC_CONFIG, $CC_DBC; @@ -533,7 +575,7 @@ class Application_Model_Schedule { public static function createNewFormSections($p_view){ $isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true; - + $formWhat = new Application_Form_AddShowWhat(); $formWho = new Application_Form_AddShowWho(); $formWhen = new Application_Form_AddShowWhen(); @@ -560,16 +602,16 @@ class Application_Model_Schedule { 'add_show_duration' => '1h')); $formRepeats->populate(array('add_show_end_date' => date("Y-m-d"))); - + if(!$isSaas){ $formRecord = new Application_Form_AddShowRR(); $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates(); $formRebroadcast = new Application_Form_AddShowRebroadcastDates(); - + $formRecord->removeDecorator('DtDdWrapper'); $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper'); $formRebroadcast->removeDecorator('DtDdWrapper'); - + $p_view->rr = $formRecord; $p_view->absoluteRebroadcast = $formAbsoluteRebroadcast; $p_view->rebroadcast = $formRebroadcast; diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php new file mode 100644 index 000000000..d6e21d13a --- /dev/null +++ b/airtime_mvc/application/models/Scheduler.php @@ -0,0 +1,352 @@ + "", + "cliplength" => "", + "cuein" => "00:00:00", + "cueout" => "00:00:00", + "fadein" => "00:00:00", + "fadeout" => "00:00:00", + "sched_id" => null, + ); + + public function __construct($id = null) { + + $this->con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); + } + + /* + * @param $id + * @param $type + * + * @return $files + */ + private function retrieveMediaFiles($id, $type) { + + $files = array(); + + if ($type === "audioclip") { + $file = CcFilesQuery::create()->findPK($id, $this->con); + + $data = $this->fileInfo; + $data["id"] = $id; + $data["cliplength"] = $file->getDbLength(); + + $files[] = $data; + } + else if ($type === "playlist") { + + $contents = CcPlaylistcontentsQuery::create() + ->orderByDbPosition() + ->filterByDbPlaylistId($id) + ->find($this->con); + + foreach ($contents as $plItem) { + + $data = $this->fileInfo; + $data["id"] = $plItem->getDbFileId(); + $data["cliplength"] = $plItem->getDbCliplength(); + $data["cuein"] = $plItem->getDbCuein(); + $data["cueout"] = $plItem->getDbCueout(); + $data["fadein"] = $plItem->getDbFadein(); + $data["fadeout"] = $plItem->getDbFadeout(); + + $files[] = $data; + } + } + + return $files; + } + + /* + * @param DateTime startDT + * @param string duration + * in format H:i:s.u (could be more that 24 hours) + */ + private function findEndTime($startDT, $duration) { + + } + + /* + * @param array $scheduledIds + * @param array $fileIds + * @param array $playlistIds + */ + private function insertAfter($scheduleItems, $schedFiles, $adjustSched = true) { + + try { + + //dont want to recalculate times for moved items. + $excludeIds = array(); + foreach ($schedFiles as $file) { + if (isset($file["sched_id"])) { + $excludeIds[] = intval($file["sched_id"]); + } + } + + foreach ($scheduleItems as $schedule) { + $id = intval($schedule["id"]); + + Logging::log("scheduling after scheduled item: ".$id); + Logging::log("in show: ".intval($schedule["instance"])); + + if ($id !== 0) { + $schedItem = CcScheduleQuery::create()->findPK($id, $this->con); + $instance = $schedItem->getDbInstanceId(); + + //user has an old copy of the time line opened. + if ($instance !== intval($schedule["instance"])) { + Logging::log("items have been since updated"); + return; + } + + $nextStartDT = $schedItem->getDbEnds(null); + } + //selected empty row to add after + else { + $showInstance = CcShowInstancesQuery::create()->findPK($schedule["instance"], $this->con); + $nextStartDT = $showInstance->getDbStarts(null); + $instance = intval($schedule["instance"]); + } + + Logging::log("finding items >= {$nextStartDT->format("Y-m-d H:i:s.u")}"); + if ($adjustSched === true) { + $followingSchedItems = CcScheduleQuery::create() + ->filterByDBStarts($nextStartDT->format("Y-m-d H:i:s.u"), Criteria::GREATER_EQUAL) + ->filterByDbInstanceId($instance) + ->filterByDbId($excludeIds, Criteria::NOT_IN) + ->orderByDbStarts() + ->find($this->con); + + foreach ($excludeIds as $id) { + Logging::log("Excluding id {$id}"); + } + } + + foreach($schedFiles as $file) { + + Logging::log("adding file with id: ".$file["id"]); + + $durationDT = new DateTime("1970-01-01 {$file['cliplength']}", new DateTimeZone("UTC")); + $endTimeEpoch = $nextStartDT->format("U") + $durationDT->format("U"); + $endTimeDT = DateTime::createFromFormat("U", $endTimeEpoch, new DateTimeZone("UTC")); + + //item existed previously and is being moved. + //need to keep same id for resources if we want REST. + if (isset($file['sched_id'])) { + $sched = CcScheduleQuery::create()->findPK($file['sched_id'], $this->con); + } + else { + $sched = new CcSchedule(); + } + Logging::log("id {$sched->getDbId()}"); + Logging::log("start time {$nextStartDT->format("Y-m-d H:i:s.u")}"); + Logging::log("end time {$endTimeDT->format("Y-m-d H:i:s.u")}"); + + $sched->setDbStarts($nextStartDT); + $sched->setDbEnds($endTimeDT); + $sched->setDbFileId($file['id']); + $sched->setDbCueIn($file['cuein']); + $sched->setDbCueOut($file['cueout']); + $sched->setDbFadeIn($file['fadein']); + $sched->setDbFadeOut($file['fadeout']); + $sched->setDbClipLength($durationDT->format("H:i:s.u")); + $sched->setDbInstanceId($instance); + $sched->save($this->con); + + $nextStartDT = $endTimeDT; + } + + if ($adjustSched === true) { + + //recalculate the start/end times after the inserted items. + foreach($followingSchedItems as $item) { + + Logging::log("adjusting iterm {$item->getDbId()}"); + + $durationDT = new DateTime("1970-01-01 {$item->getDbClipLength()}", new DateTimeZone("UTC")); + $endTimeEpoch = $nextStartDT->format("U") + $durationDT->format("U"); + $endTimeDT = DateTime::createFromFormat("U", $endTimeEpoch, new DateTimeZone("UTC")); + + $item->setDbStarts($nextStartDT); + $item->setDbEnds($endTimeDT); + $item->save($this->con); + + $nextStartDT = $endTimeDT; + } + } + } + + } + catch (Exception $e) { + throw $e; + } + } + + /* + * @param array $scheduledIds + * @param array $fileIds + * @param array $playlistIds + */ + public function scheduleAfter($scheduleItems, $mediaItems, $adjustSched = true) { + + $this->con->beginTransaction(); + + $schedFiles = array(); + + try { + + foreach($mediaItems as $media) { + Logging::log("Media Id ".$media["id"]); + Logging::log("Type ".$media["type"]); + + $schedFiles = array_merge($schedFiles, $this->retrieveMediaFiles($media["id"], $media["type"])); + } + $this->insertAfter($scheduleItems, $schedFiles, $adjustSched); + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; + } + } + + /* + * @param array $selectedItem + * @param array $afterItem + */ + public function moveItem($selectedItem, $afterItem, $adjustSched = true) { + + $this->con->beginTransaction(); + + try { + + $origSelIns = intval($selectedItem[0]["instance"]); + $origAfterIns = intval($afterItem[0]["instance"]); + + Logging::log("Moving item {$selectedItem[0]["id"]}"); + Logging::log("After {$afterItem[0]["id"]}"); + + $selected = CcScheduleQuery::create()->findPk($selectedItem[0]["id"]); + $after = CcScheduleQuery::create()->findPk($afterItem[0]["id"]); + + /* + if (isset($after) && $origSelIns !== $selected->getDBInstanceId() + || $origAfterIns !== $after->getDBInstanceId()) { + + Logging::log("items have been since updated"); + return; + } + */ + + $this->removeGaps($origSelIns, $selected->getDbId()); + + //moved to another show, remove gaps from original show. + if ($adjustSched === true && $origSelIns !== $origAfterIns) { + + } + + $data = $this->fileInfo; + $data["id"] = $selected->getDbFileId(); + $data["cliplength"] = $selected->getDbClipLength(); + $data["cuein"] = $selected->getDbCueIn(); + $data["cueout"] = $selected->getDbCueOut(); + $data["fadein"] = $selected->getDbFadeIn(); + $data["fadeout"] = $selected->getDbFadeOut(); + $data["sched_id"] = $selected->getDbId(); + + $this->insertAfter($afterItem, array($data), $adjustSched); + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; + } + } + + public function removeItems($scheduledIds, $adjustSched = true) { + + $showInstances = array(); + $this->con->beginTransaction(); + + try { + + $removedItems = CcScheduleQuery::create()->findPks($scheduledIds); + $removedItems->delete($this->con); + + if ($adjustSched === true) { + //get the show instances of the shows we must adjust times for. + foreach ($removedItems as $item) { + + $instance = $item->getDBInstanceId(); + if (!in_array($instance, $showInstances)) { + $showInstances[] = $instance; + } + } + + foreach($showInstances as $instance) { + $this->removeGaps($instance); + } + } + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + throw $e; + } + } + + /* + * @param int $showInstance + * @param array $exclude + * ids of sched items to remove from the calulation. + */ + public function removeGaps($showInstance, $exclude=null) { + + Logging::log("removing gaps from show instance #".$showInstance); + + $instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con); + $itemStartDT = $instance->getDbStarts(null); + + $schedule = CcScheduleQuery::create() + ->filterByDbInstanceId($showInstance) + ->filterByDbId($exclude, Criteria::NOT_IN) + ->orderByDbStarts() + ->find($this->con); + + + foreach ($schedule as $item) { + + Logging::log("adjusting item #".$item->getDbId()); + + if (!$item->isDeleted()) { + Logging::log("item #".$item->getDbId()." is not deleted"); + + $durationDT = new DateTime("1970-01-01 {$item->getDbClipLength()}", new DateTimeZone("UTC")); + $startEpoch = $itemStartDT->format("U"); + Logging::log("new start time"); + Logging::log($itemStartDT->format("Y-m-d H:i:s")); + + Logging::log("duration"); + Logging::log($durationDT->format("U"). "seconds"); + + $endEpoch = $itemStartDT->format("U") + $durationDT->format("U"); + $itemEndDT = DateTime::createFromFormat("U", $endEpoch, new DateTimeZone("UTC")); + Logging::log("new end time"); + Logging::log($itemEndDT->format("Y-m-d H:i:s")); + + $item->setDbStarts($itemStartDT); + $item->setDbEnds($itemEndDT); + $item->save($this->con); + + $itemStartDT = $itemEndDT; + } + } + } +} \ No newline at end of file diff --git a/airtime_mvc/application/models/ShowBuilder.php b/airtime_mvc/application/models/ShowBuilder.php new file mode 100644 index 000000000..b7f462732 --- /dev/null +++ b/airtime_mvc/application/models/ShowBuilder.php @@ -0,0 +1,156 @@ + false, + "footer" => false, + "empty" => false, + "checkbox" => false, + "id" => 0, + "instance" => "", + "starts" => "", + "startsUnix" => null, + "ends" => "", + "endsUnix" => null, + "runtime" => "", + "title" => "", + "creator" => "", + "album" => "" + ); + + /* + * @param DateTime $p_startsDT + * @param DateTime $p_endsDT + */ + public function __construct($p_startDT, $p_endDT) { + + $this->startDT = $p_startDT; + $this->endDT = $p_endDT; + $this->timezone = date_default_timezone_get(); + $this->user = Application_Model_User::GetCurrentUser(); + } + + /* + * @param DateInterval $p_interval + * + * @return string $runtime + */ + private function formatDuration($p_interval){ + + $hours = $p_interval->format("%h"); + $mins = $p_interval->format("%i"); + + if( $hours == 0) { + $runtime = $p_interval->format("%i:%S"); + } + else { + $runtime = $p_interval->format("%h:%I:%S"); + } + + return $runtime; + } + + private function makeFooterRow() { + + $row = $this->defaultRowArray; + $row["footer"] = true; + + return $row; + } + + private function makeHeaderRow($p_item) { + + $row = $this->defaultRowArray; + + $showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC")); + $showStartDT->setTimezone(new DateTimeZone($this->timezone)); + $showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC")); + $showEndDT->setTimezone(new DateTimeZone($this->timezone)); + + //$diff = + + $row["header"] = true; + $row["starts"] = $showStartDT->format("Y-m-d H:i"); + $row["ends"] = $showEndDT->format("Y-m-d H:i"); + $row["duration"] = $showEndDT->format("U") - $showStartDT->format("U"); + $row["title"] = $p_item["show_name"]; + $row["instance"] = intval($p_item["si_id"]); + + return $row; + } + + private function makeScheduledItemRow($p_item) { + $row = $this->defaultRowArray; + + if (isset($p_item["sched_starts"])) { + + $schedStartDT = new DateTime($p_item["sched_starts"], new DateTimeZone("UTC")); + $schedStartDT->setTimezone(new DateTimeZone($this->timezone)); + $schedEndDT = new DateTime($p_item["sched_ends"], new DateTimeZone("UTC")); + $schedEndDT->setTimezone(new DateTimeZone($this->timezone)); + + $runtime = $schedStartDT->diff($schedEndDT); + + $row["id"] = intval($p_item["sched_id"]); + $row["instance"] = intval($p_item["si_id"]); + $row["starts"] = $schedStartDT->format("H:i:s"); + $row["ends"] = $schedEndDT->format("H:i:s"); + $row["runtime"] = $this->formatDuration($runtime); + $row["title"] = $p_item["file_track_title"]; + $row["creator"] = $p_item["file_artist_name"]; + $row["album"] = $p_item["file_album_title"]; + + if ($this->user->canSchedule($item["show_id"]) === true) { + $row["checkbox"] = true; + } + } + //show is empty + else { + $row["empty"] = true; + $row["id"] = 0 ; + $row["instance"] = intval($p_item["si_id"]); + } + + return $row; + } + + public function GetItems() { + + $current_id = -1; + $display_items = array(); + + $scheduled_items = Application_Model_Schedule::GetScheduleDetailItems($this->startDT->format("Y-m-d H:i:s"), $this->endDT->format("Y-m-d H:i:s")); + + foreach ($scheduled_items as $item) { + + //make a header row. + if ($current_id !== $item["si_id"]) { + + //make a footer row. + if ($current_id !== -1) { + $display_items[] = $this->makeFooterRow(); + } + + $display_items[] = $this->makeHeaderRow($item); + + $current_id = $item["si_id"]; + } + + //make a normal data row. + $display_items[] = $this->makeScheduledItemRow($item); + } + + //make the last footer if there were any scheduled items. + if (count($scheduled_items) > 0) { + $display_items[] = $this->makeFooterRow(); + } + + return $display_items; + } +} \ No newline at end of file diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index c51ea3dfd..91ea82347 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -90,7 +90,7 @@ class Application_Model_StoredFile { } $this->setDbColMetadata($dbMd); } - + $this->_file->setDbMtime(new DateTime("now"), new DateTimeZone("UTC")); $this->_file->save(); } @@ -227,30 +227,6 @@ class Application_Model_StoredFile { return $md; } - /** - * Delete and insert media file - * - * @param string $p_localFilePath - * local path - * @return TRUE|PEAR_Error - */ - public function replaceFile($p_localFilePath, $p_copyMedia=TRUE) - { - // Dont do anything if the source and destination files are - // the same. - if ($this->name == $p_localFilePath) { - return TRUE; - } - - if ($this->exists) { - $r = $this->deleteFile(); - if (PEAR::isError($r)) { - return $r; - } - } - return $this->addFile($p_localFilePath, $p_copyMedia); - } - /** * Set state of virtual file * @@ -301,98 +277,30 @@ class Application_Model_StoredFile { * * @param boolean $p_deleteFile * - * @return void|PEAR_Error */ public function delete($deleteFromPlaylist=false) { - if ($this->exists()) { - if ($this->getFormat() == 'audioclip') { - $res = $this->deleteFile(); - if (PEAR::isError($res)) { - return $res; - } - } - } - - if($deleteFromPlaylist){ - Application_Model_Playlist::DeleteFileFromAllPlaylists($this->getId()); - } - - // set file_exists falg to false - $this->_file->setDbFileExists(false); - $this->_file->save(); - //$this->_file->delete(); - - if (isset($res)) { - return $res; - } - else { - return false; - } - } - - /** - * Delete media file from filesystem. - * You cant delete a file if it is being accessed. - * You cant delete a file if it is scheduled to be played in the future. - * The file will be removed from all playlists it is a part of. - * - * @return boolean|PEAR_Error - */ - public function deleteFile() - { - global $CC_CONFIG; - - if ($this->isAccessed()) { - return PEAR::raiseError('Cannot delete a file that is currently accessed.'); - } - - // Check if the file is scheduled to be played in the future - if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) { - return PEAR::raiseError('Cannot delete a file that is scheduled in the future.'); - } - - return true; - } - - /** - * Returns true if media file exists - * @return boolean - */ - public function exists() - { - if ($this->_file->isDeleted()) { - return false; - } - if ($this->getFormat() == 'audioclip') { - return $this->existsFile(); - } - } - - /** - * Returns true if raw media file exists - * @return boolean - */ - public function existsFile() { $filepath = $this->getFilePath(); - if (!isset($filepath) || !file_exists($filepath) || !is_readable($filepath)) { - return false; + // Check if the file is scheduled to be played in the future + if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) { + throw new DeleteScheduledFileException(); } - else { - return true; - } - } - /** - * Returns true if virtual file is currently in use.
- * - * @return boolean - */ - public function isAccessed() - { - return ($this->_file->getDbCurrentlyaccessing() > 0); + if (file_exists($filepath)) { + + $data = array("filepath" => $filepath, "delete" => 1); + Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); + } + + if ($deleteFromPlaylist){ + Application_Model_Playlist::DeleteFileFromAllPlaylists($this->getId()); + } + + // set file_exists falg to false + $this->_file->setDbFileExists(false); + $this->_file->save(); } /** @@ -419,10 +327,10 @@ class Application_Model_StoredFile { * @return string */ public function getFilePath() - { + { $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory()); $directory = $music_dir->getDirectory(); - + $filepath = $this->_file->getDbFilepath(); return $directory.$filepath; @@ -436,7 +344,7 @@ class Application_Model_StoredFile { public function setFilePath($p_filepath) { $path_info = Application_Model_MusicDir::splitFilePath($p_filepath); - + if (is_null($path_info)) { return -1; } @@ -506,7 +414,7 @@ class Application_Model_StoredFile { $storedFile->_file = $file; if(isset($md['MDATA_KEY_FILEPATH'])) { - // removed "//" in the path. Always use '/' for path separator + // removed "//" in the path. Always use '/' for path separator $filepath = str_replace("//", "/", $md['MDATA_KEY_FILEPATH']); $res = $storedFile->setFilePath($filepath); if ($res === -1) { @@ -643,6 +551,34 @@ class Application_Model_StoredFile { return $res; } +/* + * @param DateInterval $p_interval + * + * @return string $runtime + */ + private static function formatDuration($dt){ + + $hours = $dt->format("H"); + $min = $dt->format("i"); + $sec = $dt->format("s"); + + $time = "PT{$hours}H{$min}M{$sec}S"; + + $p_interval = new DateInterval($time); + + $hours = $p_interval->format("%h"); + $mins = $p_interval->format("%i"); + + if( $hours == 0) { + $runtime = $p_interval->format("%i:%S"); + } + else { + $runtime = $p_interval->format("%h:%I:%S"); + } + + return $runtime; + } + public static function searchFilesForPlaylistBuilder($datatables) { global $CC_CONFIG; @@ -660,11 +596,11 @@ class Application_Model_StoredFile { $plSelect .= "'playlist' AS ".$key.", "; $fileSelect .= $key.", "; } else if ($key === "artist_name") { - $plSelect .= "creator AS ".$key.", "; + $plSelect .= "login AS ".$key.", "; $fileSelect .= $key.", "; } else if ($key === "length") { $plSelect .= $key.", "; - $fileSelect .= $key.", "; + $fileSelect .= $key."::interval, "; } else if ($key === "year") { $plSelect .= "CAST(utime AS varchar) AS ".$key.", "; $fileSelect .= $key.", "; @@ -681,13 +617,19 @@ class Application_Model_StoredFile { } $fromTable = " ((".$plSelect."PL.id - FROM ".$CC_CONFIG["playListTable"]." AS PL - LEFT JOIN ".$CC_CONFIG['playListTimeView']." AS PLT USING(id)) + FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id)) UNION (".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES WHERE file_exists = 'TRUE')) AS RESULTS"; - + $results = Application_Model_StoredFile::searchFiles($fromTable, $datatables); + foreach($results['aaData'] as &$row){ + + $row['id'] = intval($row['id']); + + $length = new DateTime($row['length']); + $row['length'] = self::formatDuration($length); + // add checkbox row $row['checkbox'] = ""; @@ -695,7 +637,22 @@ class Application_Model_StoredFile { // split it and grab only the year info $yearSplit = explode('-', $row['year']); $row['year'] = $yearSplit[0]; + + $type = substr($row['ftype'], 0, 2); + + $row['tr_id'] = "{$type}_{$row['id']}"; + + //TODO url like this to work on both playlist/showbuilder screens. + //datatable stuff really needs to be pulled out and generalized within the project + //access to zend view methods to access url helpers is needed. + if($type == "au") { + $row['image'] = ''; + } + else { + $row['image'] = ''; + } } + return $results; } @@ -723,7 +680,8 @@ class Application_Model_StoredFile { unset($columnsDisplayed[$key]); } } - $selectorRows = "SELECT " . join(',', $columnsDisplayed ); + //$selectorRows = "SELECT " . join(',', $columnsDisplayed ); + $selectorRows = "SELECT * "; $sql = $selectorCount." FROM ".$fromTable; $totalRows = $CC_DBC->getOne($sql); @@ -774,9 +732,11 @@ class Application_Model_StoredFile { else { $sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"]; } - + + //Logging::log($sql); + $results = $CC_DBC->getAll($sql); - + if(!isset($totalDisplayRows)) { $totalDisplayRows = $totalRows; } @@ -905,6 +865,7 @@ class Application_Model_StoredFile { $audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName; Logging::log("copyFileToStor: moving file $audio_file to $audio_stor"); + //Martin K.: changed to rename: Much less load + quicker since this is an atomic operation $r = @rename($audio_file, $audio_stor); @@ -927,14 +888,14 @@ class Application_Model_StoredFile { } /** - * + * * Enter description here ... * @param $dir_id - if this is not provided, it returns all files with full path constructed. * @param $propelObj - if this is true, it returns array of proepl obj */ public static function listAllFiles($dir_id=null, $propelObj=false){ global $CC_DBC; - + if($propelObj){ $sql = "SELECT m.directory || f.filepath as fp" ." FROM CC_MUSIC_DIRS m" @@ -996,12 +957,12 @@ class Application_Model_StoredFile { public function getSoundCloudErrorMsg(){ return $this->_file->getDbSoundCloudErrorMsg(); } - + public function setFileExistsFlag($flag){ $this->_file->setDbFileExists($flag) ->save(); } - + public function getFileExistsFlag(){ return $this->_file->getDbFileExists(); } @@ -1048,3 +1009,4 @@ class Application_Model_StoredFile { } } +class DeleteScheduledFileException extends Exception {} diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php index 7e9862d0d..aa79e71bf 100644 --- a/airtime_mvc/application/models/User.php +++ b/airtime_mvc/application/models/User.php @@ -11,11 +11,16 @@ class Application_Model_User { public function __construct($userId) { - if (strlen($userId)==0){ + if (empty($userId)){ $this->_userInstance = $this->createUser(); - } else { + } + else { $this->_userInstance = CcSubjsQuery::create()->findPK($userId); - } + + if (is_null($this->_userInstance)){ + throw new Exception(); + } + } } public function getId() { @@ -29,7 +34,20 @@ class Application_Model_User { public function isAdmin() { return $this->isUserType(UTYPE_ADMIN); } - + + public function canSchedule($p_showId) { + $type = $this->getType(); + + if ( $type === UTYPE_ADMIN || + $type === UTYPE_PROGRAM_MANAGER || + CcShowHostsQuery::create()->filterByDbShow($p_showId)->filterByDbHost($this->getId())->count() > 0 ) + { + return true; + } + + return false; + } + public function isUserType($type, $showId=''){ if(is_array($type)){ $result = false; @@ -62,99 +80,99 @@ class Application_Model_User { } } } - + public function setLogin($login){ $user = $this->_userInstance; - $user->setDbLogin($login); + $user->setDbLogin($login); } - + public function setPassword($password){ $user = $this->_userInstance; - $user->setDbPass(md5($password)); + $user->setDbPass(md5($password)); } - + public function setFirstName($firstName){ $user = $this->_userInstance; - $user->setDbFirstName($firstName); + $user->setDbFirstName($firstName); } - + public function setLastName($lastName){ $user = $this->_userInstance; - $user->setDbLastName($lastName); + $user->setDbLastName($lastName); } - + public function setType($type){ $user = $this->_userInstance; - $user->setDbType($type); + $user->setDbType($type); } public function setEmail($email){ $user = $this->_userInstance; - $user->setDbEmail($email); + $user->setDbEmail($email); } public function setSkype($skype){ $user = $this->_userInstance; - $user->setDbSkypeContact($skype); + $user->setDbSkypeContact($skype); } public function setJabber($jabber){ $user = $this->_userInstance; - $user->setDbJabberContact($jabber); + $user->setDbJabberContact($jabber); } - + public function getLogin(){ $user = $this->_userInstance; - return $user->getDbLogin(); - } - + return $user->getDbLogin(); + } + public function getPassword(){ $user = $this->_userInstance; - return $user->getDbPass(); + return $user->getDbPass(); } - + public function getFirstName(){ $user = $this->_userInstance; - return $user->getDbFirstName(); + return $user->getDbFirstName(); } - + public function getLastName(){ $user = $this->_userInstance; - return $user->getDbLastName(); + return $user->getDbLastName(); } - + public function getType(){ $user = $this->_userInstance; - return $user->getDbType(); + return $user->getDbType(); } public function getEmail(){ $user = $this->_userInstance; - return $user->getDbEmail(); + return $user->getDbEmail(); } public function getSkype(){ $user = $this->_userInstance; - return $user->getDbSkypeContact(); + return $user->getDbSkypeContact(); } public function getJabber(){ $user = $this->_userInstance; - return $user->getDbJabberContact(); - + return $user->getDbJabberContact(); + } - + public function save(){ $this->_userInstance->save(); } - + public function delete(){ if (!$this->_userInstance->isDeleted()) $this->_userInstance->delete(); } private function createUser() { - $user = new CcSubjs(); + $user = new CcSubjs(); return $user; } @@ -165,7 +183,7 @@ class Application_Model_User { $sql_gen = "SELECT login AS value, login AS label, id as index FROM cc_subjs "; $sql = $sql_gen; - + if(is_array($type)) { for($i=0; $iGetAll($sql); + + return $CC_DBC->GetAll($sql); } - + public static function getUserCount($type=NULL){ global $CC_DBC; $sql; $sql_gen = "SELECT count(*) AS cnt FROM cc_subjs "; - + if(!isset($type)){ $sql = $sql_gen; } @@ -209,21 +227,21 @@ class Application_Model_User { else { $sql_type = "type = {$type}"; } - + $sql = $sql_gen ." WHERE (". $sql_type.") "; } - + return $CC_DBC->GetOne($sql); } public static function getHosts($search=NULL) { return Application_Model_User::getUsers(array('H'), $search); } - + public static function getUsersDataTablesInfo($datatables_post) { $fromTable = "cc_subjs"; - + // get current user $username = ""; $auth = Zend_Auth::getInstance(); @@ -231,9 +249,9 @@ class Application_Model_User { if ($auth->hasIdentity()) { $username = $auth->getIdentity()->login; } - + $res = Application_Model_StoredFile::searchFiles($fromTable, $datatables_post); - + // mark record which is for the current user foreach($res['aaData'] as &$record){ if($record['login'] == $username){ @@ -242,20 +260,20 @@ class Application_Model_User { $record['delete'] = ""; } } - + return $res; } - + public static function getUserData($id){ global $CC_DBC; - + $sql = "SELECT login, first_name, last_name, type, id, email, skype_contact, jabber_contact" ." FROM cc_subjs" ." WHERE id = $id"; - + return $CC_DBC->GetRow($sql); } - + public static function GetUserID($login){ $user = CcSubjsQuery::create()->findOneByDbLogin($login); if (is_null($user)){ @@ -265,4 +283,9 @@ class Application_Model_User { } } + public static function GetCurrentUser() { + $userinfo = Zend_Auth::getInstance()->getStorage()->read(); + + return new self($userinfo->id); + } } diff --git a/airtime_mvc/application/models/airtime/CcPlaylist.php b/airtime_mvc/application/models/airtime/CcPlaylist.php index 0d3cff401..c7303e8b1 100644 --- a/airtime_mvc/application/models/airtime/CcPlaylist.php +++ b/airtime_mvc/application/models/airtime/CcPlaylist.php @@ -5,7 +5,7 @@ /** * Skeleton subclass for representing a row from the 'cc_playlist' table. * - * + * * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as @@ -15,34 +15,66 @@ */ class CcPlaylist extends BaseCcPlaylist { - - public function computeLastPosition() + /** + * Get the [optionally formatted] temporal [utime] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw DateTime object will be returned. + * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getDbUtime($format = 'Y-m-d H:i:s') { - $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); + if ($this->utime === null) { + return null; + } - $sql = 'SELECT MAX('.CcPlaylistcontentsPeer::POSITION.') AS pos' - . ' FROM ' .CcPlaylistcontentsPeer::TABLE_NAME - . ' WHERE ' .CcPlaylistcontentsPeer::PLAYLIST_ID. ' = :p1'; + try { + $dt = new DateTime($this->utime, new DateTimeZone("UTC")); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->utime, true), $x); + } - $stmt = $con->prepare($sql); - $stmt->bindValue(':p1', $this->getDbId()); - $stmt->execute(); - return $stmt->fetchColumn(); + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } } - public function computeLength() + /** + * Get the [optionally formatted] temporal [mtime] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw DateTime object will be returned. + * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getDbMtime($format = 'Y-m-d H:i:s') { - $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); + if ($this->mtime === null) { + return null; + } - $sql = 'SELECT SUM('.CcPlaylistcontentsPeer::CLIPLENGTH.') AS length' - . ' FROM ' .CcPlaylistcontentsPeer::TABLE_NAME - . ' WHERE ' .CcPlaylistcontentsPeer::PLAYLIST_ID. ' = :p1'; + try { + $dt = new DateTime($this->mtime, new DateTimeZone("UTC")); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->mtime, true), $x); + } - $stmt = $con->prepare($sql); - $stmt->bindValue(':p1', $this->getDbId()); - $stmt->execute(); - return $stmt->fetchColumn(); + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } } - } // CcPlaylist diff --git a/airtime_mvc/application/models/airtime/CcPlaylistcontents.php b/airtime_mvc/application/models/airtime/CcPlaylistcontents.php index 1b6417a66..d71f66595 100644 --- a/airtime_mvc/application/models/airtime/CcPlaylistcontents.php +++ b/airtime_mvc/application/models/airtime/CcPlaylistcontents.php @@ -5,7 +5,7 @@ require_once('Common.php'); /** * Skeleton subclass for representing a row from the 'cc_playlistcontents' table. * - * + * * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as @@ -15,67 +15,5 @@ require_once('Common.php'); */ class CcPlaylistcontents extends BaseCcPlaylistcontents { - public function getDbFadein() - { - return $this->fadein; - } - - public function setDbFadein($time) - { - $this->fadein = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::FADEIN; - Common::setTimeInSub($this, 'FADEIN', $time); - } - - public function getDbFadeout() - { - return $this->fadeout; - } - - public function setDbFadeout($time) - { - $this->fadeout = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::FADEOUT; - Common::setTimeInSub($this, 'FADEOUT', $time); - } - - public function getDbCuein() - { - return $this->cuein; - } - - public function setDbCuein($time) - { - $this->cuein = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::CUEIN; - Common::setTimeInSub($this, 'CUEIN', $time); - } - - public function getDbCueout() - { - return $this->cueout; - } - - public function setDbCueout($time) - { - $this->cueout = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::CUEOUT; - Common::setTimeInSub($this, 'CUEOUT', $time); - } - - public function getDbCliplength() - { - return $this->cliplength; - } - - public function setDbCliplength($time) - { - $this->cliplength = $time; - //$this->modifiedColumns[] = CcPlaylistcontentsPeer::CLIPLENGTH; - Common::setTimeInSub($this, 'CLIPLENGTH', $time); - } - - - } // CcPlaylistcontents diff --git a/airtime_mvc/application/models/airtime/CcSchedule.php b/airtime_mvc/application/models/airtime/CcSchedule.php index 0193fbbf7..0484c350f 100644 --- a/airtime_mvc/application/models/airtime/CcSchedule.php +++ b/airtime_mvc/application/models/airtime/CcSchedule.php @@ -5,7 +5,7 @@ /** * Skeleton subclass for representing a row from the 'cc_schedule' table. * - * + * * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as @@ -15,4 +15,88 @@ */ class CcSchedule extends BaseCcSchedule { + public function getDbClipLength($format = 'H:i:s.u') + { + if ($this->clip_length === null) { + return null; + } + + try { + $dt = new DateTime($this->clip_length); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->clip_length, true), $x); + } + + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } + } + + /** + * Get the [optionally formatted] temporal [starts] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw DateTime object will be returned. + * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getDbStarts($format = 'Y-m-d H:i:s') + { + if ($this->starts === null) { + return null; + } + + try { + $dt = new DateTime($this->starts, new DateTimeZone("UTC")); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->starts, true), $x); + } + + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } + } + + /** + * Get the [optionally formatted] temporal [ends] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw DateTime object will be returned. + * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getDbEnds($format = 'Y-m-d H:i:s') + { + if ($this->ends === null) { + return null; + } + + try { + $dt = new DateTime($this->ends, new DateTimeZone("UTC")); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ends, true), $x); + } + + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } + } + } // CcSchedule diff --git a/airtime_mvc/application/models/airtime/CcShowInstances.php b/airtime_mvc/application/models/airtime/CcShowInstances.php index ae442a0b4..26d568f09 100644 --- a/airtime_mvc/application/models/airtime/CcShowInstances.php +++ b/airtime_mvc/application/models/airtime/CcShowInstances.php @@ -5,7 +5,7 @@ /** * Skeleton subclass for representing a row from the 'cc_show_instances' table. * - * + * * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as @@ -15,4 +15,65 @@ */ class CcShowInstances extends BaseCcShowInstances { + /** + * Get the [optionally formatted] temporal [starts] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw DateTime object will be returned. + * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getDbStarts($format = 'Y-m-d H:i:s') + { + if ($this->starts === null) { + return null; + } + + try { + $dt = new DateTime($this->starts, new DateTimeZone("UTC")); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->starts, true), $x); + } + + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } + } + + /** + * Get the [optionally formatted] temporal [ends] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw DateTime object will be returned. + * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getDbEnds($format = 'Y-m-d H:i:s') + { + if ($this->ends === null) { + return null; + } + + try { + $dt = new DateTime($this->ends, new DateTimeZone("UTC")); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ends, true), $x); + } + + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } + } } // CcShowInstances diff --git a/airtime_mvc/application/models/airtime/map/CcPlaylistTableMap.php b/airtime_mvc/application/models/airtime/map/CcPlaylistTableMap.php index 49cd3e309..543f0c6e2 100644 --- a/airtime_mvc/application/models/airtime/map/CcPlaylistTableMap.php +++ b/airtime_mvc/application/models/airtime/map/CcPlaylistTableMap.php @@ -40,14 +40,12 @@ class CcPlaylistTableMap extends TableMap { // columns $this->addPrimaryKey('ID', 'DbId', 'INTEGER', true, null, null); $this->addColumn('NAME', 'DbName', 'VARCHAR', true, 255, ''); - $this->addColumn('STATE', 'DbState', 'VARCHAR', true, 128, 'empty'); - $this->addColumn('CURRENTLYACCESSING', 'DbCurrentlyaccessing', 'INTEGER', true, null, 0); - $this->addForeignKey('EDITEDBY', 'DbEditedby', 'INTEGER', 'cc_subjs', 'ID', false, null, null); $this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', false, 6, null); $this->addColumn('UTIME', 'DbUtime', 'TIMESTAMP', false, 6, null); $this->addColumn('LPTIME', 'DbLPtime', 'TIMESTAMP', false, 6, null); - $this->addColumn('CREATOR', 'DbCreator', 'VARCHAR', false, 32, null); + $this->addForeignKey('CREATOR_ID', 'DbCreatorId', 'INTEGER', 'cc_subjs', 'ID', false, null, null); $this->addColumn('DESCRIPTION', 'DbDescription', 'VARCHAR', false, 512, null); + $this->addColumn('LENGTH', 'DbLength', 'VARCHAR', false, null, '00:00:00'); // validators } // initialize() @@ -56,8 +54,21 @@ class CcPlaylistTableMap extends TableMap { */ public function buildRelations() { - $this->addRelation('CcSubjs', 'CcSubjs', RelationMap::MANY_TO_ONE, array('editedby' => 'id', ), null, null); + $this->addRelation('CcSubjs', 'CcSubjs', RelationMap::MANY_TO_ONE, array('creator_id' => 'id', ), null, null); $this->addRelation('CcPlaylistcontents', 'CcPlaylistcontents', RelationMap::ONE_TO_MANY, array('id' => 'playlist_id', ), 'CASCADE', null); } // buildRelations() + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'aggregate_column' => array('name' => 'length', 'expression' => 'SUM(cliplength)', 'foreign_table' => 'cc_playlistcontents', ), + ); + } // getBehaviors() + } // CcPlaylistTableMap diff --git a/airtime_mvc/application/models/airtime/map/CcPlaylistcontentsTableMap.php b/airtime_mvc/application/models/airtime/map/CcPlaylistcontentsTableMap.php index b00f39ade..d654fb799 100644 --- a/airtime_mvc/application/models/airtime/map/CcPlaylistcontentsTableMap.php +++ b/airtime_mvc/application/models/airtime/map/CcPlaylistcontentsTableMap.php @@ -59,4 +59,17 @@ class CcPlaylistcontentsTableMap extends TableMap { $this->addRelation('CcPlaylist', 'CcPlaylist', RelationMap::MANY_TO_ONE, array('playlist_id' => 'id', ), 'CASCADE', null); } // buildRelations() + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'aggregate_column_relation' => array('foreign_table' => 'cc_playlist', 'update_method' => 'updateDbLength', ), + ); + } // getBehaviors() + } // CcPlaylistcontentsTableMap diff --git a/airtime_mvc/application/models/airtime/map/CcSubjsTableMap.php b/airtime_mvc/application/models/airtime/map/CcSubjsTableMap.php index 5a97a57cd..95d1c2844 100644 --- a/airtime_mvc/application/models/airtime/map/CcSubjsTableMap.php +++ b/airtime_mvc/application/models/airtime/map/CcSubjsTableMap.php @@ -62,7 +62,7 @@ class CcSubjsTableMap extends TableMap { $this->addRelation('CcFiles', 'CcFiles', RelationMap::ONE_TO_MANY, array('id' => 'editedby', ), null, null); $this->addRelation('CcPerms', 'CcPerms', RelationMap::ONE_TO_MANY, array('id' => 'subj', ), 'CASCADE', null); $this->addRelation('CcShowHosts', 'CcShowHosts', RelationMap::ONE_TO_MANY, array('id' => 'subjs_id', ), 'CASCADE', null); - $this->addRelation('CcPlaylist', 'CcPlaylist', RelationMap::ONE_TO_MANY, array('id' => 'editedby', ), null, null); + $this->addRelation('CcPlaylist', 'CcPlaylist', RelationMap::ONE_TO_MANY, array('id' => 'creator_id', ), null, null); $this->addRelation('CcPref', 'CcPref', RelationMap::ONE_TO_MANY, array('id' => 'subjid', ), 'CASCADE', null); $this->addRelation('CcSess', 'CcSess', RelationMap::ONE_TO_MANY, array('id' => 'userid', ), 'CASCADE', null); $this->addRelation('CcSubjsToken', 'CcSubjsToken', RelationMap::ONE_TO_MANY, array('id' => 'user_id', ), 'CASCADE', null); diff --git a/airtime_mvc/application/models/airtime/om/BaseCcPlaylist.php b/airtime_mvc/application/models/airtime/om/BaseCcPlaylist.php index d00e79d62..3231a5235 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcPlaylist.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcPlaylist.php @@ -37,26 +37,6 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent */ protected $name; - /** - * The value for the state field. - * Note: this column has a database default value of: 'empty' - * @var string - */ - protected $state; - - /** - * The value for the currentlyaccessing field. - * Note: this column has a database default value of: 0 - * @var int - */ - protected $currentlyaccessing; - - /** - * The value for the editedby field. - * @var int - */ - protected $editedby; - /** * The value for the mtime field. * @var string @@ -76,10 +56,10 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent protected $lptime; /** - * The value for the creator field. - * @var string + * The value for the creator_id field. + * @var int */ - protected $creator; + protected $creator_id; /** * The value for the description field. @@ -87,6 +67,13 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent */ protected $description; + /** + * The value for the length field. + * Note: this column has a database default value of: '00:00:00' + * @var string + */ + protected $length; + /** * @var CcSubjs */ @@ -120,8 +107,7 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent public function applyDefaultValues() { $this->name = ''; - $this->state = 'empty'; - $this->currentlyaccessing = 0; + $this->length = '00:00:00'; } /** @@ -154,36 +140,6 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent return $this->name; } - /** - * Get the [state] column value. - * - * @return string - */ - public function getDbState() - { - return $this->state; - } - - /** - * Get the [currentlyaccessing] column value. - * - * @return int - */ - public function getDbCurrentlyaccessing() - { - return $this->currentlyaccessing; - } - - /** - * Get the [editedby] column value. - * - * @return int - */ - public function getDbEditedby() - { - return $this->editedby; - } - /** * Get the [optionally formatted] temporal [mtime] column value. * @@ -284,13 +240,13 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent } /** - * Get the [creator] column value. + * Get the [creator_id] column value. * - * @return string + * @return int */ - public function getDbCreator() + public function getDbCreatorId() { - return $this->creator; + return $this->creator_id; } /** @@ -303,6 +259,16 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent return $this->description; } + /** + * Get the [length] column value. + * + * @return string + */ + public function getDbLength() + { + return $this->length; + } + /** * Set the value of [id] column. * @@ -343,70 +309,6 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent return $this; } // setDbName() - /** - * Set the value of [state] column. - * - * @param string $v new value - * @return CcPlaylist The current object (for fluent API support) - */ - public function setDbState($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->state !== $v || $this->isNew()) { - $this->state = $v; - $this->modifiedColumns[] = CcPlaylistPeer::STATE; - } - - return $this; - } // setDbState() - - /** - * Set the value of [currentlyaccessing] column. - * - * @param int $v new value - * @return CcPlaylist The current object (for fluent API support) - */ - public function setDbCurrentlyaccessing($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->currentlyaccessing !== $v || $this->isNew()) { - $this->currentlyaccessing = $v; - $this->modifiedColumns[] = CcPlaylistPeer::CURRENTLYACCESSING; - } - - return $this; - } // setDbCurrentlyaccessing() - - /** - * Set the value of [editedby] column. - * - * @param int $v new value - * @return CcPlaylist The current object (for fluent API support) - */ - public function setDbEditedby($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->editedby !== $v) { - $this->editedby = $v; - $this->modifiedColumns[] = CcPlaylistPeer::EDITEDBY; - } - - if ($this->aCcSubjs !== null && $this->aCcSubjs->getDbId() !== $v) { - $this->aCcSubjs = null; - } - - return $this; - } // setDbEditedby() - /** * Sets the value of [mtime] column to a normalized version of the date/time value specified. * @@ -555,24 +457,28 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent } // setDbLPtime() /** - * Set the value of [creator] column. + * Set the value of [creator_id] column. * - * @param string $v new value + * @param int $v new value * @return CcPlaylist The current object (for fluent API support) */ - public function setDbCreator($v) + public function setDbCreatorId($v) { if ($v !== null) { - $v = (string) $v; + $v = (int) $v; } - if ($this->creator !== $v) { - $this->creator = $v; - $this->modifiedColumns[] = CcPlaylistPeer::CREATOR; + if ($this->creator_id !== $v) { + $this->creator_id = $v; + $this->modifiedColumns[] = CcPlaylistPeer::CREATOR_ID; + } + + if ($this->aCcSubjs !== null && $this->aCcSubjs->getDbId() !== $v) { + $this->aCcSubjs = null; } return $this; - } // setDbCreator() + } // setDbCreatorId() /** * Set the value of [description] column. @@ -594,6 +500,26 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent return $this; } // setDbDescription() + /** + * Set the value of [length] column. + * + * @param string $v new value + * @return CcPlaylist The current object (for fluent API support) + */ + public function setDbLength($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->length !== $v || $this->isNew()) { + $this->length = $v; + $this->modifiedColumns[] = CcPlaylistPeer::LENGTH; + } + + return $this; + } // setDbLength() + /** * Indicates whether the columns in this object are only set to default values. * @@ -608,11 +534,7 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent return false; } - if ($this->state !== 'empty') { - return false; - } - - if ($this->currentlyaccessing !== 0) { + if ($this->length !== '00:00:00') { return false; } @@ -640,14 +562,12 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null; $this->name = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null; - $this->state = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null; - $this->currentlyaccessing = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null; - $this->editedby = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null; - $this->mtime = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null; - $this->utime = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null; - $this->lptime = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null; - $this->creator = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null; - $this->description = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null; + $this->mtime = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null; + $this->utime = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null; + $this->lptime = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null; + $this->creator_id = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null; + $this->description = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null; + $this->length = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null; $this->resetModified(); $this->setNew(false); @@ -656,7 +576,7 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent $this->ensureConsistency(); } - return $startcol + 10; // 10 = CcPlaylistPeer::NUM_COLUMNS - CcPlaylistPeer::NUM_LAZY_LOAD_COLUMNS). + return $startcol + 8; // 8 = CcPlaylistPeer::NUM_COLUMNS - CcPlaylistPeer::NUM_LAZY_LOAD_COLUMNS). } catch (Exception $e) { throw new PropelException("Error populating CcPlaylist object", $e); @@ -679,7 +599,7 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent public function ensureConsistency() { - if ($this->aCcSubjs !== null && $this->editedby !== $this->aCcSubjs->getDbId()) { + if ($this->aCcSubjs !== null && $this->creator_id !== $this->aCcSubjs->getDbId()) { $this->aCcSubjs = null; } } // ensureConsistency @@ -1008,29 +928,23 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent return $this->getDbName(); break; case 2: - return $this->getDbState(); - break; - case 3: - return $this->getDbCurrentlyaccessing(); - break; - case 4: - return $this->getDbEditedby(); - break; - case 5: return $this->getDbMtime(); break; - case 6: + case 3: return $this->getDbUtime(); break; - case 7: + case 4: return $this->getDbLPtime(); break; - case 8: - return $this->getDbCreator(); + case 5: + return $this->getDbCreatorId(); break; - case 9: + case 6: return $this->getDbDescription(); break; + case 7: + return $this->getDbLength(); + break; default: return null; break; @@ -1057,14 +971,12 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent $result = array( $keys[0] => $this->getDbId(), $keys[1] => $this->getDbName(), - $keys[2] => $this->getDbState(), - $keys[3] => $this->getDbCurrentlyaccessing(), - $keys[4] => $this->getDbEditedby(), - $keys[5] => $this->getDbMtime(), - $keys[6] => $this->getDbUtime(), - $keys[7] => $this->getDbLPtime(), - $keys[8] => $this->getDbCreator(), - $keys[9] => $this->getDbDescription(), + $keys[2] => $this->getDbMtime(), + $keys[3] => $this->getDbUtime(), + $keys[4] => $this->getDbLPtime(), + $keys[5] => $this->getDbCreatorId(), + $keys[6] => $this->getDbDescription(), + $keys[7] => $this->getDbLength(), ); if ($includeForeignObjects) { if (null !== $this->aCcSubjs) { @@ -1108,29 +1020,23 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent $this->setDbName($value); break; case 2: - $this->setDbState($value); - break; - case 3: - $this->setDbCurrentlyaccessing($value); - break; - case 4: - $this->setDbEditedby($value); - break; - case 5: $this->setDbMtime($value); break; - case 6: + case 3: $this->setDbUtime($value); break; - case 7: + case 4: $this->setDbLPtime($value); break; - case 8: - $this->setDbCreator($value); + case 5: + $this->setDbCreatorId($value); break; - case 9: + case 6: $this->setDbDescription($value); break; + case 7: + $this->setDbLength($value); + break; } // switch() } @@ -1157,14 +1063,12 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent if (array_key_exists($keys[0], $arr)) $this->setDbId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setDbName($arr[$keys[1]]); - if (array_key_exists($keys[2], $arr)) $this->setDbState($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setDbCurrentlyaccessing($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setDbEditedby($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setDbMtime($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setDbUtime($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setDbLPtime($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setDbCreator($arr[$keys[8]]); - if (array_key_exists($keys[9], $arr)) $this->setDbDescription($arr[$keys[9]]); + if (array_key_exists($keys[2], $arr)) $this->setDbMtime($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setDbUtime($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setDbLPtime($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setDbCreatorId($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setDbDescription($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setDbLength($arr[$keys[7]]); } /** @@ -1178,14 +1082,12 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent if ($this->isColumnModified(CcPlaylistPeer::ID)) $criteria->add(CcPlaylistPeer::ID, $this->id); if ($this->isColumnModified(CcPlaylistPeer::NAME)) $criteria->add(CcPlaylistPeer::NAME, $this->name); - if ($this->isColumnModified(CcPlaylistPeer::STATE)) $criteria->add(CcPlaylistPeer::STATE, $this->state); - if ($this->isColumnModified(CcPlaylistPeer::CURRENTLYACCESSING)) $criteria->add(CcPlaylistPeer::CURRENTLYACCESSING, $this->currentlyaccessing); - if ($this->isColumnModified(CcPlaylistPeer::EDITEDBY)) $criteria->add(CcPlaylistPeer::EDITEDBY, $this->editedby); if ($this->isColumnModified(CcPlaylistPeer::MTIME)) $criteria->add(CcPlaylistPeer::MTIME, $this->mtime); if ($this->isColumnModified(CcPlaylistPeer::UTIME)) $criteria->add(CcPlaylistPeer::UTIME, $this->utime); if ($this->isColumnModified(CcPlaylistPeer::LPTIME)) $criteria->add(CcPlaylistPeer::LPTIME, $this->lptime); - if ($this->isColumnModified(CcPlaylistPeer::CREATOR)) $criteria->add(CcPlaylistPeer::CREATOR, $this->creator); + if ($this->isColumnModified(CcPlaylistPeer::CREATOR_ID)) $criteria->add(CcPlaylistPeer::CREATOR_ID, $this->creator_id); if ($this->isColumnModified(CcPlaylistPeer::DESCRIPTION)) $criteria->add(CcPlaylistPeer::DESCRIPTION, $this->description); + if ($this->isColumnModified(CcPlaylistPeer::LENGTH)) $criteria->add(CcPlaylistPeer::LENGTH, $this->length); return $criteria; } @@ -1248,14 +1150,12 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent public function copyInto($copyObj, $deepCopy = false) { $copyObj->setDbName($this->name); - $copyObj->setDbState($this->state); - $copyObj->setDbCurrentlyaccessing($this->currentlyaccessing); - $copyObj->setDbEditedby($this->editedby); $copyObj->setDbMtime($this->mtime); $copyObj->setDbUtime($this->utime); $copyObj->setDbLPtime($this->lptime); - $copyObj->setDbCreator($this->creator); + $copyObj->setDbCreatorId($this->creator_id); $copyObj->setDbDescription($this->description); + $copyObj->setDbLength($this->length); if ($deepCopy) { // important: temporarily setNew(false) because this affects the behavior of @@ -1323,9 +1223,9 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent public function setCcSubjs(CcSubjs $v = null) { if ($v === null) { - $this->setDbEditedby(NULL); + $this->setDbCreatorId(NULL); } else { - $this->setDbEditedby($v->getDbId()); + $this->setDbCreatorId($v->getDbId()); } $this->aCcSubjs = $v; @@ -1349,8 +1249,8 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent */ public function getCcSubjs(PropelPDO $con = null) { - if ($this->aCcSubjs === null && ($this->editedby !== null)) { - $this->aCcSubjs = CcSubjsQuery::create()->findPk($this->editedby, $con); + if ($this->aCcSubjs === null && ($this->creator_id !== null)) { + $this->aCcSubjs = CcSubjsQuery::create()->findPk($this->creator_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be @@ -1503,14 +1403,12 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent { $this->id = null; $this->name = null; - $this->state = null; - $this->currentlyaccessing = null; - $this->editedby = null; $this->mtime = null; $this->utime = null; $this->lptime = null; - $this->creator = null; + $this->creator_id = null; $this->description = null; + $this->length = null; $this->alreadyInSave = false; $this->alreadyInValidation = false; $this->clearAllReferences(); @@ -1543,6 +1441,34 @@ abstract class BaseCcPlaylist extends BaseObject implements Persistent $this->aCcSubjs = null; } + // aggregate_column behavior + + /** + * Computes the value of the aggregate column length + * + * @param PropelPDO $con A connection object + * + * @return mixed The scalar result from the aggregate query + */ + public function computeDbLength(PropelPDO $con) + { + $stmt = $con->prepare('SELECT SUM(cliplength) FROM "cc_playlistcontents" WHERE cc_playlistcontents.PLAYLIST_ID = :p1'); + $stmt->bindValue(':p1', $this->getDbId()); + $stmt->execute(); + return $stmt->fetchColumn(); + } + + /** + * Updates the aggregate column length + * + * @param PropelPDO $con A connection object + */ + public function updateDbLength(PropelPDO $con) + { + $this->setDbLength($this->computeDbLength($con)); + $this->save($con); + } + /** * Catches calls to virtual methods */ diff --git a/airtime_mvc/application/models/airtime/om/BaseCcPlaylistPeer.php b/airtime_mvc/application/models/airtime/om/BaseCcPlaylistPeer.php index 067563842..9e23ce4fe 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcPlaylistPeer.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcPlaylistPeer.php @@ -26,7 +26,7 @@ abstract class BaseCcPlaylistPeer { const TM_CLASS = 'CcPlaylistTableMap'; /** The total number of columns. */ - const NUM_COLUMNS = 10; + const NUM_COLUMNS = 8; /** The number of lazy-loaded columns. */ const NUM_LAZY_LOAD_COLUMNS = 0; @@ -37,15 +37,6 @@ abstract class BaseCcPlaylistPeer { /** the column name for the NAME field */ const NAME = 'cc_playlist.NAME'; - /** the column name for the STATE field */ - const STATE = 'cc_playlist.STATE'; - - /** the column name for the CURRENTLYACCESSING field */ - const CURRENTLYACCESSING = 'cc_playlist.CURRENTLYACCESSING'; - - /** the column name for the EDITEDBY field */ - const EDITEDBY = 'cc_playlist.EDITEDBY'; - /** the column name for the MTIME field */ const MTIME = 'cc_playlist.MTIME'; @@ -55,12 +46,15 @@ abstract class BaseCcPlaylistPeer { /** the column name for the LPTIME field */ const LPTIME = 'cc_playlist.LPTIME'; - /** the column name for the CREATOR field */ - const CREATOR = 'cc_playlist.CREATOR'; + /** the column name for the CREATOR_ID field */ + const CREATOR_ID = 'cc_playlist.CREATOR_ID'; /** the column name for the DESCRIPTION field */ const DESCRIPTION = 'cc_playlist.DESCRIPTION'; + /** the column name for the LENGTH field */ + const LENGTH = 'cc_playlist.LENGTH'; + /** * An identiy map to hold any loaded instances of CcPlaylist objects. * This must be public so that other peer classes can access this when hydrating from JOIN @@ -77,12 +71,12 @@ abstract class BaseCcPlaylistPeer { * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ private static $fieldNames = array ( - BasePeer::TYPE_PHPNAME => array ('DbId', 'DbName', 'DbState', 'DbCurrentlyaccessing', 'DbEditedby', 'DbMtime', 'DbUtime', 'DbLPtime', 'DbCreator', 'DbDescription', ), - BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbName', 'dbState', 'dbCurrentlyaccessing', 'dbEditedby', 'dbMtime', 'dbUtime', 'dbLPtime', 'dbCreator', 'dbDescription', ), - BasePeer::TYPE_COLNAME => array (self::ID, self::NAME, self::STATE, self::CURRENTLYACCESSING, self::EDITEDBY, self::MTIME, self::UTIME, self::LPTIME, self::CREATOR, self::DESCRIPTION, ), - BasePeer::TYPE_RAW_COLNAME => array ('ID', 'NAME', 'STATE', 'CURRENTLYACCESSING', 'EDITEDBY', 'MTIME', 'UTIME', 'LPTIME', 'CREATOR', 'DESCRIPTION', ), - BasePeer::TYPE_FIELDNAME => array ('id', 'name', 'state', 'currentlyaccessing', 'editedby', 'mtime', 'utime', 'lptime', 'creator', 'description', ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + BasePeer::TYPE_PHPNAME => array ('DbId', 'DbName', 'DbMtime', 'DbUtime', 'DbLPtime', 'DbCreatorId', 'DbDescription', 'DbLength', ), + BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbName', 'dbMtime', 'dbUtime', 'dbLPtime', 'dbCreatorId', 'dbDescription', 'dbLength', ), + BasePeer::TYPE_COLNAME => array (self::ID, self::NAME, self::MTIME, self::UTIME, self::LPTIME, self::CREATOR_ID, self::DESCRIPTION, self::LENGTH, ), + BasePeer::TYPE_RAW_COLNAME => array ('ID', 'NAME', 'MTIME', 'UTIME', 'LPTIME', 'CREATOR_ID', 'DESCRIPTION', 'LENGTH', ), + BasePeer::TYPE_FIELDNAME => array ('id', 'name', 'mtime', 'utime', 'lptime', 'creator_id', 'description', 'length', ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, ) ); /** @@ -92,12 +86,12 @@ abstract class BaseCcPlaylistPeer { * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 */ private static $fieldKeys = array ( - BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbName' => 1, 'DbState' => 2, 'DbCurrentlyaccessing' => 3, 'DbEditedby' => 4, 'DbMtime' => 5, 'DbUtime' => 6, 'DbLPtime' => 7, 'DbCreator' => 8, 'DbDescription' => 9, ), - BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbName' => 1, 'dbState' => 2, 'dbCurrentlyaccessing' => 3, 'dbEditedby' => 4, 'dbMtime' => 5, 'dbUtime' => 6, 'dbLPtime' => 7, 'dbCreator' => 8, 'dbDescription' => 9, ), - BasePeer::TYPE_COLNAME => array (self::ID => 0, self::NAME => 1, self::STATE => 2, self::CURRENTLYACCESSING => 3, self::EDITEDBY => 4, self::MTIME => 5, self::UTIME => 6, self::LPTIME => 7, self::CREATOR => 8, self::DESCRIPTION => 9, ), - BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'NAME' => 1, 'STATE' => 2, 'CURRENTLYACCESSING' => 3, 'EDITEDBY' => 4, 'MTIME' => 5, 'UTIME' => 6, 'LPTIME' => 7, 'CREATOR' => 8, 'DESCRIPTION' => 9, ), - BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'name' => 1, 'state' => 2, 'currentlyaccessing' => 3, 'editedby' => 4, 'mtime' => 5, 'utime' => 6, 'lptime' => 7, 'creator' => 8, 'description' => 9, ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbName' => 1, 'DbMtime' => 2, 'DbUtime' => 3, 'DbLPtime' => 4, 'DbCreatorId' => 5, 'DbDescription' => 6, 'DbLength' => 7, ), + BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbName' => 1, 'dbMtime' => 2, 'dbUtime' => 3, 'dbLPtime' => 4, 'dbCreatorId' => 5, 'dbDescription' => 6, 'dbLength' => 7, ), + BasePeer::TYPE_COLNAME => array (self::ID => 0, self::NAME => 1, self::MTIME => 2, self::UTIME => 3, self::LPTIME => 4, self::CREATOR_ID => 5, self::DESCRIPTION => 6, self::LENGTH => 7, ), + BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'NAME' => 1, 'MTIME' => 2, 'UTIME' => 3, 'LPTIME' => 4, 'CREATOR_ID' => 5, 'DESCRIPTION' => 6, 'LENGTH' => 7, ), + BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'name' => 1, 'mtime' => 2, 'utime' => 3, 'lptime' => 4, 'creator_id' => 5, 'description' => 6, 'length' => 7, ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, ) ); /** @@ -171,25 +165,21 @@ abstract class BaseCcPlaylistPeer { if (null === $alias) { $criteria->addSelectColumn(CcPlaylistPeer::ID); $criteria->addSelectColumn(CcPlaylistPeer::NAME); - $criteria->addSelectColumn(CcPlaylistPeer::STATE); - $criteria->addSelectColumn(CcPlaylistPeer::CURRENTLYACCESSING); - $criteria->addSelectColumn(CcPlaylistPeer::EDITEDBY); $criteria->addSelectColumn(CcPlaylistPeer::MTIME); $criteria->addSelectColumn(CcPlaylistPeer::UTIME); $criteria->addSelectColumn(CcPlaylistPeer::LPTIME); - $criteria->addSelectColumn(CcPlaylistPeer::CREATOR); + $criteria->addSelectColumn(CcPlaylistPeer::CREATOR_ID); $criteria->addSelectColumn(CcPlaylistPeer::DESCRIPTION); + $criteria->addSelectColumn(CcPlaylistPeer::LENGTH); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.NAME'); - $criteria->addSelectColumn($alias . '.STATE'); - $criteria->addSelectColumn($alias . '.CURRENTLYACCESSING'); - $criteria->addSelectColumn($alias . '.EDITEDBY'); $criteria->addSelectColumn($alias . '.MTIME'); $criteria->addSelectColumn($alias . '.UTIME'); $criteria->addSelectColumn($alias . '.LPTIME'); - $criteria->addSelectColumn($alias . '.CREATOR'); + $criteria->addSelectColumn($alias . '.CREATOR_ID'); $criteria->addSelectColumn($alias . '.DESCRIPTION'); + $criteria->addSelectColumn($alias . '.LENGTH'); } } @@ -514,7 +504,7 @@ abstract class BaseCcPlaylistPeer { $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME, Propel::CONNECTION_READ); } - $criteria->addJoin(CcPlaylistPeer::EDITEDBY, CcSubjsPeer::ID, $join_behavior); + $criteria->addJoin(CcPlaylistPeer::CREATOR_ID, CcSubjsPeer::ID, $join_behavior); $stmt = BasePeer::doCount($criteria, $con); @@ -550,7 +540,7 @@ abstract class BaseCcPlaylistPeer { $startcol = (CcPlaylistPeer::NUM_COLUMNS - CcPlaylistPeer::NUM_LAZY_LOAD_COLUMNS); CcSubjsPeer::addSelectColumns($criteria); - $criteria->addJoin(CcPlaylistPeer::EDITEDBY, CcSubjsPeer::ID, $join_behavior); + $criteria->addJoin(CcPlaylistPeer::CREATOR_ID, CcSubjsPeer::ID, $join_behavior); $stmt = BasePeer::doSelect($criteria, $con); $results = array(); @@ -630,7 +620,7 @@ abstract class BaseCcPlaylistPeer { $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME, Propel::CONNECTION_READ); } - $criteria->addJoin(CcPlaylistPeer::EDITEDBY, CcSubjsPeer::ID, $join_behavior); + $criteria->addJoin(CcPlaylistPeer::CREATOR_ID, CcSubjsPeer::ID, $join_behavior); $stmt = BasePeer::doCount($criteria, $con); @@ -668,7 +658,7 @@ abstract class BaseCcPlaylistPeer { CcSubjsPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (CcSubjsPeer::NUM_COLUMNS - CcSubjsPeer::NUM_LAZY_LOAD_COLUMNS); - $criteria->addJoin(CcPlaylistPeer::EDITEDBY, CcSubjsPeer::ID, $join_behavior); + $criteria->addJoin(CcPlaylistPeer::CREATOR_ID, CcSubjsPeer::ID, $join_behavior); $stmt = BasePeer::doSelect($criteria, $con); $results = array(); diff --git a/airtime_mvc/application/models/airtime/om/BaseCcPlaylistQuery.php b/airtime_mvc/application/models/airtime/om/BaseCcPlaylistQuery.php index a61148f44..b1ae599f0 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcPlaylistQuery.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcPlaylistQuery.php @@ -8,25 +8,21 @@ * * @method CcPlaylistQuery orderByDbId($order = Criteria::ASC) Order by the id column * @method CcPlaylistQuery orderByDbName($order = Criteria::ASC) Order by the name column - * @method CcPlaylistQuery orderByDbState($order = Criteria::ASC) Order by the state column - * @method CcPlaylistQuery orderByDbCurrentlyaccessing($order = Criteria::ASC) Order by the currentlyaccessing column - * @method CcPlaylistQuery orderByDbEditedby($order = Criteria::ASC) Order by the editedby column * @method CcPlaylistQuery orderByDbMtime($order = Criteria::ASC) Order by the mtime column * @method CcPlaylistQuery orderByDbUtime($order = Criteria::ASC) Order by the utime column * @method CcPlaylistQuery orderByDbLPtime($order = Criteria::ASC) Order by the lptime column - * @method CcPlaylistQuery orderByDbCreator($order = Criteria::ASC) Order by the creator column + * @method CcPlaylistQuery orderByDbCreatorId($order = Criteria::ASC) Order by the creator_id column * @method CcPlaylistQuery orderByDbDescription($order = Criteria::ASC) Order by the description column + * @method CcPlaylistQuery orderByDbLength($order = Criteria::ASC) Order by the length column * * @method CcPlaylistQuery groupByDbId() Group by the id column * @method CcPlaylistQuery groupByDbName() Group by the name column - * @method CcPlaylistQuery groupByDbState() Group by the state column - * @method CcPlaylistQuery groupByDbCurrentlyaccessing() Group by the currentlyaccessing column - * @method CcPlaylistQuery groupByDbEditedby() Group by the editedby column * @method CcPlaylistQuery groupByDbMtime() Group by the mtime column * @method CcPlaylistQuery groupByDbUtime() Group by the utime column * @method CcPlaylistQuery groupByDbLPtime() Group by the lptime column - * @method CcPlaylistQuery groupByDbCreator() Group by the creator column + * @method CcPlaylistQuery groupByDbCreatorId() Group by the creator_id column * @method CcPlaylistQuery groupByDbDescription() Group by the description column + * @method CcPlaylistQuery groupByDbLength() Group by the length column * * @method CcPlaylistQuery leftJoin($relation) Adds a LEFT JOIN clause to the query * @method CcPlaylistQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query @@ -45,25 +41,21 @@ * * @method CcPlaylist findOneByDbId(int $id) Return the first CcPlaylist filtered by the id column * @method CcPlaylist findOneByDbName(string $name) Return the first CcPlaylist filtered by the name column - * @method CcPlaylist findOneByDbState(string $state) Return the first CcPlaylist filtered by the state column - * @method CcPlaylist findOneByDbCurrentlyaccessing(int $currentlyaccessing) Return the first CcPlaylist filtered by the currentlyaccessing column - * @method CcPlaylist findOneByDbEditedby(int $editedby) Return the first CcPlaylist filtered by the editedby column * @method CcPlaylist findOneByDbMtime(string $mtime) Return the first CcPlaylist filtered by the mtime column * @method CcPlaylist findOneByDbUtime(string $utime) Return the first CcPlaylist filtered by the utime column * @method CcPlaylist findOneByDbLPtime(string $lptime) Return the first CcPlaylist filtered by the lptime column - * @method CcPlaylist findOneByDbCreator(string $creator) Return the first CcPlaylist filtered by the creator column + * @method CcPlaylist findOneByDbCreatorId(int $creator_id) Return the first CcPlaylist filtered by the creator_id column * @method CcPlaylist findOneByDbDescription(string $description) Return the first CcPlaylist filtered by the description column + * @method CcPlaylist findOneByDbLength(string $length) Return the first CcPlaylist filtered by the length column * * @method array findByDbId(int $id) Return CcPlaylist objects filtered by the id column * @method array findByDbName(string $name) Return CcPlaylist objects filtered by the name column - * @method array findByDbState(string $state) Return CcPlaylist objects filtered by the state column - * @method array findByDbCurrentlyaccessing(int $currentlyaccessing) Return CcPlaylist objects filtered by the currentlyaccessing column - * @method array findByDbEditedby(int $editedby) Return CcPlaylist objects filtered by the editedby column * @method array findByDbMtime(string $mtime) Return CcPlaylist objects filtered by the mtime column * @method array findByDbUtime(string $utime) Return CcPlaylist objects filtered by the utime column * @method array findByDbLPtime(string $lptime) Return CcPlaylist objects filtered by the lptime column - * @method array findByDbCreator(string $creator) Return CcPlaylist objects filtered by the creator column + * @method array findByDbCreatorId(int $creator_id) Return CcPlaylist objects filtered by the creator_id column * @method array findByDbDescription(string $description) Return CcPlaylist objects filtered by the description column + * @method array findByDbLength(string $length) Return CcPlaylist objects filtered by the length column * * @package propel.generator.airtime.om */ @@ -212,90 +204,6 @@ abstract class BaseCcPlaylistQuery extends ModelCriteria return $this->addUsingAlias(CcPlaylistPeer::NAME, $dbName, $comparison); } - /** - * Filter the query on the state column - * - * @param string $dbState The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return CcPlaylistQuery The current query, for fluid interface - */ - public function filterByDbState($dbState = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($dbState)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $dbState)) { - $dbState = str_replace('*', '%', $dbState); - $comparison = Criteria::LIKE; - } - } - return $this->addUsingAlias(CcPlaylistPeer::STATE, $dbState, $comparison); - } - - /** - * Filter the query on the currentlyaccessing column - * - * @param int|array $dbCurrentlyaccessing The value to use as filter. - * Accepts an associative array('min' => $minValue, 'max' => $maxValue) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return CcPlaylistQuery The current query, for fluid interface - */ - public function filterByDbCurrentlyaccessing($dbCurrentlyaccessing = null, $comparison = null) - { - if (is_array($dbCurrentlyaccessing)) { - $useMinMax = false; - if (isset($dbCurrentlyaccessing['min'])) { - $this->addUsingAlias(CcPlaylistPeer::CURRENTLYACCESSING, $dbCurrentlyaccessing['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($dbCurrentlyaccessing['max'])) { - $this->addUsingAlias(CcPlaylistPeer::CURRENTLYACCESSING, $dbCurrentlyaccessing['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - return $this->addUsingAlias(CcPlaylistPeer::CURRENTLYACCESSING, $dbCurrentlyaccessing, $comparison); - } - - /** - * Filter the query on the editedby column - * - * @param int|array $dbEditedby The value to use as filter. - * Accepts an associative array('min' => $minValue, 'max' => $maxValue) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return CcPlaylistQuery The current query, for fluid interface - */ - public function filterByDbEditedby($dbEditedby = null, $comparison = null) - { - if (is_array($dbEditedby)) { - $useMinMax = false; - if (isset($dbEditedby['min'])) { - $this->addUsingAlias(CcPlaylistPeer::EDITEDBY, $dbEditedby['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($dbEditedby['max'])) { - $this->addUsingAlias(CcPlaylistPeer::EDITEDBY, $dbEditedby['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - return $this->addUsingAlias(CcPlaylistPeer::EDITEDBY, $dbEditedby, $comparison); - } - /** * Filter the query on the mtime column * @@ -390,25 +298,34 @@ abstract class BaseCcPlaylistQuery extends ModelCriteria } /** - * Filter the query on the creator column + * Filter the query on the creator_id column * - * @param string $dbCreator The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) + * @param int|array $dbCreatorId The value to use as filter. + * Accepts an associative array('min' => $minValue, 'max' => $maxValue) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return CcPlaylistQuery The current query, for fluid interface */ - public function filterByDbCreator($dbCreator = null, $comparison = null) + public function filterByDbCreatorId($dbCreatorId = null, $comparison = null) { - if (null === $comparison) { - if (is_array($dbCreator)) { + if (is_array($dbCreatorId)) { + $useMinMax = false; + if (isset($dbCreatorId['min'])) { + $this->addUsingAlias(CcPlaylistPeer::CREATOR_ID, $dbCreatorId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($dbCreatorId['max'])) { + $this->addUsingAlias(CcPlaylistPeer::CREATOR_ID, $dbCreatorId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $dbCreator)) { - $dbCreator = str_replace('*', '%', $dbCreator); - $comparison = Criteria::LIKE; } } - return $this->addUsingAlias(CcPlaylistPeer::CREATOR, $dbCreator, $comparison); + return $this->addUsingAlias(CcPlaylistPeer::CREATOR_ID, $dbCreatorId, $comparison); } /** @@ -433,6 +350,28 @@ abstract class BaseCcPlaylistQuery extends ModelCriteria return $this->addUsingAlias(CcPlaylistPeer::DESCRIPTION, $dbDescription, $comparison); } + /** + * Filter the query on the length column + * + * @param string $dbLength The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return CcPlaylistQuery The current query, for fluid interface + */ + public function filterByDbLength($dbLength = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($dbLength)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $dbLength)) { + $dbLength = str_replace('*', '%', $dbLength); + $comparison = Criteria::LIKE; + } + } + return $this->addUsingAlias(CcPlaylistPeer::LENGTH, $dbLength, $comparison); + } + /** * Filter the query by a related CcSubjs object * @@ -444,7 +383,7 @@ abstract class BaseCcPlaylistQuery extends ModelCriteria public function filterByCcSubjs($ccSubjs, $comparison = null) { return $this - ->addUsingAlias(CcPlaylistPeer::EDITEDBY, $ccSubjs->getDbId(), $comparison); + ->addUsingAlias(CcPlaylistPeer::CREATOR_ID, $ccSubjs->getDbId(), $comparison); } /** diff --git a/airtime_mvc/application/models/airtime/om/BaseCcPlaylistcontents.php b/airtime_mvc/application/models/airtime/om/BaseCcPlaylistcontents.php index 0118d5038..457a9b958 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcPlaylistcontents.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcPlaylistcontents.php @@ -107,6 +107,9 @@ abstract class BaseCcPlaylistcontents extends BaseObject implements Persistent */ protected $alreadyInValidation = false; + // aggregate_column_relation behavior + protected $oldCcPlaylist; + /** * Applies default values to this object. * This method should be called from the object's constructor (or @@ -895,6 +898,8 @@ abstract class BaseCcPlaylistcontents extends BaseObject implements Persistent $this->postUpdate($con); } $this->postSave($con); + // aggregate_column_relation behavior + $this->updateRelatedCcPlaylist($con); CcPlaylistcontentsPeer::addInstanceToPool($this); } else { $affectedRows = 0; @@ -1437,6 +1442,10 @@ abstract class BaseCcPlaylistcontents extends BaseObject implements Persistent */ public function setCcPlaylist(CcPlaylist $v = null) { + // aggregate_column_relation behavior + if (null !== $this->aCcPlaylist && $v !== $this->aCcPlaylist) { + $this->oldCcPlaylist = $this->aCcPlaylist; + } if ($v === null) { $this->setDbPlaylistId(NULL); } else { @@ -1518,6 +1527,24 @@ abstract class BaseCcPlaylistcontents extends BaseObject implements Persistent $this->aCcPlaylist = null; } + // aggregate_column_relation behavior + + /** + * Update the aggregate column in the related CcPlaylist object + * + * @param PropelPDO $con A connection object + */ + protected function updateRelatedCcPlaylist(PropelPDO $con) + { + if ($ccPlaylist = $this->getCcPlaylist()) { + $ccPlaylist->updateDbLength($con); + } + if ($this->oldCcPlaylist) { + $this->oldCcPlaylist->updateDbLength($con); + $this->oldCcPlaylist = null; + } + } + /** * Catches calls to virtual methods */ diff --git a/airtime_mvc/application/models/airtime/om/BaseCcPlaylistcontentsQuery.php b/airtime_mvc/application/models/airtime/om/BaseCcPlaylistcontentsQuery.php index 6c717c6c6..85262c7bd 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcPlaylistcontentsQuery.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcPlaylistcontentsQuery.php @@ -578,4 +578,90 @@ abstract class BaseCcPlaylistcontentsQuery extends ModelCriteria return $this; } + /** + * Code to execute before every DELETE statement + * + * @param PropelPDO $con The connection object used by the query + */ + protected function basePreDelete(PropelPDO $con) + { + // aggregate_column_relation behavior + $this->findRelatedCcPlaylists($con); + + return $this->preDelete($con); + } + + /** + * Code to execute after every DELETE statement + * + * @param int $affectedRows the number of deleted rows + * @param PropelPDO $con The connection object used by the query + */ + protected function basePostDelete($affectedRows, PropelPDO $con) + { + // aggregate_column_relation behavior + $this->updateRelatedCcPlaylists($con); + + return $this->postDelete($affectedRows, $con); + } + + /** + * Code to execute before every UPDATE statement + * + * @param array $values The associatiove array of columns and values for the update + * @param PropelPDO $con The connection object used by the query + * @param boolean $forceIndividualSaves If false (default), the resulting call is a BasePeer::doUpdate(), ortherwise it is a series of save() calls on all the found objects + */ + protected function basePreUpdate(&$values, PropelPDO $con, $forceIndividualSaves = false) + { + // aggregate_column_relation behavior + $this->findRelatedCcPlaylists($con); + + return $this->preUpdate($values, $con, $forceIndividualSaves); + } + + /** + * Code to execute after every UPDATE statement + * + * @param int $affectedRows the number of udated rows + * @param PropelPDO $con The connection object used by the query + */ + protected function basePostUpdate($affectedRows, PropelPDO $con) + { + // aggregate_column_relation behavior + $this->updateRelatedCcPlaylists($con); + + return $this->postUpdate($affectedRows, $con); + } + + // aggregate_column_relation behavior + + /** + * Finds the related CcPlaylist objects and keep them for later + * + * @param PropelPDO $con A connection object + */ + protected function findRelatedCcPlaylists($con) + { + $criteria = clone $this; + if ($this->useAliasInSQL) { + $alias = $this->getModelAlias(); + $criteria->removeAlias($alias); + } else { + $alias = ''; + } + $this->ccPlaylists = CcPlaylistQuery::create() + ->joinCcPlaylistcontents($alias) + ->mergeWith($criteria) + ->find($con); + } + + protected function updateRelatedCcPlaylists($con) + { + foreach ($this->ccPlaylists as $ccPlaylist) { + $ccPlaylist->updateDbLength($con); + } + $this->ccPlaylists = array(); + } + } // BaseCcPlaylistcontentsQuery diff --git a/airtime_mvc/application/models/airtime/om/BaseCcSubjsQuery.php b/airtime_mvc/application/models/airtime/om/BaseCcSubjsQuery.php index c921e7394..0d987e281 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcSubjsQuery.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcSubjsQuery.php @@ -758,7 +758,7 @@ abstract class BaseCcSubjsQuery extends ModelCriteria public function filterByCcPlaylist($ccPlaylist, $comparison = null) { return $this - ->addUsingAlias(CcSubjsPeer::ID, $ccPlaylist->getDbEditedby(), $comparison); + ->addUsingAlias(CcSubjsPeer::ID, $ccPlaylist->getDbCreatorId(), $comparison); } /** diff --git a/airtime_mvc/application/views/scripts/library/get-file-meta-data.ajax.phtml b/airtime_mvc/application/views/scripts/library/get-file-meta-data.ajax.phtml index 43af9afcf..77fcdf933 100644 --- a/airtime_mvc/application/views/scripts/library/get-file-meta-data.ajax.phtml +++ b/airtime_mvc/application/views/scripts/library/get-file-meta-data.ajax.phtml @@ -1,4 +1,4 @@ -type == "au") : ?> +type == "audioclip") : ?>
Title:md["MDATA_KEY_TITLE"]);?>
Artist:md["MDATA_KEY_CREATOR"]);?>
Album:md["MDATA_KEY_SOURCE"]);?>
@@ -19,7 +19,7 @@ -type == "pl") : ?> +type == "playlist") : ?>
Name:md["dc:title"]);?>
Creator:md["dc:creator"]);?>
Length:md["dcterms:extent"]);?>
diff --git a/airtime_mvc/application/views/scripts/library/index.phtml b/airtime_mvc/application/views/scripts/library/index.phtml index bfb8b78b3..e69de29bb 100644 --- a/airtime_mvc/application/views/scripts/library/index.phtml +++ b/airtime_mvc/application/views/scripts/library/index.phtml @@ -1,18 +0,0 @@ - -
- - - -
-
- diff --git a/airtime_mvc/application/views/scripts/library/library.phtml b/airtime_mvc/application/views/scripts/library/library.phtml new file mode 100644 index 000000000..d1f8d7cb8 --- /dev/null +++ b/airtime_mvc/application/views/scripts/library/library.phtml @@ -0,0 +1,9 @@ + +
+ + + +
+
diff --git a/airtime_mvc/application/views/scripts/playlist/index.phtml b/airtime_mvc/application/views/scripts/playlist/index.phtml index 6f4d6836b..e1c14e724 100644 --- a/airtime_mvc/application/views/scripts/playlist/index.phtml +++ b/airtime_mvc/application/views/scripts/playlist/index.phtml @@ -1,12 +1,14 @@ - + pl)) : ?> - + Playlist crossfade pl)) : ?> + +

pl->getName(); ?> diff --git a/airtime_mvc/application/views/scripts/playlist/set-cue.phtml b/airtime_mvc/application/views/scripts/playlist/set-cue.phtml index eb35d17fc..4b44e51ac 100644 --- a/airtime_mvc/application/views/scripts/playlist/set-cue.phtml +++ b/airtime_mvc/application/views/scripts/playlist/set-cue.phtml @@ -1,11 +1,11 @@
Cue In:
-
+
cueIn; ?>
Cue Out:
-
+
cueOut; ?>
diff --git a/airtime_mvc/application/views/scripts/playlist/set-fade.phtml b/airtime_mvc/application/views/scripts/playlist/set-fade.phtml index 1c9135323..4a55fb2db 100644 --- a/airtime_mvc/application/views/scripts/playlist/set-fade.phtml +++ b/airtime_mvc/application/views/scripts/playlist/set-fade.phtml @@ -1,11 +1,11 @@
Fade out:
-
+
fadeOut; ?>
Fade in:
-
+
fadeIn; ?>
diff --git a/airtime_mvc/application/views/scripts/playlist/update.phtml b/airtime_mvc/application/views/scripts/playlist/update.phtml index b003349da..bd55a9f94 100644 --- a/airtime_mvc/application/views/scripts/playlist/update.phtml +++ b/airtime_mvc/application/views/scripts/playlist/update.phtml @@ -4,7 +4,7 @@ if (count($items)) : ?> -
  • "> +
  • " unqid="">