Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use custom intro/outro playlists per show #2941

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# pylint: disable=invalid-name

from django.db import migrations

from ._migrations import legacy_migration_factory

UP = """
ALTER TABLE cc_show ADD COLUMN intro_playlist_id integer DEFAULT NULL;
ALTER TABLE cc_show ADD CONSTRAINT cc_playlist_intro_playlist_fkey FOREIGN KEY (intro_playlist_id) REFERENCES cc_playlist (id) ON DELETE SET NULL;
ALTER TABLE cc_show ADD COLUMN outro_playlist_id integer DEFAULT NULL;
ALTER TABLE cc_show ADD CONSTRAINT cc_playlist_outro_playlist_fkey FOREIGN KEY (outro_playlist_id) REFERENCES cc_playlist (id) ON DELETE SET NULL;
"""

DOWN = """
ALTER TABLE cc_show DROP COLUMN IF EXISTS intro_playlist_id;
ALTER TABLE cc_show DROP CONSTRAINT IF EXISTS cc_playlist_intro_playlist_fkey;
ALTER TABLE cc_show DROP COLUMN IF EXISTS outro_playlist_id;
ALTER TABLE cc_show DROP CONSTRAINT IF EXISTS cc_playlist_outro_playlist_fkey;
"""


class Migration(migrations.Migration):
dependencies = [
("legacy", "0045_add_sessions_table"),
]
operations = [
migrations.RunPython(
code=legacy_migration_factory(
target="46",
sql=UP,
)
)
]
2 changes: 1 addition & 1 deletion api/libretime_api/legacy/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# The schema version is defined using the migration file prefix number
LEGACY_SCHEMA_VERSION = "45"
LEGACY_SCHEMA_VERSION = "46"
12 changes: 12 additions & 0 deletions api/libretime_api/legacy/migrations/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ CREATE TABLE "cc_show"
"has_autoplaylist" BOOLEAN DEFAULT 'f' NOT NULL,
"autoplaylist_id" INTEGER,
"autoplaylist_repeat" BOOLEAN DEFAULT 'f' NOT NULL,
"intro_playlist_id" INTEGER,
"outro_playlist_id" INTEGER,
PRIMARY KEY ("id")
);

Expand Down Expand Up @@ -718,6 +720,16 @@ ALTER TABLE "cc_show" ADD CONSTRAINT "cc_playlist_autoplaylist_fkey"
REFERENCES "cc_playlist" ("id")
ON DELETE SET NULL;

ALTER TABLE "cc_show" ADD CONSTRAINT "cc_playlist_intro_playlist_fkey"
FOREIGN KEY ("intro_playlist_id")
REFERENCES "cc_playlist" ("id")
ON DELETE SET NULL;

ALTER TABLE "cc_show" ADD CONSTRAINT "cc_playlist_outro_playlist_fkey"
FOREIGN KEY ("outro_playlist_id")
REFERENCES "cc_playlist" ("id")
ON DELETE SET NULL;

ALTER TABLE "cc_show_instances" ADD CONSTRAINT "cc_show_fkey"
FOREIGN KEY ("show_id")
REFERENCES "cc_show" ("id")
Expand Down
18 changes: 18 additions & 0 deletions api/libretime_api/schedule/models/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ def live_enabled(self) -> bool:
auto_playlist_enabled = models.BooleanField(db_column="has_autoplaylist")
auto_playlist_repeat = models.BooleanField(db_column="autoplaylist_repeat")

intro_playlist = models.ForeignKey(
"schedule.Playlist",
on_delete=models.DO_NOTHING,
blank=True,
null=True,
db_column="intro_playlist_id",
related_name="intro_playlist",
)

outro_playlist = models.ForeignKey(
"schedule.Playlist",
on_delete=models.DO_NOTHING,
blank=True,
null=True,
db_column="outro_playlist_id",
related_name="outro_playlist",
)

hosts = models.ManyToManyField( # type: ignore[var-annotated]
"core.User",
through="ShowHost",
Expand Down
2 changes: 2 additions & 0 deletions api/libretime_api/schedule/serializers/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Meta:
"auto_playlist",
"auto_playlist_enabled",
"auto_playlist_repeat",
"intro_playlist",
"outro_playlist",
]


