Merge branch 'saas-dev-usability-hints' into saas-dev

This commit is contained in:
drigato 2015-07-16 11:00:04 -04:00
commit dd5d6342a7
20 changed files with 396 additions and 25 deletions

View file

@ -30,6 +30,7 @@ require_once "Timezone.php";
require_once "Auth.php";
require_once "interface/OAuth2.php";
require_once "TaskManager.php";
require_once "UsabilityHints.php";
require_once __DIR__.'/services/CeleryService.php';
require_once __DIR__.'/services/SoundcloudService.php';
require_once __DIR__.'/forms/helpers/ValidationTypes.php';

View file

@ -0,0 +1,184 @@
<?php
class Application_Common_UsabilityHints
{
/**
* @param $userPath User's current location in Airtime (i.e. /Plupload)
* @return string
*/
public static function getUsabilityHint($userPath=null)
{
// We want to display hints in this order:
// 1. Check if files are uploaded
// 2. Check if a show is scheduled
// 3. Check if current or next show needs content
// Once the user is on the page linked to from the hint we want to
// display a new message further describing what to do. Once this
// action has been done we can hide the message and get the next
// usability hint, if there is one.
$userIsOnCalendarPage = false;
$userIsOnAddMediaPage = false;
// If $userPath is set the request came from AJAX so the user's
// current location inside Airtime gets passed in to this function.
if (!is_null($userPath)) {
// We check if the controller names are in the user's current location
// so we can ignore leading or trailing slashes, special characters like '#',
// and additional controller action names like '/user/add-user'
if (strpos(strtolower($userPath), 'plupload') !== false) {
$userIsOnAddMediaPage = true;
}
if (strpos(strtolower($userPath), 'schedule') !== false) {
$userIsOnCalendarPage = true;
}
} else {
// If $userPath is not set the request came from inside Airtime so
// we can use Zend's Front Controller to get the user's current location.
$currentController = strtolower(Zend_Controller_Front::getInstance()->getRequest()->getControllerName());
if ($currentController == "schedule") {
$userIsOnCalendarPage = true;
}
if ($currentController == "plupload") {
$userIsOnAddMediaPage = true;
}
}
if (self::zeroFilesUploaded()) {
if ($userIsOnAddMediaPage) {
return _("Click the 'Add files' button and select files from your computer to upload.");
} else {
return sprintf(_("It looks like you have not uploaded any audio files yet. %sUpload a file now.%s "),
"<a href=\"/plupload\">",
"</a>");
}
} else if (!self::isFutureOrCurrentShowScheduled()) {
if ($userIsOnCalendarPage) {
return _("Click the 'Create New Show' button and fill out the required fields.");
} else {
return sprintf(_("It looks like you don't have any shows scheduled. %sCreate a show now.%s"),
"<a href=\"/schedule\">",
"</a>");
}
} else if (self::isCurrentShowEmpty()) {
if ($userIsOnCalendarPage) {
return _("To start broadcasting, click on the current show and select 'Add / Remove Content'");
} else {
return sprintf(_("It looks like the current show needs more tracks. %sAdd tracks to your show now.%s"),
"<a href=\"/schedule\">",
"</a>");
}
} else if (!self::getCurrentShow() && self::isNextShowEmpty()) {
if ($userIsOnCalendarPage) {
return _("Click on the show starting next and select 'Add / Remove Content'");
} else {
return sprintf(_("It looks like the next show is empty. %sAdd tracks to your show now.%s"),
"<a href=\"/schedule\">",
"</a>");
}
} else {
return "";
}
}
/**
* Returns true if no files have been uploaded.
*/
private static function zeroFilesUploaded()
{
$fileCount = CcFilesQuery::create()
->filterByDbFileExists(true)
->filterByDbHidden(false)
->count();
if ($fileCount == 0) {
return true;
} else {
return false;
}
}
/**
* Returns true if there is at least one show currently scheduled
* or in the future.
*/
private static function isFutureOrCurrentShowScheduled()
{
$futureShow = self::getNextFutureShow();
$currentShow = self::getCurrentShow();
if (is_null($futureShow) && is_null($currentShow)) {
return false;
} else {
return true;
}
}
private static function isCurrentShowEmpty()
{
$currentShow = self::getCurrentShow();
if (is_null($currentShow)) {
return false;
} else {
$now = new DateTime("now", new DateTimeZone("UTC"));
$scheduledTracks = CcScheduleQuery::create()
->filterByDbInstanceId($currentShow->getDbId())
->filterByDbEnds($now, Criteria::GREATER_EQUAL)
->find();
if ($scheduledTracks->count() == 0) {
return true;
} else {
return false;
}
}
}
private static function isNextShowEmpty()
{
$futureShow = self::getNextFutureShow();
if (is_null($futureShow)) {
return false;
} else {
$now = new DateTime("now", new DateTimeZone("UTC"));
$scheduledTracks = CcScheduleQuery::create()
->filterByDbInstanceId($futureShow->getDbId())
->filterByDbStarts($now, Criteria::GREATER_EQUAL)
->find();
if ($scheduledTracks->count() == 0) {
return true;
} else {
return false;
}
}
}
private static function getCurrentShow()
{
$now = new DateTime("now", new DateTimeZone("UTC"));
return CcShowInstancesQuery::create()
->filterByDbStarts($now, Criteria::LESS_THAN)
->filterByDbEnds($now, Criteria::GREATER_THAN)
->filterByDbModifiedInstance(false)
->findOne();
}
private static function getNextFutureShow()
{
$now = new DateTime("now", new DateTimeZone("UTC"));
return CcShowInstancesQuery::create()
->filterByDbStarts($now, Criteria::GREATER_THAN)
->filterByDbModifiedInstance(false)
->orderByDbStarts()
->findOne();
}
}

