CC-1805: Ability to edit a show
-Almost bug free....
This commit is contained in:
parent
ea11e0114a
commit
e01f493c14
2 changed files with 91 additions and 26 deletions
|
@ -456,6 +456,29 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
|
|
||||||
$formRecord->populate(array('add_show_record' => $show->isRecorded(),
|
$formRecord->populate(array('add_show_record' => $show->isRecorded(),
|
||||||
'add_show_rebroadcast' => $show->isRebroadcast()));
|
'add_show_rebroadcast' => $show->isRebroadcast()));
|
||||||
|
$formRecord->getElement('add_show_record')->setOptions(array('disabled' => true));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$rebroadcastsRelative = $show->getRebroadcastsRelative();
|
||||||
|
$rebroadcastFormValues = array();
|
||||||
|
$i = 1;
|
||||||
|
foreach ($rebroadcastsRelative as $rebroadcast){
|
||||||
|
$rebroadcastFormValues["add_show_rebroadcast_date_$i"] = $rebroadcast['day_offset'];
|
||||||
|
$rebroadcastFormValues["add_show_rebroadcast_time_$i"] = Show::removeSecondsFromTime($rebroadcast['start_time']);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$formRebroadcast->populate($rebroadcastFormValues);
|
||||||
|
|
||||||
|
$rebroadcastsAbsolute = $show->getRebroadcastsAbsolute();
|
||||||
|
$rebroadcastAbsoluteFormValues = array();
|
||||||
|
$i = 1;
|
||||||
|
foreach ($rebroadcastsAbsolute as $rebroadcast){
|
||||||
|
$rebroadcastAbsoluteFormValues["add_show_rebroadcast_absolute_date_$i"] = $rebroadcast['start_date'];
|
||||||
|
$rebroadcastAbsoluteFormValues["add_show_rebroadcast_absolute_time_$i"] = Show::removeSecondsFromTime($rebroadcast['start_time']);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$formAbsoluteRebroadcast->populate($rebroadcastAbsoluteFormValues);
|
||||||
|
|
||||||
$hosts = array();
|
$hosts = array();
|
||||||
$showHosts = CcShowHostsQuery::create()->filterByDbShow($showInstance->getShowId())->find();
|
$showHosts = CcShowHostsQuery::create()->filterByDbShow($showInstance->getShowId())->find();
|
||||||
|
|
|
@ -153,7 +153,7 @@ class Show {
|
||||||
*/
|
*/
|
||||||
public function isRecorded(){
|
public function isRecorded(){
|
||||||
$showInstancesRow = CcShowInstancesQuery::create()
|
$showInstancesRow = CcShowInstancesQuery::create()
|
||||||
->filterByDbShowId($this->_showId)
|
->filterByDbShowId($this->getId())
|
||||||
->filterByDbRecord(1)
|
->filterByDbRecord(1)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
|
@ -176,6 +176,36 @@ class Show {
|
||||||
|
|
||||||
return !is_null($showInstancesRow);
|
return !is_null($showInstancesRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRebroadcastsAbsolute()
|
||||||
|
{
|
||||||
|
global $CC_DBC;
|
||||||
|
|
||||||
|
$showId = $this->getId();
|
||||||
|
$sql = "SELECT date(starts) "
|
||||||
|
."FROM cc_show_instances "
|
||||||
|
."WHERE show_id = $showId "
|
||||||
|
."AND record = 1";
|
||||||
|
$baseDate = $CC_DBC->GetOne($sql);
|
||||||
|
|
||||||
|
$sql = "SELECT date(DATE '$baseDate' + day_offset::INTERVAL) as start_date, start_time FROM cc_show_rebroadcast "
|
||||||
|
."WHERE show_id = $showId "
|
||||||
|
."ORDER BY start_date";
|
||||||
|
|
||||||
|
return $CC_DBC->GetAll($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRebroadcastsRelative()
|
||||||
|
{
|
||||||
|
global $CC_DBC;
|
||||||
|
|
||||||
|
$showId = $this->getId();
|
||||||
|
$sql = "SELECT day_offset, start_time FROM cc_show_rebroadcast "
|
||||||
|
."WHERE show_id = $showId "
|
||||||
|
."ORDER BY day_offset";
|
||||||
|
|
||||||
|
return $CC_DBC->GetAll($sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the current show is set to repeat
|
* Check whether the current show is set to repeat
|
||||||
|
@ -240,10 +270,14 @@ class Show {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAllInstances(){
|
public function deleteAllInstances(){
|
||||||
CcShowInstancesQuery::create()
|
global $CC_DBC;
|
||||||
->filterByDbShowId($this->getId())
|
|
||||||
->find()
|
$showId = $this->getId();
|
||||||
->delete();
|
$sql = "DELETE FROM cc_show_instances "
|
||||||
|
."WHERE starts > current_timestamp "
|
||||||
|
."AND show_id = $showId";
|
||||||
|
|
||||||
|
$CC_DBC->query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeAllInstancesAfterDate($p_date){
|
public function removeAllInstancesAfterDate($p_date){
|
||||||
|
@ -416,11 +450,12 @@ class Show {
|
||||||
return CcShowInstancesQuery::create()->findPk($row);
|
return CcShowInstancesQuery::create()->findPk($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function deletePossiblyInvalidInstances($p_data, $p_show, $p_endDate)
|
public static function deletePossiblyInvalidInstances($p_data, $p_show, $p_endDate, $isRecorded, $repeatType)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($p_data['add_show_repeats'] != $p_show->isRepeating()){
|
if ($p_data['add_show_repeats'] != $p_show->isRepeating()
|
||||||
//repeat option was toggled.
|
|| $isRecorded){
|
||||||
|
//repeat option was toggled or show is recorded.
|
||||||
$p_show->deleteAllInstances();
|
$p_show->deleteAllInstances();
|
||||||
}
|
}
|
||||||
if ($p_data['add_show_start_date'] != $p_show->getStartDate()
|
if ($p_data['add_show_start_date'] != $p_show->getStartDate()
|
||||||
|
@ -441,7 +476,7 @@ class Show {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($p_data['add_show_repeats']){
|
if ($p_data['add_show_repeats']){
|
||||||
if ($p_data['add_show_repeat_type'] != $p_show->getRepeatType()){
|
if ($repeatType != $p_show->getRepeatType()){
|
||||||
//repeat type changed.
|
//repeat type changed.
|
||||||
$p_show->deleteAllInstances();
|
$p_show->deleteAllInstances();
|
||||||
} else {
|
} else {
|
||||||
|
@ -530,10 +565,10 @@ class Show {
|
||||||
|
|
||||||
//find repeat type or set to a non repeating show.
|
//find repeat type or set to a non repeating show.
|
||||||
if ($data['add_show_repeats']) {
|
if ($data['add_show_repeats']) {
|
||||||
$repeat_type = $data["add_show_repeat_type"];
|
$repeatType = $data["add_show_repeat_type"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$repeat_type = -1;
|
$repeatType = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data['add_show_id'] == -1){
|
if ($data['add_show_id'] == -1){
|
||||||
|
@ -549,13 +584,22 @@ class Show {
|
||||||
$ccShow->setDbBackgroundColor($data['add_show_background_color']);
|
$ccShow->setDbBackgroundColor($data['add_show_background_color']);
|
||||||
$ccShow->save();
|
$ccShow->save();
|
||||||
|
|
||||||
$isRecorded = ($data['add_show_record']) ? 1 : 0;
|
|
||||||
|
|
||||||
$showId = $ccShow->getDbId();
|
$showId = $ccShow->getDbId();
|
||||||
$show = new Show($showId);
|
$show = new Show($showId);
|
||||||
|
|
||||||
|
//If show is a new show (not updated), then get
|
||||||
|
//isRecorded from POST data. Otherwise get it from
|
||||||
|
//the database since the user is not allowed to
|
||||||
|
//update this option.
|
||||||
|
if ($data['add_show_id'] == -1){
|
||||||
|
$isRecorded = ($data['add_show_record']) ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
$isRecorded = $show->isRecorded();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($data['add_show_id'] != -1){
|
if ($data['add_show_id'] != -1){
|
||||||
Show::deletePossiblyInvalidInstances($data, $show, $endDate);
|
Show::deletePossiblyInvalidInstances($data, $show, $endDate, $isRecorded, $repeatType);
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if we are adding or updating a show, and if updating
|
//check if we are adding or updating a show, and if updating
|
||||||
|
@ -571,12 +615,11 @@ class Show {
|
||||||
$showDay->setDbLastShow($endDate);
|
$showDay->setDbLastShow($endDate);
|
||||||
$showDay->setDbStartTime($data['add_show_start_time']);
|
$showDay->setDbStartTime($data['add_show_start_time']);
|
||||||
$showDay->setDbDuration($data['add_show_duration']);
|
$showDay->setDbDuration($data['add_show_duration']);
|
||||||
$showDay->setDbRepeatType($repeat_type);
|
$showDay->setDbRepeatType($repeatType);
|
||||||
$showDay->setDbShowId($showId);
|
$showDay->setDbShowId($showId);
|
||||||
$showDay->setDbRecord($isRecorded);
|
$showDay->setDbRecord($isRecorded);
|
||||||
$showDay->save();
|
$showDay->save();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
foreach ($data['add_show_day_check'] as $day) {
|
foreach ($data['add_show_day_check'] as $day) {
|
||||||
if ($startDow !== $day){
|
if ($startDow !== $day){
|
||||||
|
|
||||||
|
@ -600,7 +643,7 @@ class Show {
|
||||||
$showDay->setDbStartTime($data['add_show_start_time']);
|
$showDay->setDbStartTime($data['add_show_start_time']);
|
||||||
$showDay->setDbDuration($data['add_show_duration']);
|
$showDay->setDbDuration($data['add_show_duration']);
|
||||||
$showDay->setDbDay($day);
|
$showDay->setDbDay($day);
|
||||||
$showDay->setDbRepeatType($repeat_type);
|
$showDay->setDbRepeatType($repeatType);
|
||||||
$showDay->setDbShowId($showId);
|
$showDay->setDbShowId($showId);
|
||||||
$showDay->setDbRecord($isRecorded);
|
$showDay->setDbRecord($isRecorded);
|
||||||
$showDay->save();
|
$showDay->save();
|
||||||
|
@ -614,7 +657,7 @@ class Show {
|
||||||
CcShowRebroadcastQuery::create()->filterByDbShowId($data['add_show_id'])->delete();
|
CcShowRebroadcastQuery::create()->filterByDbShowId($data['add_show_id'])->delete();
|
||||||
}
|
}
|
||||||
//adding rows to cc_show_rebroadcast
|
//adding rows to cc_show_rebroadcast
|
||||||
if ($data['add_show_record'] && $data['add_show_rebroadcast'] && $repeat_type != -1) {
|
if ($isRecorded && $data['add_show_rebroadcast'] && $repeatType != -1) {
|
||||||
|
|
||||||
for ($i=1; $i<=5; $i++) {
|
for ($i=1; $i<=5; $i++) {
|
||||||
|
|
||||||
|
@ -626,8 +669,7 @@ class Show {
|
||||||
$showRebroad->save();
|
$showRebroad->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if ($isRecorded && $data['add_show_rebroadcast'] && $repeatType == -1){
|
||||||
else if ($data['add_show_record'] && $data['add_show_rebroadcast'] && $repeat_type == -1){
|
|
||||||
|
|
||||||
for ($i=1; $i<=5; $i++) {
|
for ($i=1; $i<=5; $i++) {
|
||||||
|
|
||||||
|
@ -857,21 +899,21 @@ class Show {
|
||||||
RabbitMq::PushSchedule();
|
RabbitMq::PushSchedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function populateShow($repeat_type, $show_id, $next_pop_date,
|
private static function populateShow($repeatType, $show_id, $next_pop_date,
|
||||||
$first_show, $last_show, $start_time, $duration, $day, $record, $end_timestamp) {
|
$first_show, $last_show, $start_time, $duration, $day, $record, $end_timestamp) {
|
||||||
|
|
||||||
if($repeat_type == -1) {
|
if($repeatType == -1) {
|
||||||
Show::populateNonRepeatingShow($show_id, $first_show, $start_time, $duration, $day, $record, $end_timestamp);
|
Show::populateNonRepeatingShow($show_id, $first_show, $start_time, $duration, $day, $record, $end_timestamp);
|
||||||
}
|
}
|
||||||
else if($repeat_type == 0) {
|
else if($repeatType == 0) {
|
||||||
Show::populateRepeatingShow($show_id, $next_pop_date, $first_show, $last_show,
|
Show::populateRepeatingShow($show_id, $next_pop_date, $first_show, $last_show,
|
||||||
$start_time, $duration, $day, $record, $end_timestamp, '7 days');
|
$start_time, $duration, $day, $record, $end_timestamp, '7 days');
|
||||||
}
|
}
|
||||||
else if($repeat_type == 1) {
|
else if($repeatType == 1) {
|
||||||
Show::populateRepeatingShow($show_id, $next_pop_date, $first_show, $last_show,
|
Show::populateRepeatingShow($show_id, $next_pop_date, $first_show, $last_show,
|
||||||
$start_time, $duration, $day, $record, $end_timestamp, '14 days');
|
$start_time, $duration, $day, $record, $end_timestamp, '14 days');
|
||||||
}
|
}
|
||||||
else if($repeat_type == 2) {
|
else if($repeatType == 2) {
|
||||||
Show::populateRepeatingShow($show_id, $next_pop_date, $first_show, $last_show,
|
Show::populateRepeatingShow($show_id, $next_pop_date, $first_show, $last_show,
|
||||||
$start_time, $duration, $day, $record, $end_timestamp, '1 month');
|
$start_time, $duration, $day, $record, $end_timestamp, '1 month');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue