From 8d59c18befc1aebee1081c9633053f58b628c97e Mon Sep 17 00:00:00 2001 From: Naomi Date: Thu, 26 May 2011 15:41:47 -0400 Subject: [PATCH] CC-2326 Can't edit a show more than once (End Date problems) show editing assumed inclusive end dates while show creating assumed non inclusive. --- .../controllers/ScheduleController.php | 38 ++++++----- airtime_mvc/application/models/Shows.php | 67 ++++++++++--------- .../public/js/airtime/schedule/add-show.js | 44 +++++++----- .../schedule/full-calendar-functions.js | 46 +++++-------- 4 files changed, 100 insertions(+), 95 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 35a7a28bf..706d3082a 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -227,7 +227,7 @@ class ScheduleController extends Zend_Controller_Action 'callback' => 'window["buildContentDialog"]'), 'title' => 'Show Content'); } - if (strtotime($show->getShowEnd()) <= strtotime($today_timestamp) + if (strtotime($show->getShowEnd()) <= strtotime($today_timestamp) && is_null($show->getSoundCloudFileId()) && Application_Model_Preference::GetDoSoundCloudUpload()) { $menu[] = array('action' => array('type' => 'fn', @@ -405,9 +405,9 @@ class ScheduleController extends Zend_Controller_Action if(!$user->isAdmin()) { return; } - + $showInstanceId = $this->_getParam('id'); - + $formWhat = new Application_Form_AddShowWhat(); $formWho = new Application_Form_AddShowWho(); $formWhen = new Application_Form_AddShowWhen(); @@ -438,7 +438,7 @@ class ScheduleController extends Zend_Controller_Action $showInstance = new ShowInstance($showInstanceId); $show = new Show($showInstance->getShowId()); - + $formWhat->populate(array('add_show_id' => $show->getId(), 'add_show_name' => $show->getName(), 'add_show_url' => $show->getUrl(), @@ -455,10 +455,14 @@ class ScheduleController extends Zend_Controller_Action foreach($showDays as $showDay){ array_push($days, $showDay->getDbDay()); } - + + $displayedEndDate = new DateTime($show->getRepeatingEndDate()); + $displayedEndDate->sub(new DateInterval("P1D"));//end dates are stored non-inclusively. + $displayedEndDate = $displayedEndDate->format("Y-m-d"); + $formRepeats->populate(array('add_show_repeat_type' => $show->getRepeatType(), 'add_show_day_check' => $days, - 'add_show_end_date' => $show->getRepeatingEndDate(), + 'add_show_end_date' => $displayedEndDate, 'add_show_no_end' => ($show->getRepeatingEndDate() == ''))); $formRecord->populate(array('add_show_record' => $show->isRecorded(), @@ -475,7 +479,7 @@ class ScheduleController extends Zend_Controller_Action $rebroadcastFormValues["add_show_rebroadcast_time_$i"] = Show::removeSecondsFromTime($rebroadcast['start_time']); $i++; } - $formRebroadcast->populate($rebroadcastFormValues); + $formRebroadcast->populate($rebroadcastFormValues); $rebroadcastsAbsolute = $show->getRebroadcastsAbsolute(); $rebroadcastAbsoluteFormValues = array(); @@ -497,7 +501,7 @@ class ScheduleController extends Zend_Controller_Action $formStyle->populate(array('add_show_background_color' => $show->getBackgroundColor(), 'add_show_color' => $show->getColor())); - + $this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); $this->view->entries = 5; } @@ -543,7 +547,7 @@ class ScheduleController extends Zend_Controller_Action foreach($js as $j){ $data[$j["name"]] = $j["value"]; } - + $data['add_show_hosts'] = $this->_getParam('hosts'); $data['add_show_day_check'] = $this->_getParam('days'); @@ -586,7 +590,7 @@ class ScheduleController extends Zend_Controller_Action } if($data["add_show_repeats"]) { - + $repeats = $formRepeats->isValid($data); if($repeats) { $repeats = $formRepeats->checkReliantFields($data); @@ -596,7 +600,7 @@ class ScheduleController extends Zend_Controller_Action //make it valid, results don't matter anyways. $rebroadAb = 1; - if ($data["add_show_rebroadcast"]) { + if ($data["add_show_rebroadcast"]) { $rebroad = $formRebroadcast->isValid($data); if($rebroad) { $rebroad = $formRebroadcast->checkReliantFields($data); @@ -612,7 +616,7 @@ class ScheduleController extends Zend_Controller_Action $repeats = 1; $rebroad = 1; - if ($data["add_show_rebroadcast"]) { + if ($data["add_show_rebroadcast"]) { $rebroadAb = $formAbsoluteRebroadcast->isValid($data); if($rebroadAb) { $rebroadAb = $formAbsoluteRebroadcast->checkReliantFields($data); @@ -634,10 +638,10 @@ class ScheduleController extends Zend_Controller_Action if ($data['add_show_id'] != -1){ $show = new Show($data['add_show_id']); $data['add_show_record'] = $show->isRecorded(); - $record = $formRecord->isValid($data); + $record = $formRecord->isValid($data); $formRecord->getElement('add_show_record')->setOptions(array('disabled' => true)); } else { - $record = $formRecord->isValid($data); + $record = $formRecord->isValid($data); } if ($what && $when && $repeats && $who && $style && $record && $rebroadAb && $rebroad) { @@ -650,7 +654,7 @@ class ScheduleController extends Zend_Controller_Action //send back a new form for the user. $formWhat->reset(); $formWhat->populate(array('add_show_id' => '-1')); - + $formWho->reset(); $formWhen->reset(); $formWhen->populate(array('add_show_start_date' => date("Y-m-d"), @@ -704,10 +708,10 @@ class ScheduleController extends Zend_Controller_Action $show->deleteShow(); } } - + public function contentContextMenuAction(){ global $CC_CONFIG; - + $id = $this->_getParam('id'); $params = '/format/json/id/#id#/'; diff --git a/airtime_mvc/application/models/Shows.php b/airtime_mvc/application/models/Shows.php index 83e63f41e..e2911129e 100644 --- a/airtime_mvc/application/models/Shows.php +++ b/airtime_mvc/application/models/Shows.php @@ -320,7 +320,7 @@ class Show { * @param string $p_date * The date which to delete after */ - public function removeAllInstancesAfterDate($p_date){ + public function removeAllInstancesFromDate($p_date){ global $CC_DBC; $date = new DateHelper; @@ -328,7 +328,7 @@ class Show { $showId = $this->getId(); $sql = "DELETE FROM cc_show_instances " - ." WHERE date(starts) > DATE '$p_date'" + ." WHERE date(starts) >= DATE '$p_date'" ." AND starts > TIMESTAMP '$timestamp'" ." AND show_id = $showId"; @@ -590,7 +590,7 @@ class Show { //show "Never Ends" option was toggled. if ($p_data['add_show_no_end']){ } else { - $p_show->removeAllInstancesAfterDate($p_endDate); + $p_show->removeAllInstancesFromDate($p_endDate); } } if ($p_show->getRepeatingEndDate() != $p_data['add_show_end_date']){ @@ -599,7 +599,7 @@ class Show { $newDate = strtotime($p_data['add_show_end_date']); $oldDate = strtotime($p_show->getRepeatingEndDate()); if ($newDate < $oldDate){ - $p_show->removeAllInstancesAfterDate($p_endDate); + $p_show->removeAllInstancesFromDate($p_endDate); } } } @@ -608,7 +608,7 @@ class Show { /** * Create a show. * - * Note: end dates are non inclusive. + * Note: end dates are inclusive. * * @param array $data * @return int @@ -624,17 +624,18 @@ class Show { if ($data['add_show_no_end']) { $endDate = NULL; - //$data['add_show_repeats'] = 1; } else if ($data['add_show_repeats']) { - $sql = "SELECT date '{$data['add_show_end_date']}' + INTERVAL '1 day' "; - $r = $con->query($sql); - $endDate = $r->fetchColumn(0); + //$sql = "SELECT date '{$data['add_show_end_date']}' + INTERVAL '1 day' "; + //$r = $con->query($sql); + //$endDate = $r->fetchColumn(0); + $endDate = $data['add_show_end_date']; } else { - $sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '1 day' "; - $r = $con->query($sql); - $endDate = $r->fetchColumn(0); + //$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '1 day' "; + //$r = $con->query($sql); + //$endDate = $r->fetchColumn(0); + $endDate = $data['add_show_start_date']; } //only want the day of the week from the start date. @@ -703,7 +704,7 @@ class Show { $start = $data['add_show_start_date']; } - if (strtotime($start) < strtotime($endDate) || is_null($endDate)) { + if (strtotime($start) <= strtotime($endDate) || is_null($endDate)) { $showDay = new CcShowDays(); $showDay->setDbFirstShow($start); $showDay->setDbLastShow($endDate); @@ -921,7 +922,7 @@ class Show { $rebroadcasts = $CC_DBC->GetAll($sql); $show = new Show($show_id); - while(strtotime($next_date) < strtotime($end_timestamp) && (strtotime($last_show) > strtotime($next_date) || is_null($last_show))) { + while(strtotime($next_date) <= strtotime($end_timestamp) && (strtotime($last_show) > strtotime($next_date) || is_null($last_show))) { $start = $next_date; @@ -1179,7 +1180,7 @@ class ShowInstance { { $this->_instanceId = $instanceId; $this->_showInstance = CcShowInstancesQuery::create()->findPK($instanceId); - + if (is_null($this->_showInstance)){ throw new Exception(); } @@ -1630,32 +1631,32 @@ class ShowInstance { return $items; } - + public static function GetShowsInstancesIdsInRange($p_timeNow, $p_start, $p_end) { global $CC_DBC; - - $sql = "SELECT id FROM cc_show_instances AS si " + + $sql = "SELECT id FROM cc_show_instances AS si " ."WHERE (" ."(si.starts < TIMESTAMP '$p_timeNow' - INTERVAL '$p_start seconds' " ."AND si.ends > TIMESTAMP '$p_timeNow' - INTERVAL '$p_start seconds') " - ."OR (si.starts > TIMESTAMP '$p_timeNow' - INTERVAL '$p_start seconds' " + ."OR (si.starts > TIMESTAMP '$p_timeNow' - INTERVAL '$p_start seconds' " ."AND si.ends < TIMESTAMP '$p_timeNow' + INTERVAL '$p_end seconds') " ."OR (si.starts < TIMESTAMP '$p_timeNow' + INTERVAL '$p_end seconds' " ."AND si.ends > TIMESTAMP '$p_timeNow' + INTERVAL '$p_end seconds') " .") " ." ORDER BY si.starts"; - + $rows = $CC_DBC->GetAll($sql); return $rows; } - + public function getScheduleItemsInRange($timeNow, $start, $end) { global $CC_DBC, $CC_CONFIG; - + $instanceId = $this->_instanceId; - + $sql = "SELECT" ." si.starts as show_starts," ." si.ends as show_ends," @@ -1687,30 +1688,30 @@ class ShowInstance { return $CC_DBC->GetAll($sql); } - + public function getLastAudioItemEnd(){ global $CC_DBC; - + $sql = "SELECT ends FROM cc_schedule " ."WHERE instance_id = {$this->_instanceId} " ."ORDER BY ends DESC " ."LIMIT 1"; - - return $CC_DBC->GetOne($sql); + + return $CC_DBC->GetOne($sql); } - + public function getShowEndGapTime(){ $showEnd = $this->getShowEnd(); $lastItemEnd = $this->getLastAudioItemEnd(); - + if (is_null($lastItemEnd)){ $lastItemEnd = $this->getShowStart(); } - - + + $diff = strtotime($showEnd) - strtotime($lastItemEnd); - - return ($diff < 0) ? 0 : $diff; + + return ($diff < 0) ? 0 : $diff; } public static function GetLastShowInstance($p_timeNow){ diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index 32cdd0bd3..8b3d43ffb 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -26,11 +26,11 @@ function endDpSelect(dateText, inst) { function createDateInput(el, onSelect) { var date; - + el.datepicker({ minDate: new Date(), onSelect: onSelect, - dateFormat: 'yy-mm-dd' + dateFormat: 'yy-mm-dd' }); } @@ -46,13 +46,23 @@ function findHosts(request, callback) { url = "/User/get-hosts"; search = request.term; - $.post(url, - {format: "json", term: search}, - + $.post(url, + {format: "json", term: search}, + function(json) { callback(json.hosts); }); - + +} + +function beginEditShow(data){ + $("#add-show-form") + .empty() + .append(data.newForm); + + removeAddShowButton(); + setAddShowEvents(); + openAddShowForm(); } function setAddShowEvents() { @@ -155,24 +165,24 @@ function setAddShowEvents() { }); form.find("#add_show_duration").timepicker({ amPmText: ['', ''], - defaultTime: '01:00' + defaultTime: '01:00' }); form.find('input[name^="add_show_rebroadcast_date_absolute"]').datepicker({ minDate: new Date(), - dateFormat: 'yy-mm-dd' + dateFormat: 'yy-mm-dd' }); form.find('input[name^="add_show_rebroadcast_time"]').timepicker({ amPmText: ['', ''], - defaultTime: '' + defaultTime: '' }); form.find(".add_absolute_rebroadcast_day").click(function(){ - var li = $(this).parent().find("ul.formrow-repeat > li:visible:last").next(); - + var li = $(this).parent().find("ul.formrow-repeat > li:visible:last").next(); + li.show(); li = li.next(); - if(li.length === 0) { + if(li.length === 0) { $(this).hide(); } }); @@ -207,11 +217,11 @@ function setAddShowEvents() { list.next().show(); }); - + form.find("#add_show_hosts_autocomplete").autocomplete({ source: findHosts, select: autoSelect, - delay: 200 + delay: 200 }); form.find("#schedule-show-style input").ColorPicker({ @@ -246,7 +256,7 @@ function setAddShowEvents() { .append(json.form); setAddShowEvents(); - }); + }); makeAddShowButton(); }); @@ -255,7 +265,7 @@ function setAddShowEvents() { var addShowButton = $(this); if (!addShowButton.hasClass("disabled")){ addShowButton.addClass("disabled"); - } + } else { return; } @@ -290,7 +300,7 @@ function setAddShowEvents() { $("#add_show_end_date").val(end_date); $("#add_show_start_date").val(start_date); - showErrorSections(); + showErrorSections(); } else { $("#add-show-form") diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js index 3eaaaa13f..57511f491 100644 --- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js +++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js @@ -46,16 +46,6 @@ function removeAddShowButton(){ span.remove(); } -function beginEditShow(data){ - $("#add-show-form") - .empty() - .append(data.newForm); - - removeAddShowButton(); - setAddShowEvents(); - openAddShowForm(); -} - function makeTimeStamp(date){ var sy, sm, sd, h, m, s, timestamp; sy = date.getFullYear(); @@ -70,7 +60,7 @@ function makeTimeStamp(date){ } function dayClick(date, allDay, jsEvent, view) { - var now, today, selected, chosenDate, chosenTime; + var now, today, selected, chosenDate, chosenTime; now = new Date(); @@ -125,7 +115,7 @@ function dayClick(date, allDay, jsEvent, view) { $("#add_show_end_date").val(chosenDate); $("#add_show_start_time").val(chosenTime); $("#schedule-show-when").show(); - + openAddShowForm(); } } @@ -155,7 +145,7 @@ function viewDisplay( view ) { //re-initialize calendar with new slotmin options $(calendarEl) .fullCalendar('destroy') - .fullCalendar(opt) + .fullCalendar(opt) .fullCalendar( 'gotoDate', date ); }); @@ -176,7 +166,7 @@ function viewDisplay( view ) { } } -function eventRender(event, element, view) { +function eventRender(event, element, view) { //only put progress bar on shows that aren't being recorded. if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.record === 0) { @@ -198,29 +188,29 @@ function eventRender(event, element, view) { //record icon (only if not on soundcloud, will always be true for future events) if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.record === 1 && event.soundcloud_id === -1) { - + $(element).find(".fc-event-time").before(''); } if(view.name === 'month' && event.record === 1 && event.soundcloud_id === -1) { - + $(element).find(".fc-event-title").after(''); } //rebroadcast icon if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.rebroadcast === 1) { - + $(element).find(".fc-event-time").before(''); } if(view.name === 'month' && event.rebroadcast === 1) { - + $(element).find(".fc-event-title").after(''); } //soundcloud icon if((view.name === 'agendaDay' || view.name === 'agendaWeek') && event.soundcloud_id !== -1 && event.record === 1) { - + $(element).find(".fc-event-time").before(''); } if(view.name === 'month' && event.soundcloud_id !== -1 && event.record === 1) { - + $(element).find(".fc-event-title").after(''); } } @@ -228,9 +218,9 @@ function eventRender(event, element, view) { function eventAfterRender( event, element, view ) { $(element) - .jjmenu("click", - [{get:"/Schedule/make-context-menu/format/json/id/#id#"}], - {id: event.id}, + .jjmenu("click", + [{get:"/Schedule/make-context-menu/format/json/id/#id#"}], + {id: event.id}, {xposition: "mouse", yposition: "mouse"}); } @@ -239,7 +229,7 @@ function eventDrop(event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui url = '/Schedule/move-show/format/json'; - $.post(url, + $.post(url, {day: dayDelta, min: minuteDelta, showInstanceId: event.id}, function(json){ if(json.error) { @@ -249,19 +239,19 @@ function eventDrop(event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui }); } -function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, view ) { +function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, view ) { var url; url = '/Schedule/resize-show/format/json'; - $.post(url, + $.post(url, {day: dayDelta, min: minuteDelta, showInstanceId: event.id}, function(json){ if(json.error) { alert(json.error); revertFunc(); } - + scheduleRefetchEvents(); }); } @@ -273,7 +263,7 @@ function getFullCalendarEvents(start, end, callback) { end_date = makeTimeStamp(end); url = '/Schedule/event-feed'; - + var d = new Date(); $.post(url, {format: "json", start: start_date, end: end_date, cachep: d.getTime()}, function(json){