From 52c8bc3a01fb9ac7f483b4430f3abff484e227e4 Mon Sep 17 00:00:00 2001 From: naomiaro Date: Fri, 10 Dec 2010 15:44:36 -0500 Subject: [PATCH] tells you what shows overlap on add, re adds datepickers to newly displayed form. --- .../controllers/ScheduleController.php | 19 ++++++---- application/forms/AddShow.php | 14 ++++---- application/models/Shows.php | 22 +++++++++--- public/js/campcaster/schedule/schedule.js | 35 ++++++++++++++++--- 4 files changed, 67 insertions(+), 23 deletions(-) diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index 9d468d9c9..7337f1c9c 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -14,7 +14,8 @@ class ScheduleController extends Zend_Controller_Action $ajaxContext->addActionContext('event-feed', 'json') ->addActionContext('add-show-dialog', 'json') ->addActionContext('add-show', 'json') - ->addActionContext('move-show', 'json') + ->addActionContext('move-show', 'json') + ->addActionContext('resize-show', 'json') ->initContext(); } @@ -39,7 +40,7 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $show = new Show($userInfo->type); + $show = new Show($userInfo->id, $userInfo->type); $this->view->events = $show->getFullCalendarEvents($start, $end, $weekday); } @@ -53,8 +54,14 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $show = new Show($userInfo->type); - $show->addShow($form->getValues()); + $show = new Show($userInfo->id, $userInfo->type); + $overlap = $show->addShow($form->getValues()); + + if(isset($overlap)) { + $this->view->overlap = $overlap; + $this->view->form = $form->__toString(); + } + return; } } @@ -69,7 +76,7 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $show = new Show($userInfo->type); + $show = new Show($userInfo->id, $userInfo->type); $overlap = $show->moveShow($showId, $deltaDay, $deltaMin); @@ -85,7 +92,7 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $show = new Show($userInfo->type); + $show = new Show($userInfo->id, $userInfo->type); $overlap = $show->resizeShow($showId, $deltaDay, $deltaMin); diff --git a/application/forms/AddShow.php b/application/forms/AddShow.php index 64e3ff29a..98f159a22 100644 --- a/application/forms/AddShow.php +++ b/application/forms/AddShow.php @@ -99,14 +99,12 @@ class Application_Form_AddShow extends Zend_Form $options[$host['id']] = $host['login']; } - $this->addElement( - 'multiselect', - 'hosts', - array( - 'label' => 'Hosts:', - 'required' => true, - 'multiOptions' => $options - )); + $hosts = new Zend_Form_Element_Multiselect('hosts'); + $hosts->setLabel('Hosts:') + ->setMultiOptions($options) + ->setRequired(true); + + $this->addElement($hosts); } diff --git a/application/models/Shows.php b/application/models/Shows.php index d35ce4f9c..c649e2bb4 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -3,11 +3,12 @@ class Show { private $_userRole; + private $_userId; - public function __construct($userType='G') + public function __construct($userId, $userType='G') { $this->_userRole = $userType; - + $this->_userId = $userId; } //end dates are non inclusive. @@ -41,6 +42,12 @@ class Show { if($data['day_check'] === null) { $data['day_check'] = array($startDow); } + + $overlap = $this->getShows($data['start_date'], $endDate, $data['day_check'], $data['start_time'], $endTime); + + if(count($overlap) > 0) { + return $overlap; + } $show = new CcShow(); $show->setDbName($data['name']); @@ -76,7 +83,13 @@ class Show { $showDay->setDbShowId($showId); $showDay->save(); } - + + foreach ($data['hosts'] as $host) { + $showHost = new CcShowHosts(); + $showHost->setDbShow($showId); + $showHost->setDbHost($host); + $showHost->save(); + } } public function moveShow($showId, $deltaDay, $deltaMin){ @@ -121,7 +134,6 @@ class Show { $show->setDbEndTime($e_time); $show->save(); } - } public function resizeShow($showId, $deltaDay, $deltaMin){ @@ -188,7 +200,7 @@ class Show { $sql = $sql_gen ." WHERE ". $sql_range; } if(!is_null($start) && is_null($end)) { - $sql_range = "(last_show IS NULL) + $sql_range = "(first_show <= '{$start}' AND last_show IS NULL) OR (last_show > '{$start}')"; $sql = $sql_gen ." WHERE ". $sql_range; diff --git a/public/js/campcaster/schedule/schedule.js b/public/js/campcaster/schedule/schedule.js index 5a6ffc80e..48c68cac4 100644 --- a/public/js/campcaster/schedule/schedule.js +++ b/public/js/campcaster/schedule/schedule.js @@ -47,8 +47,35 @@ function submitShow() { formData, function(data){ if(data.form) { - $("#schedule_add_event_dialog").find("form").remove(); - $("#schedule_add_event_dialog").append(data.form); + dialog.find("form").remove(); + dialog.append(data.form); + + var start = dialog.find("#start_date"); + var end = dialog.find("#end_date"); + + createDateInput(start, startDpSelect); + createDateInput(end, endDpSelect); + + if(data.overlap) { + var table, tr, days; + table = $(""); + days = $.datepicker.regional[''].dayNamesShort; + + $.each(data.overlap, function(i, val){ + tr = $(""); + tr + .append("") + .append("") + .append("") + .append(""); + + table.append(tr); + }); + + dialog.append("Cannot add show. New show overlaps the following shows:"); + dialog.append(table); + } + } else { $("#schedule_calendar").fullCalendar( 'refetchEvents' ); @@ -82,7 +109,7 @@ function makeShowDialog(html) { width: 950, height: 400, close: closeDialog, - buttons: { "Ok": submitShow } + buttons: { "Cancel": closeDialog, "Ok": submitShow} }); return dialog; @@ -155,7 +182,7 @@ $(document).ready(function() { $('#schedule_calendar').fullCalendar({ header: { - left: 'next, today', + left: 'prev, next, today', center: 'title', right: 'agendaDay, agendaWeek, month' },
"+val.name+""+days[val.day]+""+val.start_time+""+val.end_time+"