Skip to content

Commit

Permalink
feat(legacy): trim overbooked shows after autoloading a playlist (#2897)
Browse files Browse the repository at this point in the history
### Description

Some combination of preload/postload and autoloding playlists with
smartblocks generate massively overbooked shows that clutter up the
interface. This addition performs a 'trim overbooked' after filling up
the autoload list, and does the same as pushing the 'trim overbooked'
button in the UI.


### Testing Notes

Define an autoloading playlist of 2 hours and schedule it for a one hour
show. Without patch, you'll get entries for 2 hours, with the patch, you
only get one hour and a 'overboarding' orange entry at most.

---------

Co-authored-by: Kyle Robbertze <paddatrapper@users.noreply.github.com>
Co-authored-by: Thomas Göttgens <tgoettgens@mail.com>
Co-authored-by: jo <ljonas@riseup.net>
  • Loading branch information
4 people committed Feb 2, 2024
1 parent 170d095 commit a95ce3d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions legacy/application/common/AutoPlaylistManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public static function buildAutoPlaylist()
$si->addPlaylistToShow($outroplaylistid, false);
}
$si->setAutoPlaylistBuilt(true);

// now trim excessively overbooked shows so the display isn't cluttered with myriads of red off-time blocks
if (Application_Model_Preference::getScheduleTrimOverbooked()) {
$si->trimOverbooked();
}
}
Application_Model_Preference::setAutoPlaylistPollLock(microtime(true));
}
Expand Down
1 change: 1 addition & 0 deletions legacy/application/controllers/PreferenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function indexAction()
Application_Model_Preference::SetAllow3rdPartyApi($values['thirdPartyApi']);
Application_Model_Preference::SetDefaultLocale($values['locale']);
Application_Model_Preference::SetWeekStartDay($values['weekStartDay']);
Application_Model_Preference::setScheduleTrimOverbooked($values['scheduleTrimOverbooked']);
Application_Model_Preference::setRadioPageDisplayLoginButton($values['radioPageLoginButton']);
Application_Model_Preference::setRadioPageDisabled($values['radioPageDisabled']);
Application_Model_Preference::SetFeaturePreviewMode($values['featurePreviewMode']);
Expand Down
12 changes: 12 additions & 0 deletions legacy/application/forms/GeneralPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ public function init()
]);
$this->addElement($podcast_auto_smartblock);

$scheduleTrimOverbooked = new Zend_Form_Element_Checkbox('scheduleTrimOverbooked');
$scheduleTrimOverbooked->setDecorators([
'ViewHelper',
'Errors',
'Label',
]);
$displayScheduleTrimOverbookedValue = Application_Model_Preference::getScheduleTrimOverbooked();
$scheduleTrimOverbooked->addDecorator('Label');
$scheduleTrimOverbooked->setLabel(_('Trim overbooked shows after autoloading?'));
$scheduleTrimOverbooked->setValue($displayScheduleTrimOverbookedValue);
$this->addElement($scheduleTrimOverbooked);

// TODO add and insert Podcast Smartblock and Playlist autogenerate options

$third_party_api = new Zend_Form_Element_Radio('thirdPartyApi');
Expand Down
10 changes: 10 additions & 0 deletions legacy/application/models/Preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,16 @@ public static function setRadioPageDisplayLoginButton($value)
self::setValue('radio_page_display_login_button', $value);
}

public static function getScheduleTrimOverbooked()
{
return boolval(self::getValue('schedule_trim_overbooked', false));
}

public static function setScheduleTrimOverbooked($value)
{
self::setValue('schedule_trim_overbooked', $value);
}

public static function getRadioPageDisabled()
{
return boolval(self::getValue('radio_page_disabled', false));
Expand Down
29 changes: 29 additions & 0 deletions legacy/application/models/ShowInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,4 +844,33 @@ public function isRepeating()
{
return $this->getShow()->isRepeating();
}

public function trimOverbooked()
{
// Remove all scheduled items that start time after the show has ended
$sql = <<<'SQL'
delete
from
cc_schedule
where
id in (
select
s.id
from
cc_schedule s
left join cc_show_instances si on
s.instance_id = si.id
where
si.id = :instance_id
and si.ends < s.starts
and s.playout_status = 0 -- playout_status = 0 double check that si.ends < s.starts
);
SQL;

return Application_Common_Database::prepareAndExecute(
$sql,
[':instance_id' => $this->_instanceId],
'execute'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@

<?php echo $this->element->getElement('thirdPartyApi')->render() ?>

<?php echo $this->element->getElement('scheduleTrimOverbooked')->renderViewHelper() ?>
<?php echo $this->element->getElement('scheduleTrimOverbooked')->renderLabel() ?>
<br/>
<?php echo $this->element->getElement('radioPageLoginButton')->renderViewHelper() ?>
<?php echo $this->element->getElement('radioPageLoginButton')->renderLabel() ?>
<br />
Expand Down

0 comments on commit a95ce3d

Please sign in to comment.