using zend form for validation of adding shows, still needs some UI tweaks for showing/hiding options
This commit is contained in:
parent
5490c9935a
commit
8dbc07e352
9 changed files with 211 additions and 179 deletions
|
@ -18,17 +18,6 @@ class IndexController extends Zend_Controller_Action
|
|||
$this->_helper->layout->setLayout('layout');
|
||||
}
|
||||
|
||||
public function newfieldAction()
|
||||
{
|
||||
// action body
|
||||
}
|
||||
|
||||
public function displayAction()
|
||||
{
|
||||
// action body
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class PlaylistController extends Zend_Controller_Action
|
|||
$request = $this->getRequest();
|
||||
$form = new Application_Form_PlaylistMetadata();
|
||||
|
||||
if ($this->getRequest()->isPost()) {
|
||||
if ($request->isPost()) {
|
||||
if ($form->isValid($request->getPost())) {
|
||||
|
||||
$formdata = $form->getValues();
|
||||
|
|
|
@ -40,16 +40,28 @@ class ScheduleController extends Zend_Controller_Action
|
|||
|
||||
public function addShowDialogAction()
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$this->view->hosts = $user->getHosts();
|
||||
$request = $this->getRequest();
|
||||
$form = new Application_Form_AddShow();
|
||||
|
||||
if ($request->isPost()) {
|
||||
if ($form->isValid($request->getPost())) {
|
||||
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
|
||||
$show = new Show($userInfo->type);
|
||||
$show->addShow($form->getValues());
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->view->form = $form->__toString();
|
||||
}
|
||||
|
||||
public function addShowAction()
|
||||
function addShow()
|
||||
{
|
||||
//name, description, hosts, allDay, repeats,
|
||||
//start_time, duration, start_date, end_date, dofw
|
||||
|
||||
/*
|
||||
$name = $this->_getParam('name', 'Default Name');
|
||||
$description = $this->_getParam('description', '');
|
||||
$hosts = $this->_getParam('hosts');
|
||||
|
@ -65,11 +77,12 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$endDate = $startDate;
|
||||
|
||||
$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);
|
||||
//$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
|
||||
//$show = new Show($userInfo->type);
|
||||
//$show->addShow($name, $startDate, $endDate, $startTime, $duration, $repeats, $dofw, $description);
|
||||
}
|
||||
|
||||
|
||||
|
|
126
application/forms/AddShow.php
Normal file
126
application/forms/AddShow.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShow extends Zend_Form
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
// Add name element
|
||||
$this->addElement('text', 'name', array(
|
||||
'label' => 'Name:',
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array('NotEmpty')
|
||||
));
|
||||
|
||||
// Add the description element
|
||||
$this->addElement('textarea', 'description', array(
|
||||
'label' => 'Description:',
|
||||
'required' => false,
|
||||
));
|
||||
|
||||
// Add start date element
|
||||
$this->addElement('text', 'start_date', array(
|
||||
'label' => 'Date Start:',
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))
|
||||
)
|
||||
));
|
||||
|
||||
// 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'))
|
||||
)
|
||||
));
|
||||
|
||||
$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",
|
||||
),
|
||||
));
|
||||
|
||||
$this->addElement(
|
||||
'select',
|
||||
'duration',
|
||||
array(
|
||||
'label' => 'Duration:',
|
||||
'required' => true,
|
||||
'multiOptions' => array(
|
||||
"00:30" => "00:30",
|
||||
"01:00" => "01:00",
|
||||
"01:30" => "01:30",
|
||||
"02:00" => "02:00",
|
||||
),
|
||||
));
|
||||
|
||||
$this->addElement(
|
||||
'multiCheckbox',
|
||||
'day_check',
|
||||
array(
|
||||
'label' => 'Select Days:',
|
||||
'required' => false,
|
||||
'multiOptions' => array(
|
||||
"0" => "Sun",
|
||||
"1" => "Mon",
|
||||
"2" => "Tue",
|
||||
"3" => "Wed",
|
||||
"4" => "Thu",
|
||||
"5" => "Fri",
|
||||
"6" => "Sat",
|
||||
),
|
||||
));
|
||||
|
||||
$this->addElement('checkbox', 'all_day', array(
|
||||
'label' => 'all day',
|
||||
'required' => false,
|
||||
));
|
||||
|
||||
$this->addElement('checkbox', 'repeats', array(
|
||||
'label' => 'repeats',
|
||||
'required' => false,
|
||||
));
|
||||
|
||||
$this->addElement('checkbox', 'no_end', array(
|
||||
'label' => 'no end',
|
||||
'required' => false,
|
||||
));
|
||||
|
||||
$user = new User();
|
||||
$options = array();
|
||||
$hosts = $user->getHosts();
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
$options[$host['id']] = $host['login'];
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'multiselect',
|
||||
'hosts',
|
||||
array(
|
||||
'label' => 'Hosts:',
|
||||
'required' => true,
|
||||
'multiOptions' => $options
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -35,23 +35,37 @@ class Show {
|
|||
return $event;
|
||||
}
|
||||
|
||||
public function addShow($name, $startDate, $endDate, $startTime, $duration, $repeats, $days, $description) {
|
||||
|
||||
public function addShow($data) {
|
||||
|
||||
$con = Propel::getConnection("campcaster");
|
||||
|
||||
$sql = "SELECT time '{$startTime}' + INTERVAL '{$duration} hour' ";
|
||||
$sql = "SELECT time '{$data['start_time']}' + INTERVAL '{$data['duration']} hour' ";
|
||||
$r = $con->query($sql);
|
||||
$endTime = $r->fetchColumn(0);
|
||||
|
||||
$sql = "SELECT nextval('schedule_group_id_seq')";
|
||||
$sql = "SELECT nextval('show_group_id_seq')";
|
||||
$r = $con->query($sql);
|
||||
$showId = $r->fetchColumn(0);
|
||||
|
||||
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$startDate} {$startTime}')";
|
||||
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$data['start_date']} {$data['start_time']}')";
|
||||
$r = $con->query($sql);
|
||||
$startDow = $r->fetchColumn(0);
|
||||
$startDow = $r->fetchColumn(0);
|
||||
|
||||
foreach ($days as $day) {
|
||||
if($data['no_end']) {
|
||||
$endDate = NULL;
|
||||
}
|
||||
else if($data['repeats']) {
|
||||
$endDate = $data['end_date'];
|
||||
}
|
||||
else {
|
||||
$endDate = $data['start_date'];
|
||||
}
|
||||
|
||||
if($data['day_check'] === null) {
|
||||
$data['day_check'] = array($startDow);
|
||||
}
|
||||
|
||||
foreach ($data['day_check'] as $day) {
|
||||
|
||||
if($startDow !== $day){
|
||||
|
||||
|
@ -60,23 +74,23 @@ class Show {
|
|||
else
|
||||
$daysAdd = $day - $startDow;
|
||||
|
||||
$sql = "SELECT date '{$startDate}' + INTERVAL '{$daysAdd} day' ";
|
||||
$sql = "SELECT date '{$data['start_date']}' + INTERVAL '{$daysAdd} day' ";
|
||||
$r = $con->query($sql);
|
||||
$start = $r->fetchColumn(0);
|
||||
}
|
||||
else {
|
||||
$start = $startDate;
|
||||
$start = $data['start_date'];
|
||||
}
|
||||
|
||||
$show = new CcShow();
|
||||
$show->setDbName($name);
|
||||
$show->setDbName($data['name']);
|
||||
$show->setDbFirstShow($start);
|
||||
$show->setDbLastShow($endDate);
|
||||
$show->setDbStartTime($startTime);
|
||||
$show->setDbStartTime($data['start_time']);
|
||||
$show->setDbEndTime($endTime);
|
||||
$show->setDbRepeats($repeats);
|
||||
$show->setDbRepeats($data['repeats']);
|
||||
$show->setDbDay($day);
|
||||
$show->setDbDescription($description);
|
||||
$show->setDbDescription($data['description']);
|
||||
$show->setDbShowId($showId);
|
||||
$show->save();
|
||||
}
|
||||
|
|
|
@ -13,3 +13,7 @@
|
|||
),
|
||||
'default',
|
||||
true) ?>"> Edit Playlist</a></div>
|
||||
|
||||
<?php
|
||||
|
||||
echo $this->form;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
<br /><br /><center>View script for controller <b>Schedule</b> and script/action name <b>addShow</b></center>
|
Loading…
Add table
Add a link
Reference in a new issue