2015-07-13 14:06:41 +02:00
< ? php
class Application_Common_UsabilityHints
{
2015-07-13 23:02:31 +02:00
/**
* @ 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
2015-07-15 16:41:01 +02:00
// 3. Check if current or next show needs content
2015-07-13 23:02:31 +02:00
// 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 {
2015-08-12 22:54:45 +02:00
return sprintf ( _ ( " It looks like you have not uploaded any audio files yet. %sUpload a file now%s. " ),
2015-08-25 22:43:10 +02:00
" <a href= \" /Plupload \" > " ,
2015-07-13 23:02:31 +02:00
" </a> " );
}
} else if ( ! self :: isFutureOrCurrentShowScheduled ()) {
if ( $userIsOnCalendarPage ) {
2015-08-25 22:48:31 +02:00
return _ ( " Click the 'New Show' button and fill out the required fields. " );
2015-07-13 23:02:31 +02:00
} else {
2015-08-12 22:54:45 +02:00
return sprintf ( _ ( " It looks like you don't have any shows scheduled. %sCreate a show now%s. " ),
2015-08-25 22:43:10 +02:00
" <a href= \" /Schedule \" > " ,
2015-07-13 23:02:31 +02:00
" </a> " );
}
2015-07-14 17:45:37 +02:00
} else if ( self :: isCurrentShowEmpty ()) {
2015-07-17 18:48:57 +02:00
// If the current show is linked users cannot add content to it so we have to provide a different message.
if ( self :: isCurrentShowLinked ()) {
if ( $userIsOnCalendarPage ) {
return _ ( " To start broadcasting, first you need to cancel the current linked show by clicking on it and selecting 'Cancel Current Show'. " );
} else {
2015-07-21 13:27:26 +02:00
return sprintf ( _ ( " Linked shows need to be filled with tracks before it starts. To start broadcasting cancel the current linked show and schedule an unlinked show.
2015-08-25 22:43:10 +02:00
% sCreate an unlinked show now % s . " ), " < a href = \ " /Schedule \" > " , " </a> " );
2015-07-17 18:48:57 +02:00
}
2015-07-13 23:02:31 +02:00
} else {
2015-07-17 18:48:57 +02:00
if ( $userIsOnCalendarPage ) {
return _ ( " To start broadcasting, click on the current show and select 'Add / Remove Content' " );
} else {
2015-08-12 22:54:45 +02:00
return sprintf ( _ ( " It looks like the current show needs more tracks. %sAdd tracks to your show now%s. " ),
2015-08-25 22:43:10 +02:00
" <a href= \" /Schedule \" > " ,
2015-07-17 18:48:57 +02:00
" </a> " );
}
2015-07-14 17:45:37 +02:00
}
} else if ( ! self :: getCurrentShow () && self :: isNextShowEmpty ()) {
if ( $userIsOnCalendarPage ) {
2015-07-14 18:14:00 +02:00
return _ ( " Click on the show starting next and select 'Add / Remove Content' " );
2015-07-14 17:45:37 +02:00
} else {
2015-08-12 22:54:45 +02:00
return sprintf ( _ ( " It looks like the next show is empty. %sAdd tracks to your show now%s. " ),
2015-08-25 22:43:10 +02:00
" <a href= \" /Schedule \" > " ,
2015-07-13 23:02:31 +02:00
" </a> " );
}
} else {
return " " ;
}
}
2015-07-13 14:06:41 +02:00
/**
* Returns true if no files have been uploaded .
*/
2015-07-14 17:45:37 +02:00
private static function zeroFilesUploaded ()
2015-07-13 14:06:41 +02:00
{
$fileCount = CcFilesQuery :: create ()
-> filterByDbFileExists ( true )
-> filterByDbHidden ( false )
-> count ();
if ( $fileCount == 0 ) {
return true ;
} else {
return false ;
}
}
/**
2015-07-15 16:41:01 +02:00
* Returns true if there is at least one show currently scheduled
* or in the future .
2015-07-13 14:06:41 +02:00
*/
2015-07-14 17:45:37 +02:00
private static function isFutureOrCurrentShowScheduled ()
2015-07-13 14:06:41 +02:00
{
2015-07-13 17:19:04 +02:00
$futureShow = self :: getNextFutureShow ();
$currentShow = self :: getCurrentShow ();
2015-07-13 14:06:41 +02:00
if ( is_null ( $futureShow ) && is_null ( $currentShow )) {
return false ;
} else {
return true ;
}
}
2015-07-14 17:45:37 +02:00
private static function isCurrentShowEmpty ()
2015-07-13 14:06:41 +02:00
{
2015-07-13 17:19:04 +02:00
$currentShow = self :: getCurrentShow ();
2015-07-13 14:06:41 +02:00
2015-07-14 17:45:37 +02:00
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 )) {
2015-07-13 14:06:41 +02:00
return false ;
} else {
2015-07-13 23:02:31 +02:00
$now = new DateTime ( " now " , new DateTimeZone ( " UTC " ));
2015-07-14 17:45:37 +02:00
$scheduledTracks = CcScheduleQuery :: create ()
-> filterByDbInstanceId ( $futureShow -> getDbId ())
-> filterByDbStarts ( $now , Criteria :: GREATER_EQUAL )
-> find ();
if ( $scheduledTracks -> count () == 0 ) {
return true ;
} else {
return false ;
2015-07-13 14:06:41 +02:00
}
}
}
2015-07-13 17:19:04 +02:00
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 ();
}
2015-07-17 18:48:57 +02:00
private static function isCurrentShowLinked ()
{
$currentShow = self :: getCurrentShow ();
if ( ! is_null ( $currentShow )) {
$show = CcShowQuery :: create ()
-> filterByDbId ( $currentShow -> getDbShowId ())
-> findOne ();
if ( $show -> isLinked ()) {
return true ;
} else {
return false ;
}
} else {
return false ;
}
}
2015-07-13 14:06:41 +02:00
}