CC-3174 : showbuilder

adding a showbuilder form, can filter by show,
or if you're a host user by all shows you can schedule in a range.
This commit is contained in:
Naomi Aro 2012-02-15 00:39:27 +01:00
parent eba84ee878
commit b1fbeeb448
14 changed files with 207 additions and 237 deletions

View file

@ -37,6 +37,8 @@ class LibraryController extends Zend_Controller_Action
{
global $CC_CONFIG;
$this->_helper->viewRenderer->setResponseSegment('library');
$request = $this->getRequest();
$baseUrl = $request->getBaseUrl();
@ -56,16 +58,6 @@ class LibraryController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet($baseUrl.'/css/datatables/css/ColVis.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'/css/datatables/css/ColReorder.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'/css/TableTools.css?'.$CC_CONFIG['airtime_version']);
$this->_helper->viewRenderer->setResponseSegment('library');
$form = new Application_Form_AdvancedSearch();
$form->addGroup(1, 1);
$this->search_sess->next_group = 2;
$this->search_sess->next_row[1] = 2;
$this->view->form = $form;
$this->view->md = $this->search_sess->md;
}
public function contextMenuAction()

View file

@ -204,15 +204,11 @@ class ScheduleController extends Zend_Controller_Action
&& !$instance->isRecorded()
&& !$instance->isRebroadcast()) {
$menu["schedule"] = array("name"=> "Add / Remove Content", "url" => "/showbuilder/index/");
$menu["schedule"] = array("name"=> "Add / Remove Content",
"url" => "/showbuilder/index/");
$menu["clear"] = array("name"=> "Remove All Content", "icon" => "delete", "url" => "/schedule/clear-show");
/*
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/clear-show'.$params,
'callback' => 'window["scheduleRefetchEvents"]'), 'title' => 'Remove All Content');
*/
$menu["clear"] = array("name"=> "Remove All Content", "icon" => "delete",
"url" => "/schedule/clear-show");
}
}

View file

@ -25,6 +25,8 @@ class ShowbuilderController extends Zend_Controller_Action
public function builderAction() {
$this->_helper->viewRenderer->setResponseSegment('builder');
$request = $this->getRequest();
$baseUrl = $request->getBaseUrl();
@ -37,10 +39,15 @@ class ShowbuilderController extends Zend_Controller_Action
$end = DateTime::createFromFormat("U", $to, new DateTimeZone("UTC"));
$end->setTimezone(new DateTimeZone(date_default_timezone_get()));
$this->view->start_date = $start->format("Y-m-d");
$this->view->start_time = $start->format("H:i");
$this->view->end_date = $end->format("Y-m-d");
$this->view->end_time = $end->format("H:i");
$form = new Application_Form_ShowBuilder();
$form->populate(array(
'sb_date_start' => $start->format("Y-m-d"),
'sb_time_start' => $start->format("H:i"),
'sb_date_end' => $end->format("Y-m-d"),
'sb_time_end' => $end->format("H:i")
));
$this->view->sb_form = $form;
$this->view->headScript()->appendScript("var serverTimezoneOffset = ".date("Z")."; //in seconds");
$this->view->headScript()->appendFile($baseUrl.'/js/timepicker/jquery.ui.timepicker.js','text/javascript');
@ -48,8 +55,6 @@ class ShowbuilderController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet($baseUrl.'/css/jquery.ui.timepicker.css');
$this->view->headLink()->appendStylesheet($baseUrl.'/css/showbuilder.css');
$this->_helper->viewRenderer->setResponseSegment('builder');
}
public function builderFeedAction() {
@ -60,6 +65,8 @@ class ShowbuilderController extends Zend_Controller_Action
$starts_epoch = $request->getParam("start", $current_time);
//default ends is 24 hours after starts.
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
$show_filter = intval($request->getParam("showFilter", 0));
$my_shows = intval($request->getParam("myShows", 0));
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
@ -67,7 +74,8 @@ class ShowbuilderController extends Zend_Controller_Action
Logging::log("showbuilder starts {$startsDT->format("Y-m-d H:i:s")}");
Logging::log("showbuilder ends {$endsDT->format("Y-m-d H:i:s")}");
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT);
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
$this->view->schedule = $showBuilder->GetItems();
}

