From a95ce3d2296bb864b379dcce14090bd821c1dfc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 2 Feb 2024 20:17:23 +0100 Subject: [PATCH] feat(legacy): trim overbooked shows after autoloading a playlist (#2897) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 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 Co-authored-by: Thomas Göttgens Co-authored-by: jo --- .../common/AutoPlaylistManager.php | 5 ++++ .../controllers/PreferenceController.php | 1 + .../application/forms/GeneralPreferences.php | 12 ++++++++ legacy/application/models/Preference.php | 10 +++++++ legacy/application/models/ShowInstance.php | 29 +++++++++++++++++++ .../scripts/form/preferences_general.phtml | 3 ++ 6 files changed, 60 insertions(+) diff --git a/legacy/application/common/AutoPlaylistManager.php b/legacy/application/common/AutoPlaylistManager.php index 54f62170d..e504c3013 100644 --- a/legacy/application/common/AutoPlaylistManager.php +++ b/legacy/application/common/AutoPlaylistManager.php @@ -81,6 +81,11 @@ class AutoPlaylistManager $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)); } diff --git a/legacy/application/controllers/PreferenceController.php b/legacy/application/controllers/PreferenceController.php index 8dba80c22..db48390dd 100644 --- a/legacy/application/controllers/PreferenceController.php +++ b/legacy/application/controllers/PreferenceController.php @@ -49,6 +49,7 @@ class PreferenceController extends Zend_Controller_Action 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']); diff --git a/legacy/application/forms/GeneralPreferences.php b/legacy/application/forms/GeneralPreferences.php index bec987c56..59ace16a4 100644 --- a/legacy/application/forms/GeneralPreferences.php +++ b/legacy/application/forms/GeneralPreferences.php @@ -150,6 +150,18 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm ]); $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'); diff --git a/legacy/application/models/Preference.php b/legacy/application/models/Preference.php index 0ea3034aa..bc3cd3753 100644 --- a/legacy/application/models/Preference.php +++ b/legacy/application/models/Preference.php @@ -1399,6 +1399,16 @@ class Application_Model_Preference 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)); diff --git a/legacy/application/models/ShowInstance.php b/legacy/application/models/ShowInstance.php index b5aa109df..7b91dc8ed 100644 --- a/legacy/application/models/ShowInstance.php +++ b/legacy/application/models/ShowInstance.php @@ -844,4 +844,33 @@ SQL; { 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' + ); + } } diff --git a/legacy/application/views/scripts/form/preferences_general.phtml b/legacy/application/views/scripts/form/preferences_general.phtml index 31517aa2d..43adb22dc 100644 --- a/legacy/application/views/scripts/form/preferences_general.phtml +++ b/legacy/application/views/scripts/form/preferences_general.phtml @@ -45,6 +45,9 @@ element->getElement('thirdPartyApi')->render() ?> + element->getElement('scheduleTrimOverbooked')->renderViewHelper() ?> + element->getElement('scheduleTrimOverbooked')->renderLabel() ?> +
element->getElement('radioPageLoginButton')->renderViewHelper() ?> element->getElement('radioPageLoginButton')->renderLabel() ?>