From aec0e348c4bd93d1cfb21165f535e71da6c5c6e2 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Fri, 18 Aug 2017 00:46:59 -0400 Subject: [PATCH 1/3] Working code to auto generated Smartblock and Playlist for new Podcasts --- .../application/forms/GeneralPreferences.php | 1 + .../application/services/PodcastService.php | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php index d7ac46f37..e52b5e5cb 100644 --- a/airtime_mvc/application/forms/GeneralPreferences.php +++ b/airtime_mvc/application/forms/GeneralPreferences.php @@ -117,6 +117,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm )); $this->addElement($podcast_album_override); + //TODO add and insert Podcast Smartblock and Playlist autogenerate options $third_party_api = new Zend_Form_Element_Radio('thirdPartyApi'); $third_party_api->setLabel(_('Public Airtime API')); diff --git a/airtime_mvc/application/services/PodcastService.php b/airtime_mvc/application/services/PodcastService.php index 73039f863..f3d9062da 100644 --- a/airtime_mvc/application/services/PodcastService.php +++ b/airtime_mvc/application/services/PodcastService.php @@ -147,6 +147,11 @@ class Application_Service_PodcastService $importedPodcast->setDbAutoIngest(true); $importedPodcast->save(); + // need to add an if statement to check if this option is enabled + self::createPodcastSmartblockAndPlaylist($podcast); + + + return $podcast->toArray(BasePeer::TYPE_FIELDNAME); } catch(Exception $e) { $podcast->delete(); @@ -154,6 +159,53 @@ class Application_Service_PodcastService } } + public static function createPodcastSmartblockAndPlaylist($podcast) + { + + // need to check that album override is either globally enabled or enabled for this podcast + // also need to check an option + // right here need to create new smartblock and playlist with same name as podcast title + $newBl = new Application_Model_Block(); + $newBl->setCreator(Application_Model_User::getCurrentUser()->getId()); + $newBl->setName($podcast->getDbTitle()); + $newBl->setDescription('Auto-generated smartblock for podcast'); + $newBl->saveType('dynamic'); + // limit the smartblock to 1 item + $row = new CcBlockcriteria(); + $row->setDbCriteria('limit'); + $row->setDbModifier('items'); + $row->setDbValue(1); + $row->setDbBlockId($newBl->getId()); + $row->save(); + + // sort so that it is the newest item + $row = new CcBlockcriteria(); + $row->setDbCriteria('sort'); + $row->setDbModifier('N/A'); + $row->setDbValue('newest'); + $row->setDbBlockId($newBl->getId()); + $row->save(); + + // match the track by ensuring the album title matches the podcast + $row = new CcBlockcriteria(); + $row->setDbCriteria('album_title'); + $row->setDbModifier('is'); + $row->setDbValue($newBl->getName()); + $row->setDbBlockId($newBl->getId()); + $row->save(); + + //TODO create a playlist that contains only this SmartBlock + + $newPl = new Application_Model_Playlist(); + $newPl->setName($podcast->getDbTitle()); + $newPl->setCreator(Application_Model_User::getCurrentUser()->getId()); + $row = new CcPlaylistcontents(); + $row->setDbBlockId($newBl->getId()); + $row->setDbPlaylistId($newPl->getId()); + $row->setDbType(2); + $row->save(); + } + public static function createStationPodcast() { $podcast = new Podcast(); From 3515a898a777c6762dc4180491ebbda86cef18c9 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Wed, 23 Aug 2017 12:16:42 -0400 Subject: [PATCH 2/3] Added option for Auto Smartblock and Playlist creation to preferences --- .../controllers/PreferenceController.php | 1 + .../application/forms/GeneralPreferences.php | 17 +++- airtime_mvc/application/models/Preference.php | 12 +++ .../application/services/PodcastService.php | 87 ++++++++++--------- .../scripts/form/preferences_general.phtml | 2 + 5 files changed, 75 insertions(+), 44 deletions(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index f1d14a489..6c9b0bfd9 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -46,6 +46,7 @@ class PreferenceController extends Zend_Controller_Action Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]); Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]); Application_Model_Preference::SetPodcastAlbumOverride($values["podcastAlbumOverride"]); + Application_Model_Preference::SetPodcastAutoSmartblock($values["podcastAutoSmartblock"]); Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]); Application_Model_Preference::SetAllowedCorsUrls($values["allowedCorsUrls"]); Application_Model_Preference::SetDefaultLocale($values["locale"]); diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php index e52b5e5cb..924264751 100644 --- a/airtime_mvc/application/forms/GeneralPreferences.php +++ b/airtime_mvc/application/forms/GeneralPreferences.php @@ -110,13 +110,28 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $podcast_album_override->setValue(Application_Model_Preference::GetPodcastAlbumOverride()); $podcast_album_override->setDescription(_('Enabling this means that podcast tracks will always contain the podcast name in their album field.')); $podcast_album_override->setSeparator(' '); //No
between radio buttons - //$third_party_api->addDecorator(new Zend_Form_Decorator_Label(array('tag' => 'dd', 'class' => 'radio-inline-list'))); $podcast_album_override->addDecorator('HtmlTag', array('tag' => 'dd', 'id'=>"podcastAlbumOverride-element", 'class' => 'radio-inline-list', )); $this->addElement($podcast_album_override); + $podcast_auto_smartblock = new Zend_Form_Element_Radio('podcastAutoSmartblock'); + $podcast_auto_smartblock->setLabel(_('Podcast Automatic Smartblock and Playlist')); + $podcast_auto_smartblock->setMultiOptions(array( + _("Disabled"), + _("Enabled"), + )); + $podcast_auto_smartblock->setValue(Application_Model_Preference::GetPodcastAutoSmartblock()); + $podcast_auto_smartblock->setDescription(_('Enabling this means that a smartblock and playlist matching the newest track of a + podcast will be created when a new podcast is added. This depends upon the Podcast Album Override to work.')); + $podcast_auto_smartblock->setSeparator(' '); //No
between radio buttons + $podcast_auto_smartblock->addDecorator('HtmlTag', array('tag' => 'dd', + 'id'=>"podcastAutoSmartblock-element", + 'class' => 'radio-inline-list', + )); + $this->addElement($podcast_auto_smartblock); + //TODO add and insert Podcast Smartblock and Playlist autogenerate options $third_party_api = new Zend_Form_Element_Radio('thirdPartyApi'); diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 296915956..4dee92700 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -376,6 +376,18 @@ class Application_Model_Preference return $val === '1' ? true : false; } + public static function SetPodcastAutoSmartblock($bool) + { + self::setValue("podcast_auto_smartblock", $bool); + } + + public static function GetPodcastAutoSmartblock() + { + $val = self::getValue("podcast_auto_smartblock"); + return $val === '1' ? true : false; + } + + public static function SetPhone($phone) { self::setValue("phone", $phone); diff --git a/airtime_mvc/application/services/PodcastService.php b/airtime_mvc/application/services/PodcastService.php index f3d9062da..1a57e6515 100644 --- a/airtime_mvc/application/services/PodcastService.php +++ b/airtime_mvc/application/services/PodcastService.php @@ -147,9 +147,10 @@ class Application_Service_PodcastService $importedPodcast->setDbAutoIngest(true); $importedPodcast->save(); - // need to add an if statement to check if this option is enabled - self::createPodcastSmartblockAndPlaylist($podcast); - + // if the autosmartblock and album override are enabled then create a smartblock and playlist matching this podcast via the album name + if (Application_Model_Preference::GetPodcastAutoSmartblock() && Application_Model_Preference::GetPodcastAlbumOverride()) { + self::createPodcastSmartblockAndPlaylist($podcast); + } return $podcast->toArray(BasePeer::TYPE_FIELDNAME); @@ -159,52 +160,52 @@ class Application_Service_PodcastService } } + /** + * @param $podcast + * This will automatically create a smartblock and playlist for this podcast. + */ + public static function createPodcastSmartblockAndPlaylist($podcast) { + $newBl = new Application_Model_Block(); + $newBl->setCreator(Application_Model_User::getCurrentUser()->getId()); + $newBl->setName($podcast->getDbTitle()); + $newBl->setDescription('Auto-generated smartblock for podcast'); + $newBl->saveType('dynamic'); + // limit the smartblock to 1 item + $row = new CcBlockcriteria(); + $row->setDbCriteria('limit'); + $row->setDbModifier('items'); + $row->setDbValue(1); + $row->setDbBlockId($newBl->getId()); + $row->save(); - // need to check that album override is either globally enabled or enabled for this podcast - // also need to check an option - // right here need to create new smartblock and playlist with same name as podcast title - $newBl = new Application_Model_Block(); - $newBl->setCreator(Application_Model_User::getCurrentUser()->getId()); - $newBl->setName($podcast->getDbTitle()); - $newBl->setDescription('Auto-generated smartblock for podcast'); - $newBl->saveType('dynamic'); - // limit the smartblock to 1 item - $row = new CcBlockcriteria(); - $row->setDbCriteria('limit'); - $row->setDbModifier('items'); - $row->setDbValue(1); - $row->setDbBlockId($newBl->getId()); - $row->save(); + // sort so that it is the newest item + $row = new CcBlockcriteria(); + $row->setDbCriteria('sort'); + $row->setDbModifier('N/A'); + $row->setDbValue('newest'); + $row->setDbBlockId($newBl->getId()); + $row->save(); - // sort so that it is the newest item - $row = new CcBlockcriteria(); - $row->setDbCriteria('sort'); - $row->setDbModifier('N/A'); - $row->setDbValue('newest'); - $row->setDbBlockId($newBl->getId()); - $row->save(); + // match the track by ensuring the album title matches the podcast + $row = new CcBlockcriteria(); + $row->setDbCriteria('album_title'); + $row->setDbModifier('is'); + $row->setDbValue($newBl->getName()); + $row->setDbBlockId($newBl->getId()); + $row->save(); - // match the track by ensuring the album title matches the podcast - $row = new CcBlockcriteria(); - $row->setDbCriteria('album_title'); - $row->setDbModifier('is'); - $row->setDbValue($newBl->getName()); - $row->setDbBlockId($newBl->getId()); - $row->save(); + $newPl = new Application_Model_Playlist(); + $newPl->setName($podcast->getDbTitle()); + $newPl->setCreator(Application_Model_User::getCurrentUser()->getId()); + $row = new CcPlaylistcontents(); + $row->setDbBlockId($newBl->getId()); + $row->setDbPlaylistId($newPl->getId()); + $row->setDbType(2); + $row->save(); + } - //TODO create a playlist that contains only this SmartBlock - - $newPl = new Application_Model_Playlist(); - $newPl->setName($podcast->getDbTitle()); - $newPl->setCreator(Application_Model_User::getCurrentUser()->getId()); - $row = new CcPlaylistcontents(); - $row->setDbBlockId($newBl->getId()); - $row->setDbPlaylistId($newPl->getId()); - $row->setDbType(2); - $row->save(); - } public static function createStationPodcast() { diff --git a/airtime_mvc/application/views/scripts/form/preferences_general.phtml b/airtime_mvc/application/views/scripts/form/preferences_general.phtml index 61dbfeabe..8e9c63562 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_general.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_general.phtml @@ -33,6 +33,8 @@ element->getElement('podcastAlbumOverride')->render() ?> + element->getElement('podcastAutoSmartblock')->render() ?> + element->getElement('thirdPartyApi')->render() ?> element->getElement('allowedCorsUrls')->render() ?> From 9dae48702fac8ca313f4253f7694be6ce123d71d Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Wed, 23 Aug 2017 12:43:48 -0400 Subject: [PATCH 3/3] Added some basic javascript based checking to require album override to be enabled for auto smartblock to be enabled --- .../public/js/airtime/preferences/preferences.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/airtime_mvc/public/js/airtime/preferences/preferences.js b/airtime_mvc/public/js/airtime/preferences/preferences.js index 8850caa32..b54932658 100644 --- a/airtime_mvc/public/js/airtime/preferences/preferences.js +++ b/airtime_mvc/public/js/airtime/preferences/preferences.js @@ -29,6 +29,19 @@ function setEnableSystemEmailsListener() { }); } +function setPodcastAutoSmartblockReadonly() { + var disablePodcastAutomSmartblock = $("#podcastAutoSmartblock-0"); + var enablePodcastAutomSmartblock = $("#podcastAutoSmartblock-1"); + var podcastOverride = $("#podcastAlbumOverride-1"); + if ($(podcastOverride).is(':checked')) { + enablePodcastAutomSmartblock.removeAttr("readonly"); + } else { + disablePodcastAutomSmartblock.prop("checked", true); + disablePodcastAutomSmartblock.attr("readonly","readonly"); + enablePodcastAutomSmartblock.attr("readonly","readonly"); + } +} + function setSystemFromEmailReadonly() { var enableSystemEmails = $("#enableSystemEmail"); var systemFromEmail = $("#systemEmail"); @@ -189,6 +202,7 @@ $(document).ready(function() { showErrorSections(); setMailServerInputReadonly(); + setPodcastAutoSmartblockReadonly(); setSystemFromEmailReadonly(); setConfigureMailServerListener(); setEnableSystemEmailsListener();