View file

@ -1,65 +0,0 @@
<?php
class Application_Form_AdvancedSearch extends Zend_Form
{
public function init()
{
// Add the add button
$this->addElement('button', 'search_add_group', array(
'ignore' => true,
'label' => 'Add',
'order' => '-2'
));
$this->getElement('search_add_group')->removeDecorator('DtDdWrapper');
// Add the submit button
$this->addElement('button', 'search_submit', array(
'ignore' => true,
'label' => 'Save',
'order' => '-1'
));
$this->getElement('search_submit')->removeDecorator('DtDdWrapper');
}
public function addGroup($group_id, $row_id=null) {
$this->addSubForm(new Application_Form_AdvancedSearchGroup(), 'group_'.$group_id, $group_id);
$this->getSubForm('group_'.$group_id)->removeDecorator('DtDdWrapper');
if(!is_null($row_id)) {
$subGroup = $this->getSubForm('group_'.$group_id);
$subGroup->addRow($row_id);
}
}
public function preValidation(array $data) {
function findId($name) {
$t = explode("_", $name);
return $t[1];
}
function findFields($field) {
return strpos($field, 'group') !== false;
}
$groups = array_filter(array_keys($data), 'findFields');
foreach ($groups as $group) {
$group_id = findId($group);
$this->addGroup($group_id);
$subGroup = $this->getSubForm($group);
foreach (array_keys($data[$group]) as $row) {
$row_id = findId($row);
$subGroup->addRow($row_id, $data[$group][$row]);
}
}
}
}

View file

@ -1,37 +0,0 @@
<?php
class Application_Form_AdvancedSearchGroup extends Zend_Form_SubForm
{
public function init()
{
// Add the add button
$this->addElement('button', 'search_add_row', array(
'ignore' => true,
'label' => 'Add',
'order' => '-2'
));
$this->getElement('search_add_row')->removeDecorator('DtDdWrapper');
// Add the add button
$this->addElement('button', 'search_remove_group', array(
'ignore' => true,
'label' => 'Remove',
'order' => '-1'
));
$this->getElement('search_remove_group')->removeDecorator('DtDdWrapper');
}
public function addRow($row_id, $data=null) {
$this->addSubForm(new Application_Form_AdvancedSearchRow(), 'row_'.$row_id, $row_id);
$row = $this->getSubForm('row_'.$row_id);
$row->removeDecorator('DtDdWrapper');
if(!is_null($data)) {
$row->setDefaults($data);
}
}
}

View file

@ -1,70 +0,0 @@
<?php
class Application_Form_AdvancedSearchRow extends Zend_Form_SubForm
{
public function init()
{
$this->addElement(
'select',
'metadata',
array(
'required' => true,
'multiOptions' => array(
"dc:title" => "Title",
"dc:format" => "Format",
"dc:creator" => "Artist/Creator",
"dc:source" => "Album",
"ls:bitrate" => "Bitrate",
"ls:samplerate" => "Samplerate",
"dcterms:extent" => "Length",
"dc:description" => "Comments",
"dc:type" => "Genre",
"ls:channels" => "channels",
"ls:year" => "Year",
"ls:track_num" => "track_number",
"ls:mood" => "mood",
"ls:bpm" => "BPM",
"ls:rating" => "rating",
"ls:encoded_by" => "encoded_by",
"dc:publisher" => "label",
"ls:composer" => "Composer",
"ls:encoder" => "Encoder",
"ls:lyrics" => "lyrics",
"ls:orchestra" => "orchestra",
"ls:conductor" => "conductor",
"ls:lyricist" => "lyricist",
"ls:originallyricist" => "original_lyricist",
"ls:isrcnumber" => "isrc_number",
"dc:language" => "Language",
),
)
);
$this->getElement('metadata')->removeDecorator('Label')->removeDecorator('HtmlTag');
$this->addElement(
'select',
'match',
array(
'required' => true,
'multiOptions' => array(
"0" => "partial",
"1" => "=",
"2" => "<",
"3" => "<=",
"4" => ">",
"5" => ">=",
"6" => "!=",
),
)
);
$this->getElement('match')->removeDecorator('Label')->removeDecorator('HtmlTag');
$this->addElement('text', 'search', array(
'required' => true,
));
$this->getElement('search')->removeDecorator('Label')->removeDecorator('HtmlTag');
}
}

