diff --git a/.zfproject.xml b/.zfproject.xml index 986d3777a..f2620db70 100644 --- a/.zfproject.xml +++ b/.zfproject.xml @@ -53,6 +53,8 @@ + + @@ -167,6 +169,12 @@ + + + + + + diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index f22ee89ff..6acb96ee3 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -32,6 +32,10 @@ class ScheduleController extends Zend_Controller_Action $end = $this->_getParam('end', null); $weekday = $this->_getParam('weekday', null); + if(!is_null($weekday)) { + $weekday = array($weekday); + } + $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $show = new Show($userInfo->type); @@ -56,33 +60,21 @@ class ScheduleController extends Zend_Controller_Action $this->view->form = $form->__toString(); } - function addShow() + public function moveShowAction() { - //name, description, hosts, allDay, repeats, - //start_time, duration, start_date, end_date, dofw + $deltaDay = $this->_getParam('day'); + $deltaMin = $this->_getParam('min'); + $showId = $this->_getParam('showId'); - /* - $name = $this->_getParam('name', 'Default Name'); - $description = $this->_getParam('description', ''); - $hosts = $this->_getParam('hosts'); - $allDay = $this->_getParam('all_day', false); - $repeats = $this->_getParam('repeats', false); - $startTime = $this->_getParam('start_time'); - $duration = $this->_getParam('duration'); - $startDate = $this->_getParam('start_date'); - $endDate = $this->_getParam('end_date', null); - $dofw = $this->_getParam('dofw'); + $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - if($repeats === false) - $endDate = $startDate; + $show = new Show($userInfo->type); + $show->moveShow($showId, $deltaDay, $deltaMin); + } - $repeats = $repeats ? 1 : 0; - */ - - //$userInfo = Zend_Auth::getInstance()->getStorage()->read(); - - //$show = new Show($userInfo->type); - //$show->addShow($name, $startDate, $endDate, $startTime, $duration, $repeats, $dofw, $description); + public function resizeShowAction() + { + // action body } @@ -94,3 +86,7 @@ class ScheduleController extends Zend_Controller_Action + + + + diff --git a/application/forms/AddShow.php b/application/forms/AddShow.php index bb0f34ca7..64e3ff29a 100644 --- a/application/forms/AddShow.php +++ b/application/forms/AddShow.php @@ -30,17 +30,6 @@ class Application_Form_AddShow extends Zend_Form ) )); - // Add end date element - $this->addElement('text', 'end_date', array( - 'label' => 'Date End:', - 'required' => false, - 'filters' => array('StringTrim'), - 'validators' => array( - 'NotEmpty', - array('date', false, array('YYYY-MM-DD')) - ) - )); - // Add start time element $this->addElement('text', 'start_time', array( 'label' => 'Start Time:', @@ -52,23 +41,6 @@ class Application_Form_AddShow extends Zend_Form ) )); - /* - $this->addElement( - 'select', - 'start_time', - array( - 'label' => 'Start Time:', - 'required' => true, - 'multiOptions' => array( - "00:00" => "00:00", - "00:30" => "00:30", - "01:00" => "01:00", - "01:30" => "01:30", - "02:00" => "02:00", - ), - )); - */ - // Add duration element $this->addElement('text', 'duration', array( 'label' => 'Duration:', @@ -80,6 +52,12 @@ class Application_Form_AddShow extends Zend_Form ) )); + // Add repeats element + $this->addElement('checkbox', 'repeats', array( + 'label' => 'repeats', + 'required' => false, + )); + $this->addElement( 'multiCheckbox', 'day_check', @@ -97,15 +75,16 @@ class Application_Form_AddShow extends Zend_Form ), )); - $this->addElement('checkbox', 'all_day', array( - 'label' => 'all day', + // Add end date element + $this->addElement('text', 'end_date', array( + 'label' => 'Date End:', 'required' => false, - )); - - $this->addElement('checkbox', 'repeats', array( - 'label' => 'repeats', - 'required' => false, - )); + 'filters' => array('StringTrim'), + 'validators' => array( + 'NotEmpty', + array('date', false, array('YYYY-MM-DD')) + ) + )); $this->addElement('checkbox', 'no_end', array( 'label' => 'no end', diff --git a/application/models/Shows.php b/application/models/Shows.php index b6a000d8b..8a517ed61 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -53,6 +53,7 @@ class Show { if($data['no_end']) { $endDate = NULL; + $data['repeats'] = 1; } else if($data['repeats']) { $endDate = $data['end_date']; @@ -97,7 +98,29 @@ class Show { } - public function getShows($start=NULL, $end=NULL, $weekday=NULL) { + public function moveShow($showId, $deltaDay, $deltaMin){ + global $CC_DBC; + + $sql = "SELECT * FROM cc_show WHERE show_id = '{$showId}'"; + $res = $CC_DBC->GetAll($sql); + + $show = $res[0]; + $start = $show["first_show"]; + $end = $show["last_show"]; + $days = array(); + $s_time = $show["start_time"]; + $e_time = $show["end_time"]; + + foreach($res as $show) { + $days[] = $show["day"]; + } + + $shows_overlap = $this->getShows($start, $end, $days, $s_time, $e_time); + + echo $shows_overlap; + } + + public function getShows($start=NULL, $end=NULL, $days=NULL, $s_time=NULL, $e_time=NULL) { global $CC_DBC; $sql; @@ -113,12 +136,27 @@ class Show { $sql = $sql_gen ." WHERE ". $sql_range; } - if(!is_null($weekday)){ - $sql_day = "day = {$weekday}"; + if(!is_null($days)){ + + $sql_opt = array(); + foreach ($days as $day) { + $sql_opt[] = "day = {$day}"; + } + $sql_day = join(" OR ", $sql_opt); $sql = $sql_gen ." WHERE (". $sql_day ." AND (". $sql_range ."))"; } - + if(!is_null($s_time) && !is_null($e_time)) { + $sql_time = "(start_time <= '{$s_time}' AND end_time >= '{$e_time}') + OR (start_time >= '{$s_time}' AND end_time <= '{$e_time}') + OR (end_time > '{$s_time}' AND end_time <= '{$e_time}') + OR (start_time >= '{$s_time}' AND start_time < '{$e_time}')"; + + $sql = $sql_gen ." WHERE (". $sql_day ." AND (". $sql_range .") AND (". $sql_time ."))"; + } + + //echo $sql; + return $CC_DBC->GetAll($sql); } @@ -150,15 +188,24 @@ class Show { $end_epoch = strtotime($end); + //add repeating events until the show end is reached or fullcalendar's end date is reached. if($row["repeats"]) { + if(!is_null($row["last_show"])) { + $time = $row["last_show"] ." ".$row["end_time"]; + $show_end_epoch = strtotime($time); + } + while(true) { $diff = "SELECT date '{$newDate}' + integer '7'"; $repeatDate = $CC_DBC->GetOne($diff); $repeat_epoch = strtotime($repeatDate); - if ($repeat_epoch < $end_epoch ) { + if (isset($show_end_epoch) && $repeat_epoch < $show_end_epoch && $repeat_epoch < $end_epoch) { + $shows[] = $this->makeFullCalendarEvent($row, $repeatDate); + } + else if(!isset($show_end_epoch) && $repeat_epoch < $end_epoch) { $shows[] = $this->makeFullCalendarEvent($row, $repeatDate); } else { diff --git a/public/js/campcaster/schedule/schedule.js b/public/js/campcaster/schedule/schedule.js index 1a9d5dbed..fa19fc088 100644 --- a/public/js/campcaster/schedule/schedule.js +++ b/public/js/campcaster/schedule/schedule.js @@ -113,13 +113,34 @@ function eventMouseout(event, jsEvent, view) { } function eventDrop(event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui, view) { - var x; + var url; + + url = '/Schedule/move-show/format/json'; + + $.post(url, + {day: dayDelta, min: minuteDelta, showId: event.id}, + function(json){ + if(json.error) { + revertFunc(); + } + }); } function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, view ) { var x; } +function openShowDialog() { + var url; + + url = '/Schedule/add-show-dialog/format/json'; + + $.get(url, function(json){ + var dialog = makeShowDialog(json.form); + dialog.dialog('open'); + }); +} + $(document).ready(function() { $('#schedule_calendar').fullCalendar({ @@ -130,6 +151,7 @@ $(document).ready(function() { }, defaultView: 'agendaDay', editable: false, + allDaySlot: false, events: function(start, end, callback) { var url, start_date, end_date; @@ -170,17 +192,7 @@ $(document).ready(function() { }) - $('#schedule_add_show').click(function() { - var url; - - url = '/Schedule/add-show-dialog/format/json'; - - $.get(url, function(json){ - var dialog = makeShowDialog(json.form); - dialog.dialog('open'); - }); - - }); + $('#schedule_add_show').click(openShowDialog); });