View file

@ -64,6 +64,7 @@ class ApiController extends Zend_Controller_Action
->addActionContext('update-stream-setting-table' , 'json')
->addActionContext('update-replay-gain-value' , 'json')
->addActionContext('update-cue-values-by-silan' , 'json')
->addActionContext('get-usability-hint' , 'json')
->initContext();
}
@ -1466,5 +1467,13 @@ class ApiController extends Zend_Controller_Action
}
$this->_helper->json->sendJson(array(1));
}
public function getUsabilityHintAction()
{
$userPath = $this->_getParam("userPath");
$hint = Application_Common_UsabilityHints::getUsabilityHint($userPath);
$this->_helper->json->sendJson($hint);
}
}

View file

@ -98,6 +98,9 @@ class ScheduleController extends Zend_Controller_Action
$this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.columnFilter.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/libs/moment.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/libs/moment-timezone-with-data-2010-2020.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/library/events/library_showbuilder.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/library/library.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
@ -584,7 +587,20 @@ class ScheduleController extends Zend_Controller_Action
$forms = $this->createShowFormAction();
$this->view->addNewShow = true;
if ($data['add_show_start_now'] == "now") {
//have to use the timezone the user has entered in the form to check past/present
$showTimezone = new DateTimeZone($data["add_show_timezone"]);
$nowDateTime = new DateTime("now", $showTimezone);
//$showStartDateTime = new DateTime($start_time, $showTimezone);
//$showEndDateTime = new DateTime($end_time, $showTimezone);
$data['add_show_start_time'] = $nowDateTime->format("H:i");
$data['add_show_start_date'] = $nowDateTime->format("Y-m-d");
}
if ($service_showForm->validateShowForms($forms, $data)) {
// Get the show ID from the show service to pass as a parameter to the RESTful ShowImageController
$this->view->showId = $service_show->addUpdateShow($data);

View file

@ -15,11 +15,26 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
"/^[0-2]?[0-9]:[0-5][0-9]$/",
_("'%value%' does not fit the time format 'HH:mm'"));
// Add start date element
$startNow = new Zend_Form_Element_Radio('add_show_start_now');
$startNow->setRequired(false)
->setLabel(_('Start Time:'))
->addMultiOptions(array(
'now' => 'Now',
'future' => 'In the Future:'
))
->setValue('future')
->setDecorators(array('ViewHelper'));
//$startDate->setAttrib('alt', 'date');
$this->addElement($startNow);
// Add start date element
$startDate = new Zend_Form_Element_Text('add_show_start_date');
$startDate->class = 'input_text';
$startDate->setRequired(true)
->setLabel(_('Date/Time Start:'))
->setLabel(_('In the Future:'))
->setValue(date("Y-m-d"))
->setFilters(array('StringTrim'))
->setValidators(array(
@ -46,7 +61,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
$endDate = new Zend_Form_Element_Text('add_show_end_date_no_repeat');
$endDate->class = 'input_text';
$endDate->setRequired(true)
->setLabel(_('Date/Time End:'))
->setLabel(_('End Time:'))
->setValue(date("Y-m-d"))
->setFilters(array('StringTrim'))
->setValidators(array(
@ -119,7 +134,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
$showStartDateTime = new DateTime($start_time, $showTimezone);
$showEndDateTime = new DateTime($end_time, $showTimezone);
if ($validateStartDate) {
if ($validateStartDate && ($formData['add_show_start_now'] != "now")) {
if ($showStartDateTime < $nowDateTime) {
$this->getElement('add_show_start_time')->setErrors(array(_('Cannot create show in the past')));
$valid = false;

View file

@ -70,7 +70,13 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
</div>
<div class="wrapper" id="content"><?php echo $this->layout()->content ?></div>
<div class="wrapper" id="content">
<?php
$hint = Application_Common_UsabilityHints::getUsabilityHint(); ?>
<div class="usability_hint" <?php if ($hint == "") { echo "style='display:none'"; } ?>><?php echo $hint; ?></div>
<?php echo $this->layout()->content ?></div>
<script id="tmpl-pl-cues" type="text/template">
<div class="waveform-cues">

View file

@ -169,6 +169,9 @@ class Application_Service_ShowFormService
}
}
//Disable starting a show 'now' when editing an existing show.
$form->getElement('add_show_start_now')->setAttrib('disable', array('now'));
$form->populate(
array(
'add_show_start_date' => $showStart->format("Y-m-d"),
@ -225,8 +228,12 @@ class Application_Service_ShowFormService
$form->disableStartDateAndTime();
}
//Disable starting a show 'now' when editing an existing show.
$form->getElement('add_show_start_now')->setAttrib('disable', array('now'));
$form->populate(
array(
'add_show_start_now' => 'future',
'add_show_start_date' => $showStart->format("Y-m-d"),
'add_show_start_time' => $showStart->format("H:i"),
'add_show_end_date_no_repeat' => $showEnd->format("Y-m-d"),

View file

@ -1,8 +1,18 @@
<fieldset>
<dl>
<dt id="add_show_start_now-label">
<label for="add_show_start_now">
<?php echo $this->element->getElement('add_show_start_now')->getLabel()?>
</label>
</dt>
<dd>
<?php echo $this->element->getElement('add_show_start_now') ?>
</dd>
<dt id="add_show_start_date-label">
<label for="add_show_start_date" class="required">
<?php echo $this->element->getElement('add_show_start_date')->getLabel()?>
<?php //echo $this->element->getElement('add_show_start_date')->getLabel()?>
</label>
</dt>
<dd>
@ -19,6 +29,9 @@
<?php endforeach; ?>
</ul>
<?php } ?>
<dt id="add_show_end_date_no_repeat-label">
<label for="add_show_end_date_no_repeat" class="required">
<?php echo $this->element->getElement('add_show_end_date_no_repeat')->getLabel()?>

View file

@ -8,6 +8,7 @@
<table id="library_display" cellpadding="0" cellspacing="0" class="datatable"></table>
</div>
<div id="show_builder" class="sb-content ui-widget ui-widget-content block-shadow omega-block padded">
<div id="builder-dialog-hint"><p><?php echo _("Drag files from the library on the left to add them to your show."); ?></p></div>
<table id="show_builder_table" cellpadding="0" cellspacing="0" class="datatable"></table>
</div>
</div>