View file

@ -0,0 +1,104 @@
<?php
class Application_Form_ShowBuilder extends Zend_Form_SubForm
{
public function init()
{
$user = Application_Model_User::GetCurrentUser();
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/showbuilder.phtml'))
));
// Add start date element
$startDate = new Zend_Form_Element_Text('sb_date_start');
$startDate->class = 'input_text';
$startDate->setRequired(true)
->setLabel('Date Start:')
->setValue(date("Y-m-d"))
->setFilters(array('StringTrim'))
->setValidators(array(
'NotEmpty',
array('date', false, array('YYYY-MM-DD'))))
->setDecorators(array('ViewHelper'));
$startDate->setAttrib('alt', 'date');
$this->addElement($startDate);
// Add start time element
$startTime = new Zend_Form_Element_Text('sb_time_start');
$startTime->class = 'input_text';
$startTime->setRequired(true)
->setValue('00:00')
->setFilters(array('StringTrim'))
->setValidators(array(
'NotEmpty',
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))))
->setDecorators(array('ViewHelper'));
$startTime->setAttrib('alt', 'time');
$this->addElement($startTime);
// Add end date element
$endDate = new Zend_Form_Element_Text('sb_date_end');
$endDate->class = 'input_text';
$endDate->setRequired(true)
->setLabel('Date End:')
->setValue(date("Y-m-d"))
->setFilters(array('StringTrim'))
->setValidators(array(
'NotEmpty',
array('date', false, array('YYYY-MM-DD'))))
->setDecorators(array('ViewHelper'));
$endDate->setAttrib('alt', 'date');
$this->addElement($endDate);
// Add end time element
$endTime = new Zend_Form_Element_Text('sb_time_end');
$endTime->class = 'input_text';
$endTime->setRequired(true)
->setValue('01:00')
->setFilters(array('StringTrim'))
->setValidators(array(
'NotEmpty',
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))))
->setDecorators(array('ViewHelper'));
$endTime->setAttrib('alt', 'time');
$this->addElement($endTime);
// add a select to choose a show.
$showSelect = new Zend_Form_Element_Select("sb_show_filter");
$showSelect->setLabel("Filter By Show:");
$showSelect->setMultiOptions($this->getShowNames());
$showSelect->setValue(null);
$showSelect->setDecorators(array('ViewHelper'));
$this->addElement($showSelect);
if ($user->getType() === 'H') {
$myShows = new Zend_Form_Element_Checkbox('sb_my_shows');
$myShows->setLabel('All My Shows')
->setDecorators(array('ViewHelper'));
$this->addElement($myShows);
}
}
private function getShowNames() {
$showNames = array("0" => "-------------------------");
$shows = CcShowQuery::create()
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
->orderByDbName()
->find();
foreach ($shows as $show) {
$showNames[$show->getDbId()] = $show->getDbName();
}
return $showNames;
}
}

View file

