Clean up and simplifcation of linked show filling
This commit is contained in:
parent
e3596dfed3
commit
32e06a7456
|
@ -196,15 +196,15 @@ class Application_Service_SchedulerService
|
||||||
{
|
{
|
||||||
//TODO can we remove the code until line 216 ??
|
//TODO can we remove the code until line 216 ??
|
||||||
|
|
||||||
|
/*
|
||||||
$instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime();
|
$instanceIds = $ccShow->getInstanceIdsSortedByMostRecentStartTime();
|
||||||
if (count($instanceIds) == 0) {
|
if (count($instanceIds) == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First check if any linked instances have content
|
//First check if any linked instances have content
|
||||||
* If all instances are empty then we don't need to fill
|
//If all instances are empty then we don't need to fill
|
||||||
* any other instances with content
|
//any other instances with content
|
||||||
*/
|
|
||||||
$doesAnyShowInstanceHaveContent = false;
|
$doesAnyShowInstanceHaveContent = false;
|
||||||
foreach ($instanceIds as $instanceId)
|
foreach ($instanceIds as $instanceId)
|
||||||
{
|
{
|
||||||
|
@ -226,7 +226,10 @@ class Application_Service_SchedulerService
|
||||||
//(No content should be propagated to the other show instances...
|
//(No content should be propagated to the other show instances...
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Get the "template" schedule for the linked show (contents of the linked show) that will be
|
||||||
|
//copied into to all the new show instances.
|
||||||
$linkedShowSchedule = self::getLinkedShowSchedule($ccShow->getDbId(), $instanceIdsToFill);
|
$linkedShowSchedule = self::getLinkedShowSchedule($ccShow->getDbId(), $instanceIdsToFill);
|
||||||
|
|
||||||
//get time_filled so we can update cc_show_instances
|
//get time_filled so we can update cc_show_instances
|
||||||
|
@ -236,81 +239,72 @@ class Application_Service_SchedulerService
|
||||||
$timeFilled = Application_Common_Database::prepareAndExecute(
|
$timeFilled = Application_Common_Database::prepareAndExecute(
|
||||||
$timeFilled_sql, array(), Application_Common_Database::COLUMN);
|
$timeFilled_sql, array(), Application_Common_Database::COLUMN);
|
||||||
} else {
|
} else {
|
||||||
|
//We probably shouldn't return here because the code below will
|
||||||
|
//set this on each empty show instance...
|
||||||
$timeFilled = "00:00:00";
|
$timeFilled = "00:00:00";
|
||||||
}
|
}
|
||||||
|
|
||||||
//need to find out which linked instances are empty
|
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
|
//Here we begin to fill the new show instances (as specified by $instanceIdsToFill)
|
||||||
|
//with content from $linkedShowSchedule.
|
||||||
try {
|
try {
|
||||||
$con->beginTransaction();
|
$con->beginTransaction();
|
||||||
foreach ($instanceIdsToFill as $id)
|
foreach ($instanceIdsToFill as $id)
|
||||||
{
|
{
|
||||||
$instanceSched_sql = "SELECT * FROM cc_schedule ".
|
//Start by clearing the show instance that needs to be filling. This ensure
|
||||||
"WHERE instance_id = {$id} ".
|
//we're not going to get in trouble in case there's an programming error somewhere else.
|
||||||
"ORDER by starts";
|
self::clearShowInstanceContents($id);
|
||||||
|
|
||||||
$showInstanceContents = Application_Common_Database::prepareAndExecute(
|
// Now fill the show instance with the same content that $linkedShowSchedule has.
|
||||||
$instanceSched_sql);
|
$instanceStart_sql = "SELECT starts FROM cc_show_instances " .
|
||||||
|
"WHERE id = {$id} " . "ORDER BY starts";
|
||||||
|
|
||||||
/* If the show instance is empty OR it has different content than
|
//What's tricky here is that when we copy the content, we have to adjust
|
||||||
* the most recent instance, we need to fill/replace with the linked
|
//the start and end times of each track so they're inside the new show instance's time slot.
|
||||||
* show schedule
|
$nextStartDT = new DateTime(
|
||||||
*/
|
|
||||||
//TODO can this check be removed?
|
|
||||||
if (count($showInstanceContents) < 1 ||
|
|
||||||
self::replaceInstanceContentCheck($showInstanceContents, $linkedShowSchedule, $id))
|
|
||||||
{
|
|
||||||
|
|
||||||
$instanceStart_sql = "SELECT starts FROM cc_show_instances ".
|
|
||||||
"WHERE id = {$id} ".
|
|
||||||
"ORDER BY starts";
|
|
||||||
$nextStartDT = new DateTime(
|
|
||||||
Application_Common_Database::prepareAndExecute(
|
|
||||||
$instanceStart_sql, array(), Application_Common_Database::COLUMN),
|
|
||||||
new DateTimeZone("UTC"));
|
|
||||||
|
|
||||||
$defaultCrossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration();
|
|
||||||
unset($values);
|
|
||||||
$values = array();
|
|
||||||
foreach ($linkedShowSchedule as $item) {
|
|
||||||
$endTimeDT = self::findEndTime($nextStartDT, $item["clip_length"]);
|
|
||||||
|
|
||||||
if (is_null($item["file_id"])) {
|
|
||||||
$item["file_id"] = "null";
|
|
||||||
}
|
|
||||||
if (is_null($item["stream_id"])) {
|
|
||||||
$item["stream_id"] = "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
$values[] = "(".
|
|
||||||
"'{$nextStartDT->format("Y-m-d H:i:s")}', ".
|
|
||||||
"'{$endTimeDT->format("Y-m-d H:i:s")}', ".
|
|
||||||
"'{$item["clip_length"]}', ".
|
|
||||||
"'{$item["fade_in"]}', ".
|
|
||||||
"'{$item["fade_out"]}', ".
|
|
||||||
"'{$item["cue_in"]}', ".
|
|
||||||
"'{$item["cue_out"]}', ".
|
|
||||||
"{$item["file_id"]}, ".
|
|
||||||
"{$item["stream_id"]}, ".
|
|
||||||
"{$id}, ".
|
|
||||||
"{$item["position"]})";
|
|
||||||
|
|
||||||
$nextStartDT = self::findTimeDifference($endTimeDT,
|
|
||||||
$defaultCrossfadeDuration);
|
|
||||||
|
|
||||||
} //foreach show item
|
|
||||||
|
|
||||||
if (!empty($values)) {
|
|
||||||
$insert_sql = "INSERT INTO cc_schedule (starts, ends, ".
|
|
||||||
"clip_length, fade_in, fade_out, cue_in, cue_out, ".
|
|
||||||
"file_id, stream_id, instance_id, position) VALUES ".
|
|
||||||
implode($values, ",");
|
|
||||||
Application_Common_Database::prepareAndExecute(
|
Application_Common_Database::prepareAndExecute(
|
||||||
$insert_sql, array(), Application_Common_Database::EXECUTE);
|
$instanceStart_sql, array(),
|
||||||
|
Application_Common_Database::COLUMN),
|
||||||
|
new DateTimeZone("UTC"));
|
||||||
|
|
||||||
|
$defaultCrossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration();
|
||||||
|
unset($values);
|
||||||
|
$values = array();
|
||||||
|
foreach ($linkedShowSchedule as $item) {
|
||||||
|
$endTimeDT = self::findEndTime($nextStartDT,
|
||||||
|
$item["clip_length"]);
|
||||||
|
|
||||||
|
if (is_null($item["file_id"])) {
|
||||||
|
$item["file_id"] = "null";
|
||||||
}
|
}
|
||||||
}
|
if (is_null($item["stream_id"])) {
|
||||||
|
$item["stream_id"] = "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
$values[] = "(" . "'{$nextStartDT->format("Y-m-d H:i:s")}', " .
|
||||||
|
"'{$endTimeDT->format("Y-m-d H:i:s")}', " .
|
||||||
|
"'{$item["clip_length"]}', " .
|
||||||
|
"'{$item["fade_in"]}', " . "'{$item["fade_out"]}', " .
|
||||||
|
"'{$item["cue_in"]}', " . "'{$item["cue_out"]}', " .
|
||||||
|
"{$item["file_id"]}, " . "{$item["stream_id"]}, " .
|
||||||
|
"{$id}, " . "{$item["position"]})";
|
||||||
|
|
||||||
|
$nextStartDT = self::findTimeDifference($endTimeDT,
|
||||||
|
$defaultCrossfadeDuration);
|
||||||
|
} //foreach show item
|
||||||
|
|
||||||
|
if (!empty($values)) {
|
||||||
|
$insert_sql = "INSERT INTO cc_schedule (starts, ends, ".
|
||||||
|
"clip_length, fade_in, fade_out, cue_in, cue_out, ".
|
||||||
|
"file_id, stream_id, instance_id, position) VALUES ".
|
||||||
|
implode($values, ",");
|
||||||
|
Application_Common_Database::prepareAndExecute(
|
||||||
|
$insert_sql, array(), Application_Common_Database::EXECUTE);
|
||||||
|
}
|
||||||
|
|
||||||
//update cc_schedule status column
|
//update cc_schedule status column
|
||||||
$instance = CcShowInstancesQuery::create()->findPk($id);
|
$instance = CcShowInstancesQuery::create()->findPk($id);
|
||||||
$instance->updateScheduleStatus($con);
|
$instance->updateScheduleStatus($con);
|
||||||
|
@ -380,6 +374,17 @@ class Application_Service_SchedulerService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Clears a show instance's schedule (which is actually clearing cc_schedule during that show instance's time slot.) */
|
||||||
|
private static function clearShowInstanceContents($instanceId)
|
||||||
|
{
|
||||||
|
//Application_Common_Database::prepareAndExecute($delete_sql, array(), Application_Common_Database::EXECUTE);
|
||||||
|
$con = Propel::getConnection();
|
||||||
|
$query = $con->prepare("DELETE FROM cc_schedule WHERE instance_id = :instance_id");
|
||||||
|
$query->bindParam(':instance_id', $instanceId);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
private static function replaceInstanceContentCheck($currentShowStamp, $showStamp, $instance_id)
|
private static function replaceInstanceContentCheck($currentShowStamp, $showStamp, $instance_id)
|
||||||
{
|
{
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
|
@ -392,26 +397,26 @@ class Application_Service_SchedulerService
|
||||||
$item["stream_id"] != $currentShowStamp[$counter]["stream_id"]) {
|
$item["stream_id"] != $currentShowStamp[$counter]["stream_id"]) {
|
||||||
$erraseShow = true;
|
$erraseShow = true;
|
||||||
break;
|
break;
|
||||||
/*CcScheduleQuery::create()
|
//CcScheduleQuery::create()
|
||||||
->filterByDbInstanceId($ccShowInstance->getDbId())
|
// ->filterByDbInstanceId($ccShowInstance->getDbId())
|
||||||
->delete();*/
|
// ->delete();
|
||||||
}
|
}
|
||||||
$counter += 1;
|
$counter += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($erraseShow) {
|
if ($erraseShow) {
|
||||||
$delete_sql = "DELETE FROM cc_schedule ".
|
$delete_sql = "DELETE FROM cc_schedule ".
|
||||||
"WHERE instance_id = {$instance_id}";
|
"WHERE instance_id = :instance_id";
|
||||||
Application_Common_Database::prepareAndExecute(
|
Application_Common_Database::prepareAndExecute(
|
||||||
$delete_sql, array(), Application_Common_Database::EXECUTE);
|
$delete_sql, array(), Application_Common_Database::EXECUTE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we get here, the content in the show instance is the same
|
//If we get here, the content in the show instance is the same
|
||||||
* as what we want to replace it with, so we can leave as is
|
// as what we want to replace it with, so we can leave as is
|
||||||
*/
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public function emptyShowContent($instanceId)
|
public function emptyShowContent($instanceId)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue