added monthly show option, bit more javascript to show/hide info when not needed in add show tabs.

This commit is contained in:
Naomi 2011-02-08 18:22:51 -05:00
parent bdad3b34e0
commit 3d3515812a
8 changed files with 118 additions and 57 deletions

View File

@ -1,6 +1,6 @@
<?php
// This file generated by Propel 1.5.2 convert-conf target
// from XML runtime conf file /home/naomiaro/dev-campcaster/campcaster/build/runtime-conf.xml
// from XML runtime conf file /home/naomi/dev-campcaster/campcaster/build/runtime-conf.xml
$conf = array (
'datasources' =>
array (

View File

@ -5,6 +5,17 @@ class Application_Form_AddShowRepeats extends Zend_Form_SubForm
public function init()
{
//Add type select
$this->addElement('select', 'add_show_repeat_type', array(
'required' => true,
'label' => 'Repeat Type:',
'multiOptions' => array(
"0" => "weekly",
"1" => "bi-weekly",
"2" => "monthly"
),
));
// Add days checkboxes
$this->addElement(
'multiCheckbox',
@ -29,16 +40,6 @@ class Application_Form_AddShowRepeats extends Zend_Form_SubForm
'viewScript' => 'form/add-show-checkbox.phtml'
))));
//Add type select
$this->addElement('select', 'add_show_repeat_type', array(
'required' => true,
'label' => 'Repeat Type:',
'multiOptions' => array(
"0" => "weekly",
"1" => "bi-weekly"
),
));
// Add end date element
$this->addElement('text', 'add_show_end_date', array(
'label' => 'Date End:',

View File

@ -71,37 +71,52 @@ class Show {
$showId = $show->getDbId();
foreach ($data['add_show_day_check'] as $day) {
//don't set day for monthly repeat type, it's invalid.
if($data['add_show_repeats'] && $data["add_show_repeat_type"] == 2) {
$showDay = new CcShowDays();
$showDay->setDbFirstShow($data['add_show_start_date']);
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbRepeatType($repeat_type);
$showDay->setDbShowId($showId);
$showDay->save();
}
else {
if($startDow !== $day){
foreach ($data['add_show_day_check'] as $day) {
if($startDow !== $day){
if($startDow > $day)
$daysAdd = 6 - $startDow + 1 + $day;
else
$daysAdd = $day - $startDow;
if($startDow > $day)
$daysAdd = 6 - $startDow + 1 + $day;
else
$daysAdd = $day - $startDow;
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '{$daysAdd} day' ";
$r = $con->query($sql);
$start = $r->fetchColumn(0);
}
else {
$start = $data['add_show_start_date'];
}
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '{$daysAdd} day' ";
$r = $con->query($sql);
$start = $r->fetchColumn(0);
}
else {
$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);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbDay($day);
$showDay->setDbRepeatType($repeat_type);
$showDay->setDbShowId($showId);
$showDay->save();
}
}
$showDay = new CcShowDays();
$showDay->setDbFirstShow($start);
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbDay($day);
$showDay->setDbRepeatType($repeat_type);
$showDay->setDbShowId($showId);
$showDay->save();
}
}
}
//add selected hosts to cc_show_hosts table.
foreach ($data['add_show_hosts'] as $host) {
$showHost = new CcShowHosts();
$showHost->setDbShow($showId);
@ -158,6 +173,19 @@ class Show {
}
}
private static function setNextPop($next_date, $show_id, $day) {
$nextInfo = explode(" ", $next_date);
$repeatInfo = CcShowDaysQuery::create()
->filterByDbShowId($show_id)
->filterByDbDay($day)
->findOne();
$repeatInfo->setDbNextPopDate($nextInfo[0])
->save();
}
//for a show with repeat_type == 0
private static function populateWeeklyShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp) {
global $CC_DBC;
@ -186,15 +214,7 @@ class Show {
$next_date = $CC_DBC->GetOne($sql);
}
$nextInfo = explode(" ", $next_date);
$repeatInfo = CcShowDaysQuery::create()
->filterByDbShowId($show_id)
->filterByDbDay($day)
->findOne();
$repeatInfo->setDbNextPopDate($nextInfo[0])
->save();
Show::setNextPop($next_date, $show_id, $day);
}
//for a show with repeat_type == 1
@ -225,15 +245,38 @@ class Show {
$next_date = $CC_DBC->GetOne($sql);
}
$nextInfo = explode(" ", $next_date);
Show::setNextPop($next_date, $show_id, $day);
}
$repeatInfo = CcShowDaysQuery::create()
->filterByDbShowId($show_id)
->filterByDbDay($day)
->findOne();
//for a show with repeat_type == 2
private static function populateMonthlyShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp) {
global $CC_DBC;
$repeatInfo->setDbNextPopDate($nextInfo[0])
->save();
if(isset($next_pop_date)) {
$next_date = $next_pop_date." ".$start_time;
}
else {
$next_date = $first_show." ".$start_time;
}
while(strtotime($next_date) < strtotime($end_timestamp) && (strtotime($last_show) > strtotime($next_date) || is_null($last_show))) {
$start = $next_date;
$sql = "SELECT timestamp '{$start}' + interval '{$duration}'";
$end = $CC_DBC->GetOne($sql);
$newShow = new CcShowInstances();
$newShow->setDbShowId($show_id);
$newShow->setDbStarts($start);
$newShow->setDbEnds($end);
$newShow->save();
$sql = "SELECT timestamp '{$start}' + interval '1 month'";
$next_date = $CC_DBC->GetOne($sql);
}
Show::setNextPop($next_date, $show_id, $day);
}
private static function populateShow($repeat_type, $show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp) {
@ -247,6 +290,9 @@ class Show {
else if($repeat_type == 1) {
Show::populateBiWeeklyShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp);
}
else if($repeat_type == 2) {
Show::populateMonthlyShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $end_timestamp);
}
}
//used to catch up a newly added show
@ -459,7 +505,7 @@ class ShowInstance {
$scheduledContentFits = $CC_DBC->GetOne($sql);
if($scheduledContentFits != "t") {
return "Must removed some scheduled content.";
return "Must remove some scheduled content.";
}
}

View File

@ -43,7 +43,7 @@ class CcShowDaysTableMap extends TableMap {
$this->addColumn('LAST_SHOW', 'DbLastShow', 'DATE', false, null, null);
$this->addColumn('START_TIME', 'DbStartTime', 'TIME', true, null, null);
$this->addColumn('DURATION', 'DbDuration', 'TIME', true, null, null);
$this->addColumn('DAY', 'DbDay', 'TINYINT', true, null, null);
$this->addColumn('DAY', 'DbDay', 'TINYINT', false, null, null);
$this->addColumn('REPEAT_TYPE', 'DbRepeatType', 'TINYINT', true, null, null);
$this->addColumn('NEXT_POP_DATE', 'DbNextPopDate', 'DATE', false, null, null);
$this->addForeignKey('SHOW_ID', 'DbShowId', 'INTEGER', 'cc_show', 'ID', true, null, null);

View File

@ -1,6 +1,6 @@
#Note: project.home is automatically generated by the propel-install script.
#Any manual changes to this value will be overwritten.
project.home = /home/naomiaro/dev-campcaster/campcaster
project.home = /home/naomi/dev-campcaster/campcaster
project.build = ${project.home}/build
#Database driver

View File

@ -143,7 +143,7 @@
<column name="last_show" phpName="DbLastShow" type="DATE" required="false"/>
<column name="start_time" phpName="DbStartTime" type="TIME" required="true"/>
<column name="duration" phpName="DbDuration" type="TIME" required="true"/>
<column name="day" phpName="DbDay" type="TINYINT" required="true"/>
<column name="day" phpName="DbDay" type="TINYINT" required="false"/>
<column name="repeat_type" phpName="DbRepeatType" type="TINYINT" required="true"/>
<column name="next_pop_date" phpName="DbNextPopDate" type="DATE" required="false"/>
<column name="show_id" phpName="DbShowId" type="INTEGER" required="true"/>

View File

@ -206,7 +206,7 @@ CREATE TABLE "cc_show_days"
"last_show" DATE,
"start_time" TIME NOT NULL,
"duration" TIME NOT NULL,
"day" INT2 NOT NULL,
"day" INT2,
"repeat_type" INT2 NOT NULL,
"next_pop_date" DATE,
"show_id" INTEGER NOT NULL,

View File

@ -70,6 +70,20 @@ function setAddShowEvents() {
$("#schedule-show-when > fieldset:last").toggle();
});
$("#add_show_repeat_type").change(function(){
var x = $(this).val();
if($(this).val() == 2) {
$("#add_show_day_check-label, #add_show_day_check-element").hide();
}
else {
$("#add_show_day_check-label, #add_show_day_check-element").show();
}
});
$("#add_show_no_end").click(function(){
$("#add_show_end_date").toggle();
});
start = $("#add_show_start_date");
end = $("#add_show_end_date");