Added option for Auto Smartblock and Playlist creation to preferences

This commit is contained in:
Robb Ebright 2017-08-23 12:16:42 -04:00
parent aec0e348c4
commit 3515a898a7
5 changed files with 75 additions and 44 deletions

View file

@ -46,6 +46,7 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]); Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]);
Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]); Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]);
Application_Model_Preference::SetPodcastAlbumOverride($values["podcastAlbumOverride"]); Application_Model_Preference::SetPodcastAlbumOverride($values["podcastAlbumOverride"]);
Application_Model_Preference::SetPodcastAutoSmartblock($values["podcastAutoSmartblock"]);
Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]); Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]);
Application_Model_Preference::SetAllowedCorsUrls($values["allowedCorsUrls"]); Application_Model_Preference::SetAllowedCorsUrls($values["allowedCorsUrls"]);
Application_Model_Preference::SetDefaultLocale($values["locale"]); Application_Model_Preference::SetDefaultLocale($values["locale"]);

View file

@ -110,13 +110,28 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
$podcast_album_override->setValue(Application_Model_Preference::GetPodcastAlbumOverride()); $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->setDescription(_('Enabling this means that podcast tracks will always contain the podcast name in their album field.'));
$podcast_album_override->setSeparator(' '); //No <br> between radio buttons $podcast_album_override->setSeparator(' '); //No <br> 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', $podcast_album_override->addDecorator('HtmlTag', array('tag' => 'dd',
'id'=>"podcastAlbumOverride-element", 'id'=>"podcastAlbumOverride-element",
'class' => 'radio-inline-list', 'class' => 'radio-inline-list',
)); ));
$this->addElement($podcast_album_override); $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 <br> 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 //TODO add and insert Podcast Smartblock and Playlist autogenerate options
$third_party_api = new Zend_Form_Element_Radio('thirdPartyApi'); $third_party_api = new Zend_Form_Element_Radio('thirdPartyApi');

View file

@ -376,6 +376,18 @@ class Application_Model_Preference
return $val === '1' ? true : false; 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) public static function SetPhone($phone)
{ {
self::setValue("phone", $phone); self::setValue("phone", $phone);

View file

@ -147,9 +147,10 @@ class Application_Service_PodcastService
$importedPodcast->setDbAutoIngest(true); $importedPodcast->setDbAutoIngest(true);
$importedPodcast->save(); $importedPodcast->save();
// need to add an if statement to check if this option is enabled // if the autosmartblock and album override are enabled then create a smartblock and playlist matching this podcast via the album name
self::createPodcastSmartblockAndPlaylist($podcast); if (Application_Model_Preference::GetPodcastAutoSmartblock() && Application_Model_Preference::GetPodcastAlbumOverride()) {
self::createPodcastSmartblockAndPlaylist($podcast);
}
return $podcast->toArray(BasePeer::TYPE_FIELDNAME); 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) 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 // sort so that it is the newest item
// also need to check an option $row = new CcBlockcriteria();
// right here need to create new smartblock and playlist with same name as podcast title $row->setDbCriteria('sort');
$newBl = new Application_Model_Block(); $row->setDbModifier('N/A');
$newBl->setCreator(Application_Model_User::getCurrentUser()->getId()); $row->setDbValue('newest');
$newBl->setName($podcast->getDbTitle()); $row->setDbBlockId($newBl->getId());
$newBl->setDescription('Auto-generated smartblock for podcast'); $row->save();
$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 // match the track by ensuring the album title matches the podcast
$row = new CcBlockcriteria(); $row = new CcBlockcriteria();
$row->setDbCriteria('sort'); $row->setDbCriteria('album_title');
$row->setDbModifier('N/A'); $row->setDbModifier('is');
$row->setDbValue('newest'); $row->setDbValue($newBl->getName());
$row->setDbBlockId($newBl->getId()); $row->setDbBlockId($newBl->getId());
$row->save(); $row->save();
// match the track by ensuring the album title matches the podcast $newPl = new Application_Model_Playlist();
$row = new CcBlockcriteria(); $newPl->setName($podcast->getDbTitle());
$row->setDbCriteria('album_title'); $newPl->setCreator(Application_Model_User::getCurrentUser()->getId());
$row->setDbModifier('is'); $row = new CcPlaylistcontents();
$row->setDbValue($newBl->getName()); $row->setDbBlockId($newBl->getId());
$row->setDbBlockId($newBl->getId()); $row->setDbPlaylistId($newPl->getId());
$row->save(); $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() public static function createStationPodcast()
{ {

View file

@ -33,6 +33,8 @@
<?php echo $this->element->getElement('podcastAlbumOverride')->render() ?> <?php echo $this->element->getElement('podcastAlbumOverride')->render() ?>
<?php echo $this->element->getElement('podcastAutoSmartblock')->render() ?>
<?php echo $this->element->getElement('thirdPartyApi')->render() ?> <?php echo $this->element->getElement('thirdPartyApi')->render() ?>
<?php echo $this->element->getElement('allowedCorsUrls')->render() ?> <?php echo $this->element->getElement('allowedCorsUrls')->render() ?>