Merge branch 'cc-5405' of https://github.com/sourcefabric/Airtime into 2.5.x

This commit is contained in:
Albert Santoni 2013-12-04 14:36:38 -05:00
commit 771d07c4cc
8 changed files with 342 additions and 89 deletions

View File

@ -183,6 +183,7 @@ class ScheduleController extends Zend_Controller_Action
$deltaDay = $this->_getParam('day'); $deltaDay = $this->_getParam('day');
$deltaMin = $this->_getParam('min'); $deltaMin = $this->_getParam('min');
$showId = $this->_getParam('showId'); $showId = $this->_getParam('showId');
$instanceId = $this->_getParam('instanceId');
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id); $user = new Application_Model_User($userInfo->id);
@ -195,7 +196,7 @@ class ScheduleController extends Zend_Controller_Action
return false; return false;
} }
$error = $show->resizeShow($deltaDay, $deltaMin); $error = $show->resizeShow($deltaDay, $deltaMin, $instanceId);
} }
if (isset($error)) { if (isset($error)) {

View File

@ -172,30 +172,97 @@ SQL;
$show->delete(); $show->delete();
} }
public function resizeShow($deltaDay, $deltaMin) public function resizeShow($deltaDay, $deltaMin, $instanceId)
{ {
$con = Propel::getConnection(); $con = Propel::getConnection();
if ($deltaDay > 0) { if ($deltaDay > 0) {
return _("Shows can have a max length of 24 hours."); return _("Shows can have a max length of 24 hours.");
} }
$utc = new DateTimeZone("UTC"); $utc = new DateTimeZone("UTC");
$nowDateTime = new DateTime("now", $utc); $nowDateTime = new DateTime("now", $utc);
$showInstances = CcShowInstancesQuery::create() //keep track of cc_show_day entries we need to update
->filterByDbShowId($this->_showId) $showDayIds = array();
->find($con);
/*
* If the resized show is an edited instance of a repeating show we
* need to treat it as a separate show and not resize the other instances
*
* Also, if the resized show has edited instances, we need to exclude
* those from the resize
*/
$ccShow = CcShowQuery::create()->findPk($this->_showId);
if ($ccShow->isRepeating()) {
//convert instance to local timezone
$ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
$startsDT = $ccShowInstance->getDbStarts(null);
$timezone = $ccShow->getFirstCcShowDay()->getDbTimezone();
$startsDT->setTimezone(new DateTimeZone($timezone));
/* Get cc_show_day for the current instance. If we don't find one
* we know it is a repeat interval of one of cc_show_days first
* show and we can assume we aren't resizing a modified instance
*/
$ccShowDay = CcShowDaysQuery::create()
->filterByDbFirstShow($startsDT->format("Y-m-d"))
->filterByDbStartTime($startsDT->format("H:i:s"))
->filterByDbShowId($this->_showId)
->findOne();
/* Check if this cc_show_day rule is non-repeating. If it is, then
* we know this instance was edited out of the repeating sequence
*/
if (!$ccShowDay || $ccShowDay->getDbRepeatType() != -1) {
$ccShowDays = $ccShow->getRepeatingCcShowDays();
foreach ($ccShowDays as $day) {
array_push($showDayIds, $day->getDbId());
}
$excludeIds = $ccShow->getEditedRepeatingInstanceIds();
//exlcude edited instances from resize
$showInstances = CcShowInstancesQuery::create()
->filterByDbShowId($this->_showId)
->filterByDbModifiedInstance(false)
->filterByDbId($excludeIds, criteria::NOT_IN)
->find();
} elseif ($ccShowDay->getDbRepeatType() == -1) {
array_push($showDayIds, $ccShowDay->getDbId());
//treat edited instance as separate show for resize
$showInstances = CcShowInstancesQuery::create()
->filterByDbId($instanceId)
->find();
}
} else {
$ccShowDays = $ccShow->getCcShowDayss();
foreach ($ccShowDays as $day) {
array_push($showDayIds, $day->getDbId());
}
$showInstances = CcShowInstancesQuery::create()
->filterByDbShowId($this->_showId)
->find($con);
}
/* Check two things: /* Check two things:
1. If the show being resized and any of its repeats end in the past 1. If the show being resized and any of its repeats end in the past
2. If the show being resized and any of its repeats overlap 2. If the show being resized and any of its repeats overlap
with other scheduled shows */ with other scheduled shows */
//keep track of instance ids for update show instances start/end times
$instanceIds = array();
//check if new show time overlaps with any other shows
foreach ($showInstances as $si) { foreach ($showInstances as $si) {
$startsDateTime = new DateTime($si->getDbStarts(), new DateTimeZone("UTC")); array_push($instanceIds, $si->getDbId());
$endsDateTime = new DateTime($si->getDbEnds(), new DateTimeZone("UTC"));
$startsDateTime = $si->getDbStarts(null);
$endsDateTime = $si->getDbEnds(null);
/* The user is moving the show on the calendar from the perspective /* The user is moving the show on the calendar from the perspective
of local time. * incase a show is moved across a time change of local time. * incase a show is moved across a time change
@ -204,19 +271,19 @@ SQL;
$startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin); //$newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin);
$newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin); $newEndsDateTime = Application_Model_ShowInstance::addDeltas($endsDateTime, $deltaDay, $deltaMin);
if ($newEndsDateTime->getTimestamp() < $nowDateTime->getTimestamp()) { if ($newEndsDateTime->getTimestamp() < $nowDateTime->getTimestamp()) {
return _("End date/time cannot be in the past"); return _("End date/time cannot be in the past");
} }
//convert our new starts/ends to UTC. //convert our new starts/ends to UTC.
$newStartsDateTime->setTimezone($utc); //$newStartsDateTime->setTimezone($utc);
$newEndsDateTime->setTimezone($utc); $newEndsDateTime->setTimezone($utc);
$overlapping = Application_Model_Schedule::checkOverlappingShows( $overlapping = Application_Model_Schedule::checkOverlappingShows(
$newStartsDateTime, $newEndsDateTime, true, $si->getDbId()); $startsDateTime, $newEndsDateTime, true, $si->getDbId());
if ($overlapping) { if ($overlapping) {
return _("Cannot schedule overlapping shows.\nNote: Resizing a repeating show ". return _("Cannot schedule overlapping shows.\nNote: Resizing a repeating show ".
@ -228,39 +295,30 @@ SQL;
$hours = ($hours > 0) ? floor($hours) : ceil($hours); $hours = ($hours > 0) ? floor($hours) : ceil($hours);
$mins = abs($deltaMin % 60); $mins = abs($deltaMin % 60);
//current timesamp in UTC. $sql_gen = "UPDATE cc_show_instances ".
$current_timestamp = gmdate("Y-m-d H:i:s"); "SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL) ".
"WHERE (id IN (".implode($instanceIds, ",").") ".
$sql_gen = <<<SQL "AND ends > :current_timestamp1) ".
UPDATE cc_show_instances "AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00')";
SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL)
WHERE (show_id = :show_id1
AND ends > :current_timestamp1)
AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00')
SQL;
Application_Common_Database::prepareAndExecute($sql_gen, Application_Common_Database::prepareAndExecute($sql_gen,
array( array(
':deltaDay1' => "$deltaDay days", ':deltaDay1' => "$deltaDay days",
':interval1' => "$hours:$mins", ':interval1' => "$hours:$mins",
':show_id1' => $this->_showId, ':current_timestamp1' => $nowDateTime->format("Y-m-d H:i:s"),
':current_timestamp1' => $current_timestamp,
':deltaDay2' => "$deltaDay days", ':deltaDay2' => "$deltaDay days",
':interval2' => "$hours:$mins" ':interval2' => "$hours:$mins"
), "execute"); ), "execute");
$sql_gen = <<<SQL $sql_gen = "UPDATE cc_show_days ".
UPDATE cc_show_days "SET duration = (CAST(duration AS interval) + :deltaDay3::INTERVAL + :interval3::INTERVAL) ".
SET duration = (CAST(duration AS interval) + :deltaDay3::INTERVAL + :interval3::INTERVAL) "WHERE id IN (".implode($showDayIds, ",").") ".
WHERE show_id = :show_id2 "AND ((CAST(duration AS interval) + :deltaDay4::INTERVAL + :interval4::INTERVAL) <= interval '24:00')";
AND ((CAST(duration AS interval) + :deltaDay4::INTERVAL + :interval4::INTERVAL) <= interval '24:00')
SQL;
Application_Common_Database::prepareAndExecute($sql_gen, Application_Common_Database::prepareAndExecute($sql_gen,
array( array(
':deltaDay3' => "$deltaDay days", ':deltaDay3' => "$deltaDay days",
':interval3' => "$hours:$mins", ':interval3' => "$hours:$mins",
':show_id2' => $this->_showId,
':deltaDay4' => "$deltaDay days", ':deltaDay4' => "$deltaDay days",
':interval4' => "$hours:$mins" ':interval4' => "$hours:$mins"
), "execute"); ), "execute");
@ -278,8 +336,8 @@ SQL;
CcShowInstancesPeer::clearInstancePool(); CcShowInstancesPeer::clearInstancePool();
$instances = CcShowInstancesQuery::create() $instances = CcShowInstancesQuery::create()
->filterByDbEnds($current_timestamp, Criteria::GREATER_THAN) ->filterByDbEnds($nowDateTime->format("Y-m-d H:i:s"), Criteria::GREATER_THAN)
->filterByDbShowId($this->_showId) ->filterByDbId($instanceIds, Criteria::IN)
->find($con); ->find($con);
foreach ($instances as $instance) { foreach ($instances as $instance) {

View File

@ -15,8 +15,20 @@
*/ */
class CcShow extends BaseCcShow { class CcShow extends BaseCcShow {
public function getCcShowDays(){ /*
return CcShowDaysQuery::create()->filterByDbShowId($this->getDbId())->find(); * Returns all cc_show_day rules that belong to a cc_show and that are
* repeating.
* We do this because editing a single instance from a repeating sequence
* creates a new rule in cc_show_days with the same cc_show id and a repeat
* type of -1 (non-repeating).
* So when the entire cc_show is updated after that, the single edited
* instance can remain separate from the rest of the instances
*/
public function getRepeatingCcShowDays(){
return CcShowDaysQuery::create()
->filterByDbShowId($this->id)
->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
->find();
} }
/** /**
@ -54,6 +66,86 @@ class CcShow extends BaseCcShow {
return $this->collCcShowDayss[0]; return $this->collCcShowDayss[0];
} }
/**
*
* A repeating show may have a rule in cc_show_days with a repeat type
* of -1 (not repeating). This happens when a single instances was edited
* from the repeating sequence.
*
* When the repeating show gets edited in this case, we want to exclude all
* the edited instances from the update. We do this by not returning any of
* the cc_show_day rules with a -1 repeat type.
*/
public function getFirstRepeatingCcShowDay()
{
return CcShowDaysQuery::create()
->filterByDbShowId($this->id)
->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
->orderByDbFirstShow()
->findOne();
}
/**
*
* In order to determine if a show is repeating we need to check each
* cc_show_day entry and check if there are any non -1 repeat types.
* Because editing a single instances creates a new cc_show_day rule
* with a -1 (non repeating) repeat type we need to check all cc_show_day
* entries
*/
public function isRepeating()
{
//get all cc_show_day entries that are repeating
$ccShowDays = CcShowDaysQuery::create()
->filterByDbShowId($this->id)
->filterByDbRepeatType(0, Criteria::GREATER_EQUAL)
->find();
if (!$ccShowDays->isEmpty()) {
return true;
}
return false;
}
/**
* Returns all cc_show_instances that have been edited out of
* a repeating sequence
*/
public function getEditedRepeatingInstanceIds()
{
//get cc_show_days that have been edited (not repeating)
$ccShowDays = CcShowDaysQuery::create()
->filterByDbShowId($this->id)
->filterByDbRepeatType(-1)
->find();
$startsUTC = array();
$utc = new DateTimeZone("UTC");
foreach ($ccShowDays as $day) {
//convert to UTC
$starts = new DateTime(
$day->getDbFirstShow()." ".$day->getDbStartTime(),
new DateTimeZone($day->getDbTimezone())
);
$starts->setTimezone($utc);
array_push($startsUTC, $starts->format("Y-m-d H:i:s"));
}
$excludeInstances = CcShowInstancesQuery::create()
->filterByDbShowId($this->id)
->filterByDbStarts($startsUTC, criteria::IN)
->find();
$excludeIds = array();
foreach ($excludeInstances as $instance) {
array_push($excludeIds, $instance->getDbId());
}
return $excludeIds;
}
/** /**
* Gets an array of CcShowInstances objects which contain a foreign key that references this object. * Gets an array of CcShowInstances objects which contain a foreign key that references this object.
* *

View File

@ -40,8 +40,7 @@ class CcShowDays extends BaseCcShowDays {
); );
//set timezone to that of the show //set timezone to that of the show
$dt->setTimezone(new DateTimeZone($this->getDbTimezone())); //$dt->setTimezone(new DateTimeZone($this->getDbTimezone()));
return $dt; return $dt;
} }
@ -50,9 +49,9 @@ class CcShowDays extends BaseCcShowDays {
* Returns the end of a show in the timezone it was created in * Returns the end of a show in the timezone it was created in
* @param DateTime $startDateTime first show in show's local time * @param DateTime $startDateTime first show in show's local time
*/ */
public function getLocalEndDateAndTime($showStart) public function getLocalEndDateAndTime()
{ {
$startDateTime = clone $showStart; $startDateTime = $this->getLocalStartDateAndTime();
$duration = explode(":", $this->getDbDuration()); $duration = explode(":", $this->getDbDuration());
return $startDateTime->add(new DateInterval('PT'.$duration[0].'H'.$duration[1].'M')); return $startDateTime->add(new DateInterval('PT'.$duration[0].'H'.$duration[1].'M'));

View File

@ -126,7 +126,15 @@ class Application_Service_CalendarService
} }
} }
$isRepeating = $this->ccShow->getFirstCcShowDay()->isRepeating(); $excludeIds = $this->ccShow->getEditedRepeatingInstanceIds();
$isRepeating = true;
$populateInstance = false;
if (in_array($this->ccShowInstance->getDbId(), $excludeIds)) {
$populateInstance = true;
$isRepeating = false;
}
if (!$this->ccShowInstance->isRebroadcast() && $isAdminOrPM) { if (!$this->ccShowInstance->isRebroadcast() && $isAdminOrPM) {
if ($isRepeating) { if ($isRepeating) {
$menu["edit"] = array( $menu["edit"] = array(
@ -143,6 +151,11 @@ class Application_Service_CalendarService
"name" => _("Edit This Instance"), "name" => _("Edit This Instance"),
"icon" => "edit", "icon" => "edit",
"url" => $baseUrl."Schedule/populate-repeating-show-instance-form"); "url" => $baseUrl."Schedule/populate-repeating-show-instance-form");
} elseif ($populateInstance) {
$menu["edit"] = array(
"name" => _("Edit Show"),
"icon" => "edit",
"url" => $baseUrl."Schedule/populate-repeating-show-instance-form");
} else { } else {
$menu["edit"] = array( $menu["edit"] = array(
"name"=> _("Edit Show"), "name"=> _("Edit Show"),

View File

@ -124,10 +124,14 @@ class Application_Service_ShowFormService
private function populateFormWhen($form) private function populateFormWhen($form)
{ {
$ccShowDay = $this->ccShow->getFirstCcShowDay(); if ($this->ccShow->isRepeating()) {
$ccShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
} else {
$ccShowDay = $this->ccShow->getFirstCcShowDay();
}
$showStart = $ccShowDay->getLocalStartDateAndTime(); $showStart = $ccShowDay->getLocalStartDateAndTime();
$showEnd = $ccShowDay->getLocalEndDateAndTime($showStart); $showEnd = $ccShowDay->getLocalEndDateAndTime();
//check if the first show is in the past //check if the first show is in the past
if ($ccShowDay->isShowStartInPast()) { if ($ccShowDay->isShowStartInPast()) {
@ -198,7 +202,11 @@ class Application_Service_ShowFormService
*/ */
private function populateFormRepeats($form, $nextFutureShowStart) private function populateFormRepeats($form, $nextFutureShowStart)
{ {
$ccShowDays = $this->ccShow->getCcShowDays(); if ($this->ccShow->isRepeating()) {
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
} else {
$ccShowDays = $this->ccShow->getCcShowDayss();
}
$days = array(); $days = array();
foreach ($ccShowDays as $ccShowDay) { foreach ($ccShowDays as $ccShowDay) {

View File

@ -55,11 +55,13 @@ class Application_Service_ShowService
throw new Exception("Permission denied"); throw new Exception("Permission denied");
} }
$showId = $showData["add_show_id"];
/****** UPDATE SCHEDULE START TIME ******/ /****** UPDATE SCHEDULE START TIME ******/
//get the ccShow object to which this instance belongs //get the ccShow object to which this instance belongs
//so we can get the original start date and time //so we can get the original start date and time
$oldCcShow = CcShowQuery::create() $this->ccShow = CcShowQuery::create()
->findPk($showData["add_show_id"]); ->findPk($showId);
//DateTime in shows's local time //DateTime in shows's local time
$newStartDateTime = new DateTime($showData["add_show_start_date"]." ". $newStartDateTime = new DateTime($showData["add_show_start_date"]." ".
@ -68,52 +70,76 @@ class Application_Service_ShowService
$ccShowInstanceOrig = CcShowInstancesQuery::create() $ccShowInstanceOrig = CcShowInstancesQuery::create()
->findPk($showData["add_show_instance_id"]); ->findPk($showData["add_show_instance_id"]);
$diff = $this->calculateShowStartDiff($newStartDateTime,
$ccShowInstanceOrig->getLocalStartDateTime());
if ($diff > 0) { //convert original start time into the show's local timezone
$origLocalStartDateTime = $ccShowInstanceOrig->getLocalStartDateTime();
$diff = $this->calculateShowStartDiff($newStartDateTime,
$origLocalStartDateTime);
if ($diff != 0) {
Application_Service_SchedulerService::updateScheduleStartTime( Application_Service_SchedulerService::updateScheduleStartTime(
array($showData["add_show_instance_id"]), $diff); array($showData["add_show_instance_id"]), $diff);
} }
/****** UPDATE SCHEDULE START TIME ENDS******/ /****** UPDATE SCHEDULE START TIME ENDS******/
$this->setCcShow($showData); /*
$this->setCcShowDays($showData); * In the case where an instance is being edited for a second
$this->setCcShowHosts($showData); * (or third, fourth, etc.) time we need to delete the old
$this->delegateInstanceCreation(); * cc_show_day record
*
* Since we don't store the cc_show_day ids we need to use the
* original start time from cc_show_instances, convert it to the show's
* local timezone, and find the record in cc_show_days
*
* *** There is a flaw here: We have to assume the show timezone has
* *** not changed (make timezone readonly??)
*/
$origCcShowDay = CcShowDaysQuery::create()
->filterByDbShowId($showId)
->filterByDbRepeatType(-1)
->filterByDbFirstShow($origLocalStartDateTime->format("Y-m-d"))
->filterByDbStartTime($origLocalStartDateTime->format("H:i:s"))
->delete();
//get the new instance id /*
$ccShowInstance = CcShowInstancesQuery::create() * Set the new cc_show_day record
->filterByDbShowId($this->ccShow->getDbId()) * Associates it with the current show_id and sets it to non-repeating
*/
$this->setCcShowDays($showData);
// DO WE NEED THIS?
$this->setCcShowHosts($showData);
/*
* We need to find the new show day rule we just created by passing
* in the first show and start time in case multiple single
* instances have been edited out of the repeating sequence.
*/
$showDay = CcShowDaysQuery::create()
->filterByDbShowId($showId)
->filterByDbRepeatType(-1)
->filterByDbFirstShow($showData["add_show_start_date"])
->filterByDbStartTime($showData["add_show_start_time"].":00")
->findOne(); ->findOne();
$newInstanceId = $ccShowInstance->getDbId(); $ccShowInstance = $this->createNonRepeatingInstance($showDay,
$this->getPopulateShowUntilDateTIme());
//update cc_schedule with the new instance id //update cc_schedule with the new instance id
$ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($showData["add_show_instance_id"])
->find();
foreach ($ccSchedules as $ccSchedule) {
$ccSchedule->setDbInstanceId($newInstanceId);
$ccSchedule->save();
}
$con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME); $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
$selectCriteria = new Criteria();
$selectCriteria->add(CcSchedulePeer::INSTANCE_ID, $showData["add_show_instance_id"]);
$updateCriteria = new Criteria();
$updateCriteria->add(CcSchedulePeer::INSTANCE_ID, $ccShowInstance->getDbId());
BasePeer::doUpdate($selectCriteria, $updateCriteria, $con);
$ccShowInstance->updateDbTimeFilled($con); $ccShowInstance->updateDbTimeFilled($con);
$ccShowInstance->updateScheduleStatus($con);
//delete the edited instance from the repeating sequence //delete the edited instance from the repeating sequence
$ccShowInstanceOrig->setDbModifiedInstance(true)->save(); $ccShowInstanceOrig->setDbModifiedInstance(true)->save();
$service_showForm = new Application_Service_ShowFormService($showData["add_show_id"]);
list($start, $end) = $service_showForm->getNextFutureRepeatShowTime();
$oldCcShowDay = $oldCcShow->getFirstCcShowDay();
$oldCcShowDay
->setDbFirstShow(
$start->setTimezone(new DateTimeZone(
$oldCcShowDay->getDbTimezone()))->format("Y-m-d"))
->save();
$con->commit(); $con->commit();
Application_Model_RabbitMq::PushSchedule(); Application_Model_RabbitMq::PushSchedule();
} catch (Exception $e) { } catch (Exception $e) {
@ -131,7 +157,11 @@ class Application_Service_ShowService
*/ */
private function storeOrigLocalShowInfo() private function storeOrigLocalShowInfo()
{ {
$this->origCcShowDay = $this->ccShow->getFirstCcShowDay(); if ($this->ccShow->isRepeating()) {
$this->origCcShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
} else {
$this->origCcShowDay = $this->ccShow->getFirstCcShowDay();
}
$this->oldShowTimezone = $this->origCcShowDay->getDbTimezone(); $this->oldShowTimezone = $this->origCcShowDay->getDbTimezone();
@ -158,6 +188,7 @@ class Application_Service_ShowService
$this->setCcShow($showData); $this->setCcShow($showData);
$daysAdded = array(); $daysAdded = array();
if ($this->isUpdate) { if ($this->isUpdate) {
$daysAdded = $this->delegateInstanceCleanup($showData); $daysAdded = $this->delegateInstanceCleanup($showData);
@ -165,7 +196,7 @@ class Application_Service_ShowService
$this->deleteRebroadcastInstances(); $this->deleteRebroadcastInstances();
$this->deleteCcShowDays(); //$this->deleteCcShowDays();
$this->deleteCcShowHosts(); $this->deleteCcShowHosts();
if ($this->isRebroadcast) { if ($this->isRebroadcast) {
//delete entry in cc_show_rebroadcast //delete entry in cc_show_rebroadcast
@ -225,7 +256,11 @@ class Application_Service_ShowService
if (is_null($this->ccShow)) { if (is_null($this->ccShow)) {
$ccShowDays = $this->getShowDaysInRange($populateUntil, $end); $ccShowDays = $this->getShowDaysInRange($populateUntil, $end);
} else { } else {
$ccShowDays = $this->ccShow->getCcShowDays(); if ($this->ccShow->isRepeating()) {
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
} else {
$ccShowDays = $this->ccShow->getCcShowDayss();
}
} }
if (!is_null($end)) { if (!is_null($end)) {
@ -372,7 +407,11 @@ SQL;
$daysAdded = array(); $daysAdded = array();
//CcShowDay object //CcShowDay object
$currentShowDay = $this->ccShow->getFirstCcShowDay(); if ($this->ccShow->isRepeating()) {
$currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
} else {
$currentShowDay = $this->ccShow->getFirstCcShowDay();
}
//new end date in users' local time //new end date in users' local time
$endDateTime = $this->calculateEndDate($showData); $endDateTime = $this->calculateEndDate($showData);
@ -416,11 +455,17 @@ SQL;
//and the repeat type changed //and the repeat type changed
if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) { if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) {
$this->deleteAllInstances($showId); $this->deleteAllInstances($showId);
} else { // when repeating by day of the month (1st, 2nd, etc.) we do not store the repeat week days
} elseif ($currentRepeatType != 2) {
//repeat type is the same, check if the days of the week are the same //repeat type is the same, check if the days of the week are the same
$repeatingDaysChanged = false; $repeatingDaysChanged = false;
$ccShowDays = $this->ccShow->getCcShowDays(); if ($this->ccShow->isRepeating()) {
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
} else {
$ccShowDays = $this->ccShow->getCcShowDayss();
}
$showDays = array(); $showDays = array();
foreach ($ccShowDays as $day) { foreach ($ccShowDays as $day) {
$showDays[] = $day->getDbDay(); $showDays[] = $day->getDbDay();
@ -695,14 +740,23 @@ SQL;
*/ */
else if (count($ccShowInstances) >= 1) { else if (count($ccShowInstances) >= 1) {
$lastShowDays = array(); $lastShowDays = array();
//get the show's timezone
$ccShow = CcShowQuery::create()->findPk($showId);
if ($ccShow->isRepeating()) {
$showTimezone = $ccShow->getFirstRepeatingCcShowDay()->getDbTimezone();
} else {
$showTimezone = $ccShow->getFirstCcShowDay()->getDbTimezone();
}
/* Creates an array where the key is the day of the week (monday, /* Creates an array where the key is the day of the week (monday,
* tuesday, etc.) and the value is the last show date for each * tuesday, etc.) and the value is the last show date for each
* day of the week. We will use this array to update the last_show * day of the week. We will use this array to update the last_show
* for each cc_show_days entry of a cc_show * for each cc_show_days entry of a cc_show
*/ */
foreach ($ccShowInstances as $instance) { foreach ($ccShowInstances as $instance) {
$instanceStartDT = new DateTime($instance->getDbStarts(), $instanceStartDT = $instance->getDbStarts(null);
new DateTimeZone("UTC")); $instanceStartDT->setTimezone(new DateTimeZone($showTimezone));
$lastShowDays[$instanceStartDT->format("w")] = $instanceStartDT; $lastShowDays[$instanceStartDT->format("w")] = $instanceStartDT;
} }
@ -710,6 +764,7 @@ SQL;
$ccShowDay = CcShowDaysQuery::create() $ccShowDay = CcShowDaysQuery::create()
->filterByDbShowId($showId) ->filterByDbShowId($showId)
->filterByDbDay($dayOfWeek) ->filterByDbDay($dayOfWeek)
->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
->findOne(); ->findOne();
if (isset($ccShowDay)) { if (isset($ccShowDay)) {
@ -725,10 +780,10 @@ SQL;
} }
//remove the old repeating deleted instances. //remove the old repeating deleted instances.
CcShowInstancesQuery::create() /*CcShowInstancesQuery::create()
->filterByDbShowId($showId) ->filterByDbShowId($showId)
->filterByDbModifiedInstance(true) ->filterByDbModifiedInstance(true)
->delete(); ->delete();*/
} }
return false; return false;
@ -915,6 +970,7 @@ SQL;
$this->createRebroadcastInstances($showDay, $start, $ccShowInstance->getDbId()); $this->createRebroadcastInstances($showDay, $start, $ccShowInstance->getDbId());
} }
} }
return $ccShowInstance;
} }
/** /**
@ -1259,12 +1315,13 @@ SQL;
$temp = clone($starts); $temp = clone($starts);
$temp->setTimezone(new DateTimeZone($this->oldShowTimezone)); $temp->setTimezone(new DateTimeZone($this->oldShowTimezone));
$temp->setTime($this->localShowStartHour, $this->localShowStartMin); $temp->setTime($this->localShowStartHour, $this->localShowStartMin);
$temp->setTimezone(new DateTimeZone("UTC")); $temp->setTimezone(new DateTimeZone("UTC"));
$ccShowInstance = CcShowInstancesQuery::create() $ccShowInstance = CcShowInstancesQuery::create()
->filterByDbStarts($temp->format("Y-m-d H:i:s"), Criteria::EQUAL) ->filterByDbStarts($temp->format("Y-m-d H:i:s"), Criteria::EQUAL)
->filterByDbShowId($this->ccShow->getDbId(), Criteria::EQUAL) ->filterByDbShowId($this->ccShow->getDbId(), Criteria::EQUAL)
->filterByDbModifiedInstance(false, Criteria::EQUAL) //->filterByDbModifiedInstance(false, Criteria::EQUAL)
->filterByDbRebroadcast(0, Criteria::EQUAL) ->filterByDbRebroadcast(0, Criteria::EQUAL)
->limit(1) ->limit(1)
->find(); ->find();
@ -1369,7 +1426,16 @@ SQL;
// Don't set day for monthly repeat type, it's invalid // Don't set day for monthly repeat type, it's invalid
if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) { if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) {
$showDay = new CcShowDays();
if ($this->isUpdate) {
$showDay = CcShowDaysQuery::create()
->filterByDbShowId($showId)
->filterByDbRepeatType($showData['add_show_repeat_type'])
->findOne();
} else {
$showDay = new CcShowDays();
}
$showDay->setDbFirstShow($startDateTime->format("Y-m-d")); $showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
$showDay->setDbLastShow($endDate); $showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($startDateTime->format("H:i:s")); $showDay->setDbStartTime($startDateTime->format("H:i:s"));
@ -1395,7 +1461,22 @@ SQL;
$startDateTimeClone->add(new DateInterval("P".$daysAdd."D")); $startDateTimeClone->add(new DateInterval("P".$daysAdd."D"));
} }
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) { if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
$showDay = new CcShowDays();
if ($this->isUpdate) {
$showDay = CcShowDaysQuery::create()
->filterByDbShowId($showId)
->filterByDbRepeatType($this->repeatType)
->filterByDbDay($day)
->findOne();
if (!$showDay) {
//if no show day object was found it is because a new
//repeating day of the week was added
$showDay = new CcShowDays();
}
} else {
$showDay = new CcShowDays();
}
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d")); $showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
$showDay->setDbLastShow($endDate); $showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($startDateTimeClone->format("H:i")); $showDay->setDbStartTime($startDateTimeClone->format("H:i"));
@ -1562,6 +1643,7 @@ SQL;
$repeatInfo = CcShowDaysQuery::create() $repeatInfo = CcShowDaysQuery::create()
->filterByDbShowId($showId) ->filterByDbShowId($showId)
->filterByDbDay($day) ->filterByDbDay($day)
->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
->findOne(); ->findOne();
$repeatInfo->setDbNextPopDate($nextInfo[0]) $repeatInfo->setDbNextPopDate($nextInfo[0])

View File

@ -332,7 +332,7 @@ function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, vie
var url = baseUrl+'Schedule/resize-show/format/json'; var url = baseUrl+'Schedule/resize-show/format/json';
$.post(url, $.post(url,
{day: dayDelta, min: minuteDelta, showId: event.showId}, {day: dayDelta, min: minuteDelta, showId: event.showId, instanceId: event.id},
function(json){ function(json){
if(json.show_error == true){ if(json.show_error == true){
alertShowErrorAndReload(); alertShowErrorAndReload();