Expand Down
12 changes: 12 additions & 0 deletions api/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6409,6 +6409,12 @@ components:
type: boolean
auto_playlist_repeat:
type: boolean
intro_playlist:
type: integer
nullable: true
outro_playlist:
type: integer
nullable: true
PatchedShowDays:
type: object
properties:
Expand Down Expand Up @@ -7241,6 +7247,12 @@ components:
type: boolean
auto_playlist_repeat:
type: boolean
intro_playlist:
type: integer
nullable: true
outro_playlist:
type: integer
nullable: true
required:
- auto_playlist_enabled
- auto_playlist_repeat
Expand Down
9 changes: 7 additions & 2 deletions legacy/application/common/AutoPlaylistManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ public static function buildAutoPlaylist()
// call the addPlaylist to show function and don't check for user permission to avoid call to non-existant user object
$sid = $si->getShowId();
$playlistrepeat = new Application_Model_Show($sid);
$introplaylistid = Application_Model_Preference::GetIntroPlaylist();
$outroplaylistid = Application_Model_Preference::GetOutroPlaylist();
if (!$introplaylistid = $playlistrepeat->getIntroPlaylistId()) {
$introplaylistid = Application_Model_Preference::GetIntroPlaylist();
}

if (!$outroplaylistid = $playlistrepeat->getOutroPlaylistId()) {
$outroplaylistid = Application_Model_Preference::GetOutroPlaylist();
}

// we want to check and see if we need to repeat this process until the show is 100% scheduled
// so we create a while loop and break it immediately if repeat until full isn't enabled
Expand Down
19 changes: 18 additions & 1 deletion legacy/application/forms/AddShowAutoPlaylist.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public function init()
// and store to assoc array
$maxLens = Application_Model_Show::getMaxLengths();

$playlistNames = Application_Model_Library::getPlaylistNames(true);

// Add autoplaylist checkbox element
$this->addElement('checkbox', 'add_show_has_autoplaylist', [
'label' => _('Add Autoloading Playlist ?'),
Expand All @@ -23,17 +25,32 @@ public function init()

$autoPlaylistSelect = new Zend_Form_Element_Select('add_show_autoplaylist_id');
$autoPlaylistSelect->setLabel(_('Select Playlist'));
$autoPlaylistSelect->setMultiOptions(Application_Model_Library::getPlaylistNames(true));
$autoPlaylistSelect->setMultiOptions($playlistNames);
$autoPlaylistSelect->setValue(null);
$autoPlaylistSelect->setDecorators(['ViewHelper']);
$this->addElement($autoPlaylistSelect);

// Add autoplaylist checkbox element
$this->addElement('checkbox', 'add_show_autoplaylist_repeat', [
'label' => _('Repeat Playlist Until Show is Full ?'),
'required' => false,
'class' => 'input_text',
'decorators' => ['ViewHelper'],
]);

$introPlaylistSelect = new Zend_Form_Element_Select('add_show_intro_playlist_id');
$introPlaylistSelect->setLabel(_('Select Intro Playlist'));
$introPlaylistSelect->setMultiOptions($playlistNames);
$introPlaylistSelect->setValue(null);
$introPlaylistSelect->setDecorators(['ViewHelper']);
$this->addElement($introPlaylistSelect);

$outroPlaylistSelect = new Zend_Form_Element_Select('add_show_outro_playlist_id');
$outroPlaylistSelect->setLabel(_('Select Outro Playlist'));
$outroPlaylistSelect->setMultiOptions($playlistNames);
$outroPlaylistSelect->setValue(null);
$outroPlaylistSelect->setDecorators(['ViewHelper']);
$this->addElement($outroPlaylistSelect);
}

public function disable()
Expand Down
26 changes: 26 additions & 0 deletions legacy/application/models/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,32 @@ public function setAutoPlaylistId($playlistid)
$show->setDbAutoPlaylistId($playlistid);
}

public function getIntroPlaylistId()
{
$show = CcShowQuery::create()->findPK($this->_showId);

return $show->getDbIntroPlaylistId();
}

public function setIntroPlaylistId($playlistid)
{
$show = CcShowQuery::create()->findPK($this->_showId);
$show->setDbIntroPlaylistId($playlistid);
}

public function getOutroPlaylistId()
{
$show = CcShowQuery::create()->findPK($this->_showId);

return $show->getDbOutroPlaylistId();
}

public function setOutroPlaylistId($playlistid)
{
$show = CcShowQuery::create()->findPK($this->_showId);
$show->setDbOutroPlaylistId($playlistid);
}

public function getHosts()
{
$sql = <<<'SQL'
Expand Down
2 changes: 2 additions & 0 deletions legacy/application/models/airtime/CcShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ public function getShowInfo()
$info['has_autoplaylist'] = $this->getDbHasAutoPlaylist();
$info['autoplaylist_id'] = $this->getDbAutoPlaylistId();
$info['autoplaylist_repeat'] = $this->getDbAutoPlaylistRepeat();
$info['intro_playlist_id'] = $this->getDbIntroPlaylistId();
$info['outro_playlist_id'] = $this->getDbOutroPlaylistId();

return $info;
}
Expand Down
4 changes: 3 additions & 1 deletion legacy/application/models/airtime/map/CcPlaylistTableMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public function initialize()
public function buildRelations()
{
$this->addRelation('CcSubjs', 'CcSubjs', RelationMap::MANY_TO_ONE, array('creator_id' => 'id', ), 'CASCADE', null);
$this->addRelation('CcShow', 'CcShow', RelationMap::ONE_TO_MANY, array('id' => 'autoplaylist_id', ), 'SET NULL', null, 'CcShows');
$this->addRelation('CcShowRelatedByDbAutoPlaylistId', 'CcShow', RelationMap::ONE_TO_MANY, array('id' => 'autoplaylist_id', ), 'SET NULL', null, 'CcShowsRelatedByDbAutoPlaylistId');
$this->addRelation('CcShowRelatedByDbIntroPlaylistId', 'CcShow', RelationMap::ONE_TO_MANY, array('id' => 'intro_playlist_id', ), 'SET NULL', null, 'CcShowsRelatedByDbIntroPlaylistId');
$this->addRelation('CcShowRelatedByDbOutroPlaylistId', 'CcShow', RelationMap::ONE_TO_MANY, array('id' => 'outro_playlist_id', ), 'SET NULL', null, 'CcShowsRelatedByDbOutroPlaylistId');
$this->addRelation('CcPlaylistcontents', 'CcPlaylistcontents', RelationMap::ONE_TO_MANY, array('id' => 'playlist_id', ), 'CASCADE', null, 'CcPlaylistcontentss');
} // buildRelations()

Expand Down
6 changes: 5 additions & 1 deletion legacy/application/models/airtime/map/CcShowTableMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function initialize()
$this->addColumn('has_autoplaylist', 'DbHasAutoPlaylist', 'BOOLEAN', true, null, false);
$this->addForeignKey('autoplaylist_id', 'DbAutoPlaylistId', 'INTEGER', 'cc_playlist', 'id', false, null, null);
$this->addColumn('autoplaylist_repeat', 'DbAutoPlaylistRepeat', 'BOOLEAN', true, null, false);
$this->addForeignKey('intro_playlist_id', 'DbIntroPlaylistId', 'INTEGER', 'cc_playlist', 'id', false, null, null);
$this->addForeignKey('outro_playlist_id', 'DbOutroPlaylistId', 'INTEGER', 'cc_playlist', 'id', false, null, null);
// validators
} // initialize()

Expand All @@ -64,7 +66,9 @@ public function initialize()
*/
public function buildRelations()
{
$this->addRelation('CcPlaylist', 'CcPlaylist', RelationMap::MANY_TO_ONE, array('autoplaylist_id' => 'id', ), 'SET NULL', null);
$this->addRelation('CcPlaylistRelatedByDbAutoPlaylistId', 'CcPlaylist', RelationMap::MANY_TO_ONE, array('autoplaylist_id' => 'id', ), 'SET NULL', null);
$this->addRelation('CcPlaylistRelatedByDbIntroPlaylistId', 'CcPlaylist', RelationMap::MANY_TO_ONE, array('intro_playlist_id' => 'id', ), 'SET NULL', null);
$this->addRelation('CcPlaylistRelatedByDbOutroPlaylistId', 'CcPlaylist', RelationMap::MANY_TO_ONE, array('outro_playlist_id' => 'id', ), 'SET NULL', null);
$this->addRelation('CcShowInstances', 'CcShowInstances', RelationMap::ONE_TO_MANY, array('id' => 'show_id', ), 'CASCADE', null, 'CcShowInstancess');
$this->addRelation('CcShowDays', 'CcShowDays', RelationMap::ONE_TO_MANY, array('id' => 'show_id', ), 'CASCADE', null, 'CcShowDayss');
$this->addRelation('CcShowRebroadcast', 'CcShowRebroadcast', RelationMap::ONE_TO_MANY, array('id' => 'show_id', ), 'CASCADE', null, 'CcShowRebroadcasts');
Expand Down