@ -303,7 +303,7 @@ class Application_Model_Schedule {
* @return array $scheduledItems
*
*/
public static function GetScheduleDetailItems($p_startDateTime, $p_endDateTime)
public static function GetScheduleDetailItems($p_startDateTime, $p_endDateTime, $p_shows)
{
global $CC_CONFIG, $CC_DBC;
@ -328,9 +328,13 @@ class Application_Model_Schedule {
WHERE si.modified_instance = false AND
si.starts >= '{$p_startDateTime}' AND si.starts < '{$p_endDateTime}'
si.starts >= '{$p_startDateTime}' AND si.starts < '{$p_endDateTime}'";
ORDER BY si.starts, sched.starts;";
if (count($p_shows) > 0) {
$sql .= " AND show_id IN (".implode(",", $p_shows).")";
}
$sql .= " ORDER BY si.starts, sched.starts;";
Logging::log($sql);

View file

@ -6,6 +6,7 @@ class Application_Model_ShowBuilder {
private $startDT;
private $endDT;
private $user;
private $opts;
private $contentDT;
@ -28,12 +29,13 @@ class Application_Model_ShowBuilder {
* @param DateTime $p_startsDT
* @param DateTime $p_endsDT
*/
public function __construct($p_startDT, $p_endDT) {
public function __construct($p_startDT, $p_endDT, $p_opts) {
$this->startDT = $p_startDT;
$this->endDT = $p_endDT;
$this->timezone = date_default_timezone_get();
$this->user = Application_Model_User::GetCurrentUser();
$this->opts = $p_opts;
}
/*
@ -165,7 +167,23 @@ class Application_Model_ShowBuilder {
$current_id = -1;
$display_items = array();
$scheduled_items = Application_Model_Schedule::GetScheduleDetailItems($this->startDT->format("Y-m-d H:i:s"), $this->endDT->format("Y-m-d H:i:s"));
$shows = array();
if ($this->opts["myShows"] === 1) {
$host_shows = CcShowHostsQuery::create()
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
->filterByDbHost($this->user->getId())
->find();
foreach ($host_shows as $host_show) {
$shows[] = $host_show->getDbShow();
}
}
else if ($this->opts["showFilter"] !== 0) {
$shows[] = $this->opts["showFilter"];
}
$scheduled_items = Application_Model_Schedule::GetScheduleDetailItems($this->startDT->format("Y-m-d H:i:s"), $this->endDT->format("Y-m-d H:i:s"), $shows);
for ($i = 0, $rows = count($scheduled_items); $i < $rows; $i++) {

View file

@ -0,0 +1,16 @@
<div class="sb-timerange">
<?php echo $this->element->getElement('sb_date_start') ?>
<?php echo $this->element->getElement('sb_time_start') ?>
<?php echo $this->element->getElement('sb_date_end') ?>
<?php echo $this->element->getElement('sb_time_end') ?>
<input type="button" id="sb_submit" class="ui-button ui-state-default" value="GO"></input>
</div>
<div class="sb-advanced-options">
<label><?php echo $this->element->getElement('sb_show_filter')->getLabel() ?></label>
<?php echo $this->element->getElement('sb_show_filter') ?>
<?php if ($this->element->getElement('sb_my_shows')):?>
<label><?php echo $this->element->getElement('sb_my_shows')->getLabel(); ?></label>
<?php echo $this->element->getElement('sb_my_shows'); ?>
<?php endif;?>
</div>

View file

@ -3,7 +3,5 @@
</ul>
<div id="simpleSearch">
<div id="import_status" style="visibility:hidden">File import in progress...</div>
<table id="library_display" cellpadding="0" cellspacing="0" class="datatable">
</table>
<table id="library_display" cellpadding="0" cellspacing="0" class="datatable"></table>
</div>

View file

@ -1,6 +1,2 @@
<input type="text" id="show_builder_datepicker_start" class="input_text" value="<?php echo $this->start_date?>"></input>
<input type="text" id="show_builder_timepicker_start" class="input_text" value="<?php echo $this->start_time?>"></input>
<input type="text" id="show_builder_datepicker_end" class="input_text" value="<?php echo $this->end_date?>"></input>
<input type="text" id="show_builder_timepicker_end" class="input_text" value="<?php echo $this->end_time?>"></input>
<input type="button" id="show_builder_timerange_button" class="ui-button ui-state-default" value="GO"></input>
<?php echo $this->sb_form; ?>
<table id="show_builder_table" cellpadding="0" cellspacing="0" class="datatable"></table>

View file

@ -1,5 +1,5 @@
@CHARSET "UTF-8";
#show_builder > input.input_text {
#show_builder input.input_text {
width:100px;
}

View file

@ -37,7 +37,7 @@ $(document).ready(function() {
*
* @return Number iTime
*/
function fnGetUIPickerUnixTimestamp(sDatePickerId, sTimePickerId) {
function fnGetTimestamp(sDatePickerId, sTimePickerId) {
var date,
time,
iTime,
@ -48,8 +48,6 @@ $(document).ready(function() {
return 0;
}
//string.split(separator, limit)
date = $(sDatePickerId).val();
time = $(sTimePickerId).val();
@ -64,7 +62,7 @@ $(document).ready(function() {
iServerOffset = serverTimezoneOffset;
iClientOffset = oDate.getTimezoneOffset() * 60;//function returns minutes
//adjust for the fact the the Date object is
//adjust for the fact the the Date object is in clent time.
iTime = iTime + iServerOffset + iClientOffset;
return iTime;
@ -80,8 +78,8 @@ $(document).ready(function() {
iRange,
DEFAULT_RANGE = 60*60*24;
iStart = fnGetUIPickerUnixTimestamp("#show_builder_datepicker_start", "#show_builder_timepicker_start");
iEnd = fnGetUIPickerUnixTimestamp("#show_builder_datepicker_end", "#show_builder_timepicker_end");
iStart = fnGetTimestamp("#sb_date_start", "#sb_time_start");
iEnd = fnGetTimestamp("#sb_date_end", "#sb_time_end");
iRange = iEnd - iStart;
@ -106,6 +104,10 @@ $(document).ready(function() {
if (fnServerData.hasOwnProperty("end")) {
aoData.push( { name: "end", value: fnServerData.end} );
}
if (fnServerData.hasOwnProperty("ops")) {
aoData.push( { name: "myShows", value: fnServerData.ops.myShows} );
aoData.push( { name: "showFilter", value: fnServerData.ops.showFilter} );
}
$.ajax( {
"dataType": "json",
@ -308,23 +310,31 @@ $(document).ready(function() {
}
});
$( "#show_builder_datepicker_start" ).datepicker(oBaseDatePickerSettings);
$("#sb_date_start").datepicker(oBaseDatePickerSettings);
$("#sb_time_start").timepicker(oBaseTimePickerSettings);
$("#sb_date_end").datepicker(oBaseDatePickerSettings);
$("#sb_time_end").timepicker(oBaseTimePickerSettings);
$( "#show_builder_timepicker_start" ).timepicker(oBaseTimePickerSettings);
$( "#show_builder_datepicker_end" ).datepicker(oBaseDatePickerSettings);
$( "#show_builder_timepicker_end" ).timepicker(oBaseTimePickerSettings);
$( "#show_builder_timerange_button" ).click(function(ev){
var oSettings,
oRange;
$("#sb_submit").click(function(ev){
var fn,
oRange,
op;
oRange = fnGetScheduleRange();
oSettings = oTable.fnSettings();
oSettings.fnServerData.start = oRange.start;
oSettings.fnServerData.end = oRange.end;
fn = oTable.fnSettings().fnServerData;
fn.start = oRange.start;
fn.end = oRange.end;
op = $("div.sb-advanced-options");
if (op.is(":visible")) {
if (fn.ops === undefined) {
fn.ops = {};
}
fn.ops.showFilter = op.find("#sb_show_filter").val();
fn.ops.myShows = op.find("#sb_my_shows").is(":checked") ? 1 : 0;
}
oTable.fnDraw();
});