2010-12-07 20:19:27 +01:00
< ? php
2012-07-16 03:17:13 +02:00
class Application_Model_Show
{
2011-04-12 17:54:24 +02:00
private $_showId ;
2010-12-07 20:19:27 +01:00
2021-10-11 16:10:47 +02:00
public function __construct ( $showId = null )
2010-12-07 20:19:27 +01:00
{
2011-04-12 17:54:24 +02:00
$this -> _showId = $showId ;
2010-12-07 20:19:27 +01:00
}
2011-03-22 14:55:33 +01:00
public function getName ()
{
2011-02-01 17:43:52 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2012-07-16 03:17:13 +02:00
2011-02-01 17:43:52 +01:00
return $show -> getDbName ();
}
2011-03-22 14:55:33 +01:00
public function setName ( $name )
{
2011-02-01 17:43:52 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbName ( $name );
2011-09-26 21:19:04 +02:00
Application_Model_RabbitMq :: PushSchedule ();
2011-02-01 17:43:52 +01:00
}
2012-07-11 00:51:32 +02:00
2012-07-16 03:17:13 +02:00
public function setAirtimeAuthFlag ( $flag )
{
2012-04-05 22:01:27 +02:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbLiveStreamUsingAirtimeAuth ( $flag );
$show -> save ();
}
2012-07-11 00:51:32 +02:00
2012-07-16 03:17:13 +02:00
public function setCustomAuthFlag ( $flag )
{
2012-04-05 22:01:27 +02:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbLiveStreamUsingCustomAuth ( $flag );
$show -> save ();
}
2012-07-11 00:51:32 +02:00
2012-07-16 03:17:13 +02:00
public function setCustomUsername ( $username )
{
2012-04-05 22:01:27 +02:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbLiveStreamUser ( $username );
$show -> save ();
}
2012-07-11 00:51:32 +02:00
2012-07-16 03:17:13 +02:00
public function setCustomPassword ( $password )
{
2012-04-05 22:01:27 +02:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbLiveStreamPass ( $password );
$show -> save ();
}
2011-02-01 17:43:52 +01:00
2011-03-22 14:55:33 +01:00
public function getDescription ()
{
2011-02-10 00:10:46 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2012-07-16 03:17:13 +02:00
2011-02-10 00:10:46 +01:00
return $show -> getDbDescription ();
}
2011-03-22 14:55:33 +01:00
public function setDescription ( $description )
{
2011-02-10 00:10:46 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbDescription ( $description );
}
2011-03-22 14:55:33 +01:00
public function getColor ()
{
2011-02-10 00:10:46 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2021-10-11 16:10:47 +02:00
2011-02-10 00:10:46 +01:00
return $show -> getDbColor ();
}
2011-03-22 14:55:33 +01:00
public function setColor ( $color )
{
2011-02-10 00:10:46 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbColor ( $color );
}
2011-04-12 06:14:26 +02:00
public function getUrl ()
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2012-07-16 03:17:13 +02:00
2011-04-12 06:14:26 +02:00
return $show -> getDbUrl ();
}
2012-09-07 17:23:18 +02:00
/* TODO : This method is not actually used anywhere as far as I can tell . We
can safely remove it and probably many other superfluous methods .
-- RG */
2011-04-12 06:14:26 +02:00
public function setUrl ( $p_url )
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbUrl ( $p_url );
}
public function getGenre ()
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2012-07-16 03:17:13 +02:00
2011-04-12 06:14:26 +02:00
return $show -> getDbGenre ();
}
public function setGenre ( $p_genre )
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbGenre ( $p_genre );
}
public function getBackgroundColor ()
{
2011-02-10 00:10:46 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2012-07-16 03:17:13 +02:00
2015-08-12 18:55:39 +02:00
$color = $show -> getDbBackgroundColor ();
if ( empty ( $color )) {
return DEFAULT_SHOW_COLOR ;
}
2021-10-11 16:10:47 +02:00
return $color ;
2011-02-10 00:10:46 +01:00
}
2011-03-22 14:55:33 +01:00
public function setBackgroundColor ( $backgroundColor )
{
2011-02-10 00:10:46 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbBackgroundColor ( $backgroundColor );
}
2011-03-30 23:27:14 +02:00
public function getId ()
{
return $this -> _showId ;
}
2017-02-13 15:35:09 +01:00
public function getHasAutoPlaylist ()
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2021-10-11 16:10:47 +02:00
return $show -> getDbHasAutoPlaylist ();
2017-02-13 15:35:09 +01:00
}
2017-03-31 06:00:19 +02:00
2021-10-11 16:10:47 +02:00
public function getAutoPlaylistRepeat ()
{
2017-03-31 06:00:19 +02:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2021-10-11 16:10:47 +02:00
return $show -> getDbAutoPlaylistRepeat ();
2017-03-31 06:00:19 +02:00
}
2017-03-31 17:46:39 +02:00
public function setAutoPlaylistRepeat ( $value )
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbAutoPlaylistRepeat ( $value );
}
2021-10-11 16:10:47 +02:00
2017-02-13 15:35:09 +01:00
public function setHasAutoPlaylist ( $value )
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbHasAutoPlaylist ( $value );
}
public function getAutoPlaylistId ()
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2021-10-11 16:10:47 +02:00
return $show -> getDbAutoPlaylistId ();
2017-02-13 15:35:09 +01:00
}
public function setAutoPlaylistId ( $playlistid )
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> setDbAutoPlaylistId ( $playlistid );
}
2024-10-21 19:34:39 +02:00
public function getHasOverrideIntroPlaylist ()
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
return $show -> getDbOverrideIntroPlaylist ();
}
2024-10-14 22:07:41 +02:00
public function getIntroPlaylistId ()
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2024-10-21 19:34:39 +02:00
if ( $show -> getDbOverrideIntroPlaylist ()) {
return $show -> getDbIntroPlaylistId ();
}
return 0 ;
2024-10-14 22:07:41 +02:00
}
public function setIntroPlaylistId ( $playlistid )
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2024-10-21 19:34:39 +02:00
$show -> setDbOverrideIntroPlaylist ( $playlistid != 0 );
2024-10-14 22:07:41 +02:00
$show -> setDbIntroPlaylistId ( $playlistid );
}
2024-10-21 19:34:39 +02:00
public function getHasOverrideOutroPlaylist ()
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
return $show -> getDbOverrideOutroPlaylist ();
}
2024-10-14 22:07:41 +02:00
public function getOutroPlaylistId ()
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2024-10-21 19:34:39 +02:00
if ( $show -> getDbOverrideOutroPlaylist ()) {
return $show -> getDbOutroPlaylistId ();
}
return 0 ;
2024-10-14 22:07:41 +02:00
}
public function setOutroPlaylistId ( $playlistid )
{
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
2024-10-21 19:34:39 +02:00
$show -> setDbOverrideOutroPlaylist ( $playlistid != 0 );
2024-10-14 22:07:41 +02:00
$show -> setDbOutroPlaylistId ( $playlistid );
}
2011-03-29 18:47:34 +02:00
public function getHosts ()
{
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-12 18:00:53 +02:00
SELECT first_name ,
last_name
FROM cc_show_hosts
LEFT JOIN cc_subjs ON cc_show_hosts . subjs_id = cc_subjs . id
WHERE show_id = : show_id
SQL ;
2011-03-29 18:47:34 +02:00
2021-10-11 16:10:47 +02:00
$hosts = Application_Common_Database :: prepareAndExecute (
$sql ,
[ ':show_id' => $this -> getId ()],
'all'
);
2011-03-29 18:47:34 +02:00
2021-10-11 16:10:47 +02:00
$res = [];
2012-09-12 17:54:37 +02:00
foreach ( $hosts as $host ) {
2021-10-11 16:10:47 +02:00
$res [] = $host [ 'first_name' ] . ' ' . $host [ 'last_name' ];
2012-09-12 17:54:37 +02:00
}
2021-10-11 16:10:47 +02:00
2011-03-29 18:47:34 +02:00
return $res ;
}
2012-04-01 21:51:03 +02:00
2012-03-02 22:55:11 +01:00
public function getHostsIds ()
{
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-12 17:59:27 +02:00
SELECT subjs_id
FROM cc_show_hosts
WHERE show_id = : show_id
SQL ;
2012-03-02 22:55:11 +01:00
2021-10-11 16:10:47 +02:00
return Application_Common_Database :: prepareAndExecute (
$sql ,
[ ':show_id' => $this -> getId ()],
'all'
);
2012-03-02 22:55:11 +01:00
}
2011-03-29 18:47:34 +02:00
2012-04-01 21:51:03 +02:00
/**
* remove everything about this show .
*/
2011-12-05 18:56:16 +01:00
public function delete ()
2011-12-02 13:31:54 +01:00
{
2022-03-14 11:15:04 +01:00
// usually we hide the show-instance, but in this case we are deleting the show template
// so delete all show-instances as well.
2011-12-02 22:22:54 +01:00
CcShowInstancesQuery :: create () -> filterByDbOriginalShow ( $this -> _showId ) -> delete ();
2011-12-13 11:10:04 +01:00
2011-12-02 13:31:54 +01:00
$show = CcShowQuery :: create () -> findPK ( $this -> _showId );
$show -> delete ();
}
2013-11-28 23:17:00 +01:00
public function resizeShow ( $deltaDay , $deltaMin , $instanceId )
2011-11-16 16:32:04 +01:00
{
2012-07-16 03:17:13 +02:00
$con = Propel :: getConnection ();
2011-12-13 11:10:04 +01:00
2011-12-12 12:11:31 +01:00
if ( $deltaDay > 0 ) {
2021-10-11 16:10:47 +02:00
return _ ( 'Shows can have a max length of 24 hours.' );
2011-12-12 12:11:31 +01:00
}
2013-11-28 23:17:00 +01:00
2021-10-11 16:10:47 +02:00
$utcTimezone = new DateTimeZone ( 'UTC' );
$nowDateTime = new DateTime ( 'now' , $utcTimezone );
2012-08-29 16:58:03 +02:00
2022-03-14 11:15:04 +01:00
// keep track of cc_show_day entries we need to update
2021-10-11 16:10:47 +02:00
$showDayIds = [];
2013-12-02 13:19:31 +01:00
/*
* If the resized show is an edited instance of a repeating show we
* need to treat it as a separate show and not resize the other instances
2021-10-11 16:10:47 +02:00
*
2013-12-02 13:19:31 +01:00
* Also , if the resized show has edited instances , we need to exclude
* those from the resize
*/
$ccShow = CcShowQuery :: create () -> findPk ( $this -> _showId );
if ( $ccShow -> isRepeating ()) {
2022-03-14 11:15:04 +01:00
// convert instance to local timezone
2013-12-02 13:19:31 +01:00
$ccShowInstance = CcShowInstancesQuery :: create () -> findPk ( $instanceId );
2013-12-04 18:20:16 +01:00
$startsDT = $ccShowInstance -> getDbStarts ( null );
2013-12-02 13:19:31 +01:00
$timezone = $ccShow -> getFirstCcShowDay () -> getDbTimezone ();
$startsDT -> setTimezone ( new DateTimeZone ( $timezone ));
/* Get cc_show_day for the current instance . If we don ' t find one
* we know it is a repeat interval of one of cc_show_days first
* show and we can assume we aren ' t resizing a modified instance
*/
$ccShowDay = CcShowDaysQuery :: create ()
2021-10-11 16:10:47 +02:00
-> filterByDbFirstShow ( $startsDT -> format ( 'Y-m-d' ))
-> filterByDbStartTime ( $startsDT -> format ( 'H:i:s' ))
2013-12-02 13:19:31 +01:00
-> filterByDbShowId ( $this -> _showId )
2022-01-23 19:15:55 +01:00
-> findOne ();
2013-12-02 13:19:31 +01:00
/* Check if this cc_show_day rule is non - repeating . If it is , then
* we know this instance was edited out of the repeating sequence
*/
if ( ! $ccShowDay || $ccShowDay -> getDbRepeatType () != - 1 ) {
$ccShowDays = $ccShow -> getRepeatingCcShowDays ();
foreach ( $ccShowDays as $day ) {
array_push ( $showDayIds , $day -> getDbId ());
}
$excludeIds = $ccShow -> getEditedRepeatingInstanceIds ();
2022-03-14 11:15:04 +01:00
// exlcude edited instances from resize
2013-12-02 13:19:31 +01:00
$showInstances = CcShowInstancesQuery :: create ()
-> filterByDbShowId ( $this -> _showId )
-> filterByDbModifiedInstance ( false )
-> filterByDbId ( $excludeIds , criteria :: NOT_IN )
2022-01-23 19:15:55 +01:00
-> find ();
2013-12-02 13:19:31 +01:00
} elseif ( $ccShowDay -> getDbRepeatType () == - 1 ) {
array_push ( $showDayIds , $ccShowDay -> getDbId ());
2022-03-14 11:15:04 +01:00
// treat edited instance as separate show for resize
2013-12-02 13:19:31 +01:00
$showInstances = CcShowInstancesQuery :: create ()
-> filterByDbId ( $instanceId )
2022-01-23 19:15:55 +01:00
-> find ();
2013-12-02 13:19:31 +01:00
}
} else {
$ccShowDays = $ccShow -> getCcShowDayss ();
foreach ( $ccShowDays as $day ) {
array_push ( $showDayIds , $day -> getDbId ());
}
$showInstances = CcShowInstancesQuery :: create ()
-> filterByDbShowId ( $this -> _showId )
2022-01-23 19:15:55 +01:00
-> find ( $con );
2013-12-02 13:19:31 +01:00
}
2012-08-29 16:58:03 +02:00
2012-10-09 20:20:00 +02:00
/* Check two things :
2013-01-14 22:16:14 +01:00
1. If the show being resized and any of its repeats end in the past
2012-10-09 20:20:00 +02:00
2. If the show being resized and any of its repeats overlap
with other scheduled shows */
2012-09-07 17:20:23 +02:00
2022-03-14 11:15:04 +01:00
// keep track of instance ids for update show instances start/end times
2021-10-11 16:10:47 +02:00
$instanceIds = [];
2013-12-04 21:48:32 +01:00
$displayTimezone = new DateTimeZone ( Application_Model_Preference :: GetUserTimezone ());
2021-10-11 16:10:47 +02:00
2022-03-14 11:15:04 +01:00
// check if new show time overlaps with any other shows
2012-08-24 21:27:04 +02:00
foreach ( $showInstances as $si ) {
2013-12-02 13:19:31 +01:00
array_push ( $instanceIds , $si -> getDbId ());
2013-12-04 18:20:16 +01:00
$startsDateTime = $si -> getDbStarts ( null );
2021-10-11 16:10:47 +02:00
$endsDateTime = $si -> getDbEnds ( null );
2012-08-29 16:58:03 +02:00
2012-09-07 17:18:10 +02:00
/* The user is moving the show on the calendar from the perspective
of local time . * incase a show is moved across a time change
border offsets should be added to the local * timestamp and
then converted back to UTC to avoid show time changes */
2013-12-04 21:48:32 +01:00
$startsDateTime -> setTimezone ( $displayTimezone );
$endsDateTime -> setTimezone ( $displayTimezone );
2012-08-29 16:58:03 +02:00
2022-03-14 11:15:04 +01:00
// $newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin);
2021-10-11 16:10:47 +02:00
$newEndsDateTime = Application_Model_ShowInstance :: addDeltas ( $endsDateTime , $deltaDay , $deltaMin );
2013-12-02 13:19:31 +01:00
2012-10-09 20:20:00 +02:00
if ( $newEndsDateTime -> getTimestamp () < $nowDateTime -> getTimestamp ()) {
2021-10-11 16:10:47 +02:00
return _ ( 'End date/time cannot be in the past' );
2012-10-09 20:20:00 +02:00
}
2012-08-29 16:58:03 +02:00
2022-03-14 11:15:04 +01:00
// convert our new starts/ends to UTC.
// $newStartsDateTime->setTimezone($utc);
2013-12-04 21:48:32 +01:00
$newEndsDateTime -> setTimezone ( $utcTimezone );
2012-09-07 17:20:23 +02:00
$overlapping = Application_Model_Schedule :: checkOverlappingShows (
2021-10-11 16:10:47 +02:00
$startsDateTime ,
$newEndsDateTime ,
true ,
$si -> getDbId ()
);
2012-08-29 16:58:03 +02:00
2012-08-24 21:27:04 +02:00
if ( $overlapping ) {
2021-10-11 16:10:47 +02:00
return _ ( " Cannot schedule overlapping shows. \n Note: Resizing a repeating show " .
2022-07-07 20:01:15 +02:00
'affects all of its repeats.' );
2012-08-24 21:27:04 +02:00
}
}
2011-11-16 16:32:04 +01:00
2021-10-11 16:10:47 +02:00
$hours = $deltaMin / 60 ;
2012-09-07 17:18:10 +02:00
$hours = ( $hours > 0 ) ? floor ( $hours ) : ceil ( $hours );
2021-10-11 16:10:47 +02:00
$mins = abs ( $deltaMin % 60 );
2011-11-16 16:32:04 +01:00
2021-10-11 16:10:47 +02:00
$sql_gen = 'UPDATE cc_show_instances ' .
'SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL) ' .
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
'WHERE (id IN (' . implode ( ',' , $instanceIds ) . ') ' .
2021-10-11 16:10:47 +02:00
'AND ends > :current_timestamp1) ' .
2013-12-02 13:19:31 +01:00
" AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00') " ;
2012-09-06 21:47:07 +02:00
2021-10-11 16:10:47 +02:00
Application_Common_Database :: prepareAndExecute (
$sql_gen ,
[
':deltaDay1' => " { $deltaDay } days " ,
':interval1' => " { $hours } : { $mins } " ,
':current_timestamp1' => $nowDateTime -> format ( DEFAULT_TIMESTAMP_FORMAT ),
':deltaDay2' => " { $deltaDay } days " ,
':interval2' => " { $hours } : { $mins } " ,
],
'execute'
);
$sql_gen = 'UPDATE cc_show_days ' .
'SET duration = (CAST(duration AS interval) + :deltaDay3::INTERVAL + :interval3::INTERVAL) ' .
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
'WHERE id IN (' . implode ( ',' , $showDayIds ) . ') ' .
2013-12-02 13:19:31 +01:00
" AND ((CAST(duration AS interval) + :deltaDay4::INTERVAL + :interval4::INTERVAL) <= interval '24:00') " ;
2012-09-19 21:03:16 +02:00
2021-10-11 16:10:47 +02:00
Application_Common_Database :: prepareAndExecute (
$sql_gen ,
[
':deltaDay3' => " { $deltaDay } days " ,
':interval3' => " { $hours } : { $mins } " ,
':deltaDay4' => " { $deltaDay } days " ,
':interval4' => " { $hours } : { $mins } " ,
],
'execute'
);
2011-11-16 16:32:04 +01:00
2012-03-01 14:59:06 +01:00
$con = Propel :: getConnection ( CcSchedulePeer :: DATABASE_NAME );
$con -> beginTransaction ();
try {
2022-03-14 11:15:04 +01:00
// update the status flag in cc_schedule.
2012-10-31 19:16:16 +01:00
/* Since we didn ' t use a propel object when updating
* cc_show_instances table we need to clear the instances
* so the correct information is retrieved from the db
*/
2012-10-31 17:36:45 +01:00
CcShowInstancesPeer :: clearInstancePool ();
2012-10-31 19:16:16 +01:00
2012-03-01 14:59:06 +01:00
$instances = CcShowInstancesQuery :: create ()
2015-06-26 20:42:52 +02:00
-> filterByDbEnds ( $nowDateTime -> format ( DEFAULT_TIMESTAMP_FORMAT ), Criteria :: GREATER_THAN )
2013-12-02 13:19:31 +01:00
-> filterByDbId ( $instanceIds , Criteria :: IN )
2022-01-23 19:15:55 +01:00
-> find ( $con );
2012-03-01 14:59:06 +01:00
foreach ( $instances as $instance ) {
2012-03-12 15:02:34 +01:00
$instance -> updateScheduleStatus ( $con );
2012-03-01 14:59:06 +01:00
}
$con -> commit ();
2012-07-16 03:17:13 +02:00
} catch ( Exception $e ) {
2012-03-01 14:59:06 +01:00
$con -> rollback ();
2012-08-22 00:41:56 +02:00
Logging :: info ( " Couldn't update schedule status. " );
Logging :: info ( $e -> getMessage ());
2012-03-01 14:59:06 +01:00
}
2011-11-16 16:32:04 +01:00
Application_Model_RabbitMq :: PushSchedule ();
}
2011-03-22 14:55:33 +01:00
public function cancelShow ( $day_timestamp )
{
2021-10-11 16:10:47 +02:00
$timeinfo = explode ( ' ' , $day_timestamp );
2011-02-12 23:21:37 +01:00
CcShowDaysQuery :: create ()
-> filterByDbShowId ( $this -> _showId )
2022-01-23 19:15:55 +01:00
-> update ([ 'DbLastShow' => $timeinfo [ 0 ]]);
2011-02-12 23:21:37 +01:00
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-17 18:32:39 +02:00
SELECT id from cc_show_instances
2012-09-12 18:05:03 +02:00
WHERE starts >= : dayTimestamp :: TIMESTAMP
AND show_id = : showId
SQL ;
2021-10-11 16:10:47 +02:00
$rows = Application_Common_Database :: prepareAndExecute ( $sql , [
2012-09-12 18:05:03 +02:00
':dayTimestamp' => $day_timestamp ,
2022-07-07 20:01:15 +02:00
':showId' => $this -> getId (),
], 'all' );
2012-09-17 18:32:39 +02:00
foreach ( $rows as $row ) {
try {
2021-10-11 16:10:47 +02:00
$showInstance = new Application_Model_ShowInstance ( $row [ 'id' ]);
2012-09-17 18:32:39 +02:00
$showInstance -> delete ( $rabbitmqPush = false );
} catch ( Exception $e ) {
Logging :: info ( $e -> getMessage ());
}
2013-01-14 22:16:14 +01:00
}
2011-11-15 15:20:33 +01:00
2011-09-26 21:19:04 +02:00
Application_Model_RabbitMq :: PushSchedule ();
2011-02-12 23:21:37 +01:00
}
2011-04-12 06:14:26 +02:00
/**
* Check whether the current show originated
* from a recording .
*
2021-10-11 16:10:47 +02:00
* @ return bool
* true if originated from recording , otherwise false
2011-04-12 06:14:26 +02:00
*/
2012-07-16 03:17:13 +02:00
public function isRecorded ()
{
2011-04-12 06:14:26 +02:00
$showInstancesRow = CcShowInstancesQuery :: create ()
2012-04-01 21:51:03 +02:00
-> filterByDbShowId ( $this -> getId ())
-> filterByDbRecord ( 1 )
-> filterByDbModifiedInstance ( false )
2022-01-23 19:15:55 +01:00
-> findOne ();
2011-04-12 06:14:26 +02:00
return ! is_null ( $showInstancesRow );
}
/**
* Check whether the current show has rebroadcasts of a recorded
* show . Should be used in conjunction with isRecorded () .
*
2021-10-11 16:10:47 +02:00
* @ return bool
* true if show has rebroadcasts , otherwise false
2011-04-12 06:14:26 +02:00
*/
public function isRebroadcast ()
{
2021-10-11 16:10:47 +02:00
$showInstancesRow = CcShowInstancesQuery :: create ()
-> filterByDbShowId ( $this -> _showId )
-> filterByDbRebroadcast ( 1 )
-> filterByDbModifiedInstance ( false )
2022-01-23 19:15:55 +01:00
-> findOne ();
2011-04-12 06:14:26 +02:00
2011-04-25 23:24:53 +02:00
return ! is_null ( $showInstancesRow );
2011-04-12 06:14:26 +02:00
}
2011-04-12 23:29:35 +02:00
2011-04-14 20:17:56 +02:00
/**
* Get start time and relative start date for a recorded
* shows rebroadcasts . For example start date format would be
2021-10-11 16:10:47 +02:00
* " x days " and time would HH : MM : SS .
2011-04-14 20:17:56 +02:00
*
* @ return array
2021-10-11 16:10:47 +02:00
* array of associate arrays containing " day_offset " and " start_time "
2011-04-14 20:17:56 +02:00
*/
2011-04-12 23:29:35 +02:00
public function getRebroadcastsRelative ()
{
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 18:10:07 +02:00
SELECT day_offset ,
start_time
FROM cc_show_rebroadcast
WHERE show_id = : showId
ORDER BY day_offset
SQL ;
2021-10-11 16:10:47 +02:00
return Application_Common_Database :: prepareAndExecute (
$sql ,
[ ':showId' => $this -> getId ()],
'all'
);
2011-04-12 23:29:35 +02:00
}
2011-04-25 23:24:53 +02:00
2011-04-12 06:14:26 +02:00
/**
* Check whether the current show is set to repeat
* repeating shows .
*
2021-10-11 16:10:47 +02:00
* @ return bool
* true if repeating shows , otherwise false
2011-04-12 06:14:26 +02:00
*/
public function isRepeating ()
{
$showDaysRow = CcShowDaysQuery :: create ()
2012-01-18 16:21:46 +01:00
-> filterByDbShowId ( $this -> _showId )
2022-01-23 19:15:55 +01:00
-> findOne ();
2011-04-12 06:14:26 +02:00
2012-07-16 03:17:13 +02:00
if ( ! is_null ( $showDaysRow )) {
2021-10-11 16:10:47 +02:00
return $showDaysRow -> getDbRepeatType () != - 1 ;
2012-01-18 16:21:46 +01:00
}
2021-10-11 16:10:47 +02:00
return false ;
2011-04-12 06:14:26 +02:00
}
2011-04-25 23:24:53 +02:00
2011-04-12 06:14:26 +02:00
/**
2021-10-11 16:10:47 +02:00
* Get the repeat type of the show . Show can have repeat type of
2013-10-10 11:43:45 +02:00
* " weekly " , " every 2 weeks " , " monthly " , " monthly on the same weekday " ,
2021-10-11 16:10:47 +02:00
* " every 3 weeks " and " every 4 weeks " . These values are represented
2013-10-10 11:43:45 +02:00
* by 0 , 1 , 2 , 3 , 4 and 5 , respectively .
2011-04-12 06:14:26 +02:00
*
* @ return int
2021-10-11 16:10:47 +02:00
* Return the integer corresponding to the repeat type
2011-04-12 06:14:26 +02:00
*/
public function getRepeatType ()
{
$showDaysRow = CcShowDaysQuery :: create ()
2012-04-01 21:51:03 +02:00
-> filterByDbShowId ( $this -> _showId )
2022-01-23 19:15:55 +01:00
-> findOne ();
2011-04-12 06:14:26 +02:00
2021-10-11 16:10:47 +02:00
if ( ! is_null ( $showDaysRow )) {
2011-04-12 06:14:26 +02:00
return $showDaysRow -> getDbRepeatType ();
2021-10-11 16:10:47 +02:00
}
return - 1 ;
2011-04-12 06:14:26 +02:00
}
/**
2021-10-11 16:10:47 +02:00
* Get the end date for a repeating show in the format yyyy - mm - dd .
2011-04-12 06:14:26 +02:00
*
* @ return string
2021-10-11 16:10:47 +02:00
* Return the end date for the repeating show or the empty
* string if there is no end
2011-04-12 06:14:26 +02:00
*/
2012-04-01 21:51:03 +02:00
public function getRepeatingEndDate ()
{
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 18:18:13 +02:00
SELECT last_show
FROM cc_show_days
WHERE show_id = : showId
ORDER BY last_show DESC
SQL ;
2011-04-25 23:24:53 +02:00
2021-10-11 16:10:47 +02:00
$query = Application_Common_Database :: prepareAndExecute (
$sql ,
[ 'showId' => $this -> getId ()],
'column'
);
2012-07-16 03:17:13 +02:00
2021-10-11 16:10:47 +02:00
// TODO: Why return empty string instead of false? very confusing --RG
return ( $query !== false ) ? $query : '' ;
2011-04-12 06:14:26 +02:00
}
2011-04-14 20:17:56 +02:00
/**
* Deletes all future instances of the current show object
2011-11-12 04:55:46 +01:00
* from the show_instances table . This function is used when
* a show is being edited - in some cases , when a show is edited
* we just destroy all future show instances , and let another function
* regenerate them later on . Note that this isn ' t always the most
* desirable thing to do . Deleting a show instance and regenerating
* it cause any scheduled playlists within those show instances to
* be gone for good .
2011-04-14 20:17:56 +02:00
*/
2012-07-16 03:17:13 +02:00
public function deleteAllInstances ()
{
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 18:22:49 +02:00
DELETE
FROM cc_show_instances
WHERE starts > : timestamp :: TIMESTAMP
AND show_id = : showId
SQL ;
2021-10-11 16:10:47 +02:00
Application_Common_Database :: prepareAndExecute (
$sql ,
2022-07-07 20:01:15 +02:00
[
':timestamp' => gmdate ( DEFAULT_TIMESTAMP_FORMAT ),
':showId' => $this -> getId (),
],
2021-10-11 16:10:47 +02:00
'execute'
);
2011-04-12 06:14:26 +02:00
}
2011-06-06 18:56:32 +02:00
2011-06-06 18:20:44 +02:00
/**
2011-06-06 18:56:32 +02:00
* Deletes all future rebroadcast instances of the current
2011-06-06 18:20:44 +02:00
* show object from the show_instances table .
*/
2012-07-16 03:17:13 +02:00
public function deleteAllRebroadcasts ()
{
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 18:29:42 +02:00
DELETE
FROM cc_show_instances
WHERE starts > : timestamp :: TIMESTAMP
AND show_id : showId
AND rebroadcast 1
SQL ;
2021-10-11 16:10:47 +02:00
Application_Common_Database :: prepareAndExecute (
$sql ,
2022-07-07 20:01:15 +02:00
[
':showId' => $this -> getId (),
':timestamp' => gmdate ( DEFAULT_TIMESTAMP_FORMAT ),
],
2021-10-11 16:10:47 +02:00
'execute'
);
2011-06-06 18:20:44 +02:00
}
2011-04-14 20:17:56 +02:00
/**
2011-11-20 20:46:01 +01:00
* Get the start date of the current show in UTC timezone .
2011-04-14 20:17:56 +02:00
*
* @ return string
2021-10-11 16:10:47 +02:00
* The start date in the format YYYY - MM - DD or empty string in case
* start date could not be found
2011-04-25 23:24:53 +02:00
*/
2012-07-16 03:17:13 +02:00
public function getStartDateAndTime ()
{
2012-04-25 00:22:39 +02:00
$con = Propel :: getConnection ();
2011-04-25 23:24:53 +02:00
2011-04-12 06:14:26 +02:00
$showId = $this -> getId ();
2012-09-04 21:26:12 +02:00
$stmt = $con -> prepare (
2021-10-11 16:10:47 +02:00
'SELECT first_show, start_time, timezone FROM cc_show_days'
2022-07-07 20:01:15 +02:00
. ' WHERE show_id = :showId'
. ' ORDER BY first_show'
. ' LIMIT 1'
2021-10-11 16:10:47 +02:00
);
2012-09-04 21:26:12 +02:00
$stmt -> bindParam ( ':showId' , $showId );
$stmt -> execute ();
2011-04-25 23:24:53 +02:00
2012-09-04 21:26:12 +02:00
if ( ! $stmt ) {
2021-10-11 16:10:47 +02:00
return '' ;
2012-09-04 21:26:12 +02:00
}
2011-11-23 18:47:44 +01:00
2012-09-04 21:26:12 +02:00
$rows = $stmt -> fetchAll ();
$row = $rows [ 0 ];
2012-07-16 03:17:13 +02:00
2021-10-11 16:10:47 +02:00
$dt = new DateTime ( $row [ 'first_show' ] . ' ' . $row [ 'start_time' ], new DateTimeZone ( $row [ 'timezone' ]));
$dt -> setTimezone ( new DateTimeZone ( 'UTC' ));
2012-09-04 21:26:12 +02:00
2021-10-11 16:10:47 +02:00
return $dt -> format ( 'Y-m-d H:i' );
2011-04-12 06:14:26 +02:00
}
2011-11-23 18:47:44 +01:00
2012-04-25 00:22:39 +02:00
/**
* Get the start date of the current show in UTC timezone .
*
* @ return string
2021-10-11 16:10:47 +02:00
* The start date in the format YYYY - MM - DD
2012-04-25 00:22:39 +02:00
*/
2012-07-16 03:17:13 +02:00
public function getStartDate ()
{
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
[ $date ] = explode ( ' ' , $this -> getStartDateAndTime ());
2012-07-16 03:17:13 +02:00
2012-07-11 00:51:32 +02:00
return $date ;
2012-04-25 00:22:39 +02:00
}
2011-04-14 20:17:56 +02:00
/**
2011-11-20 20:46:01 +01:00
* Get the start time of the current show in UTC timezone .
2011-04-14 20:17:56 +02:00
*
* @ return string
2021-10-11 16:10:47 +02:00
* The start time in the format HH : MM
2011-04-25 23:24:53 +02:00
*/
2012-07-16 03:17:13 +02:00
public function getStartTime ()
{
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
[, $time ] = explode ( ' ' , $this -> getStartDateAndTime ());
2012-07-16 03:17:13 +02:00
2012-07-11 00:51:32 +02:00
return $time ;
2011-04-12 06:14:26 +02:00
}
2011-11-15 15:20:33 +01:00
2011-10-25 22:49:44 +02:00
/**
2011-06-03 20:53:01 +02:00
* Get the end date of the current show .
2021-10-11 16:10:47 +02:00
* Note that this is not the end date of repeated show .
2011-11-15 15:20:33 +01:00
*
2011-06-03 20:53:01 +02:00
* @ return string
2021-10-11 16:10:47 +02:00
* The end date in the format YYYY - MM - DD
2011-06-03 20:53:01 +02:00
*/
2012-07-16 03:17:13 +02:00
public function getEndDate ()
{
2021-10-11 16:10:47 +02:00
$startDate = $this -> getStartDate ();
$startTime = $this -> getStartTime ();
$duration = $this -> getDuration ();
2011-11-15 15:20:33 +01:00
2021-10-11 16:10:47 +02:00
$startDateTime = new DateTime ( $startDate . ' ' . $startTime );
$duration = explode ( ':' , $duration );
2011-11-15 15:20:33 +01:00
2021-10-11 16:10:47 +02:00
$endDate = $startDateTime -> add ( new DateInterval ( 'PT' . $duration [ 0 ] . 'H' . $duration [ 1 ] . 'M' ));
2011-11-15 15:20:33 +01:00
2011-06-03 20:53:01 +02:00
return $endDate -> format ( 'Y-m-d' );
}
/**
* Get the end time of the current show .
*
* @ return string
2021-10-11 16:10:47 +02:00
* The start time in the format HH : MM : SS
2011-06-03 20:53:01 +02:00
*/
2012-07-16 03:17:13 +02:00
public function getEndTime ()
{
2011-06-03 20:53:01 +02:00
$startDate = $this -> getStartDate ();
$startTime = $this -> getStartTime ();
$duration = $this -> getDuration ();
2011-11-15 15:20:33 +01:00
2021-10-11 16:10:47 +02:00
$startDateTime = new DateTime ( $startDate . ' ' . $startTime );
$duration = explode ( ':' , $duration );
2011-11-15 15:20:33 +01:00
2021-10-11 16:10:47 +02:00
$endDate = $startDateTime -> add ( new DateInterval ( 'PT' . $duration [ 0 ] . 'H' . $duration [ 1 ] . 'M' ));
2011-11-15 15:20:33 +01:00
2011-06-03 20:53:01 +02:00
return $endDate -> format ( 'H:i:s' );
}
2011-04-14 20:17:56 +02:00
2011-05-30 18:24:39 +02:00
/**
* Indicate whether the starting point of the show is in the
* past .
*
2021-10-11 16:10:47 +02:00
* @ return bool
* true if the StartDate is in the past , false otherwise
2011-05-30 18:24:39 +02:00
*/
2012-07-16 03:17:13 +02:00
public function isStartDateTimeInPast ()
{
2021-10-11 16:10:47 +02:00
return gmdate ( DEFAULT_TIMESTAMP_FORMAT ) > ( $this -> getStartDate () . ' ' . $this -> getStartTime ());
2011-05-30 18:24:39 +02:00
}
2011-04-14 20:17:56 +02:00
/**
* Get the ID ' s of future instance of the current show .
*
* @ return array
2021-10-11 16:10:47 +02:00
* A simple array containing all ID ' s of show instance
* scheduled in the future
2011-04-25 23:24:53 +02:00
*/
2012-07-16 03:17:13 +02:00
public function getAllFutureInstanceIds ()
{
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 20:30:59 +02:00
SELECT id
FROM cc_show_instances
2012-09-12 18:15:47 +02:00
WHERE show_id = : showId
2012-09-07 20:30:59 +02:00
AND starts > : timestamp :: TIMESTAMP
AND modified_instance != TRUE
SQL ;
2021-10-11 16:10:47 +02:00
$rows = Application_Common_Database :: prepareAndExecute (
$sql ,
2022-07-07 20:01:15 +02:00
[
':showId' => $this -> getId (),
':timestamp' => gmdate ( DEFAULT_TIMESTAMP_FORMAT ),
],
2021-10-11 16:10:47 +02:00
'all'
);
$res = [];
2012-09-12 18:09:38 +02:00
foreach ( $rows as $r ) {
$res [] = $r [ 'id' ];
}
2021-10-11 16:10:47 +02:00
2012-09-12 18:09:38 +02:00
return $res ;
2011-04-12 06:14:26 +02:00
}
2011-04-25 23:24:53 +02:00
2011-11-12 04:55:46 +01:00
/* Called when a show ' s duration is changed ( edited ) .
2011-11-15 15:20:33 +01:00
*
2011-11-12 04:55:46 +01:00
* @ param array $p_data
2011-11-15 15:20:33 +01:00
* array containing the POST data about the show from the
2011-11-12 04:55:46 +01:00
* browser .
2011-11-15 15:20:33 +01:00
*
2011-11-12 04:55:46 +01:00
*/
2012-07-16 03:17:13 +02:00
private function updateDurationTime ( $p_data )
{
2022-03-14 11:15:04 +01:00
// need to update cc_show_instances, cc_show_days
2012-07-16 03:17:13 +02:00
$con = Propel :: getConnection ();
2015-06-26 20:42:52 +02:00
$timestamp = gmdate ( DEFAULT_TIMESTAMP_FORMAT );
2011-04-25 23:24:53 +02:00
2021-10-11 16:10:47 +02:00
$stmt = $con -> prepare ( 'UPDATE cc_show_days '
2022-07-07 20:01:15 +02:00
. 'SET duration = :add_show_duration '
. 'WHERE show_id = :add_show_id' );
2021-10-11 16:10:47 +02:00
$stmt -> execute ([
2012-09-06 21:55:29 +02:00
':add_show_duration' => $p_data [ 'add_show_duration' ],
2021-10-11 16:10:47 +02:00
':add_show_id' => $p_data [ 'add_show_id' ],
]);
2012-09-06 23:23:39 +02:00
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 17:12:26 +02:00
UPDATE cc_show_instances
2012-09-06 23:23:39 +02:00
SET ends = starts + : add_show_duration :: INTERVAL
2012-09-06 22:17:14 +02:00
WHERE show_id = : show_id
2012-09-07 17:12:26 +02:00
AND ends > : timestamp :: TIMESTAMP
2012-09-06 22:17:14 +02:00
SQL ;
2021-10-11 16:10:47 +02:00
Application_Common_Database :: prepareAndExecute ( $sql , [
2012-09-06 23:23:39 +02:00
':add_show_duration' => $p_data [ 'add_show_duration' ],
':show_id' => $p_data [ 'add_show_id' ],
2022-07-07 20:01:15 +02:00
':timestamp' => $timestamp ,
], 'execute' );
2011-04-12 06:14:26 +02:00
}
2011-04-25 23:24:53 +02:00
2021-10-11 16:10:47 +02:00
public function getDuration ( $format = false )
2012-07-16 03:17:13 +02:00
{
2011-04-12 06:14:26 +02:00
$showDay = CcShowDaysQuery :: create () -> filterByDbShowId ( $this -> getId ()) -> findOne ();
2012-07-16 03:17:13 +02:00
if ( ! $format ) {
2011-10-25 22:49:44 +02:00
return $showDay -> getDbDuration ();
2011-06-03 20:53:01 +02:00
}
2021-10-11 16:10:47 +02:00
$info = explode ( ':' , $showDay -> getDbDuration ());
return str_pad ( intval ( $info [ 0 ]), 2 , '0' , STR_PAD_LEFT ) . 'h ' . str_pad ( intval ( $info [ 1 ]), 2 , '0' , STR_PAD_LEFT ) . 'm' ;
2011-04-12 06:14:26 +02:00
}
2011-04-25 23:24:53 +02:00
2012-07-16 03:17:13 +02:00
public function getShowDays ()
{
2012-09-07 20:33:08 +02:00
$showDays = CcShowDaysQuery :: create () -> filterByDbShowId (
2021-10-11 16:10:47 +02:00
$this -> getId ()
) -> find ();
$res = [];
2012-09-12 18:09:38 +02:00
foreach ( $showDays as $showDay ) {
$res [] = $showDay -> getDbDay ();
}
2021-10-11 16:10:47 +02:00
2012-09-12 18:09:38 +02:00
return $res ;
2011-04-12 06:14:26 +02:00
}
2011-04-25 23:24:53 +02:00
2011-11-23 18:47:44 +01:00
/* Only used for shows that aren ' t repeating .
*
2011-11-16 18:35:02 +01:00
* @ return Boolean : true if show has an instance , otherwise false . */
2012-07-16 03:17:13 +02:00
public function hasInstance ()
{
2021-10-11 16:10:47 +02:00
return ! is_null ( $this -> getInstance ());
2011-04-12 06:14:26 +02:00
}
2011-04-25 23:24:53 +02:00
2011-11-23 18:47:44 +01:00
/* Only used for shows that aren ' t repeating .
*
* @ return CcShowInstancesQuery : An propel object representing a
2011-11-16 18:35:02 +01:00
* row in the cc_show_instances table . */
2012-07-16 03:17:13 +02:00
public function getInstance ()
{
2021-10-11 16:10:47 +02:00
return CcShowInstancesQuery :: create ()
2011-11-16 18:35:02 +01:00
-> filterByDbShowId ( $this -> getId ())
2022-01-23 19:15:55 +01:00
-> findOne ();
2011-04-12 06:14:26 +02:00
}
2012-04-01 21:51:03 +02:00
2012-02-21 23:58:05 +01:00
/**
2021-10-11 16:10:47 +02:00
* returns info about live stream override info .
2012-02-21 23:58:05 +01:00
*/
2012-07-16 03:17:13 +02:00
public function getLiveStreamInfo ()
{
2021-10-11 16:10:47 +02:00
$info = [];
2012-09-07 21:12:46 +02:00
if ( $this -> getId () == null ) {
2012-02-21 23:58:05 +01:00
return $info ;
}
2021-10-11 16:10:47 +02:00
$ccShow = CcShowQuery :: create () -> findPK ( $this -> _showId );
$info [ 'custom_username' ] = $ccShow -> getDbLiveStreamUser ();
$info [ 'cb_airtime_auth' ] = $ccShow -> getDbLiveStreamUsingAirtimeAuth ();
$info [ 'cb_custom_auth' ] = $ccShow -> getDbLiveStreamUsingCustomAuth ();
$info [ 'custom_username' ] = $ccShow -> getDbLiveStreamUser ();
$info [ 'custom_password' ] = $ccShow -> getDbLiveStreamPass ();
return $info ;
2012-02-21 23:58:05 +01:00
}
2011-04-25 23:24:53 +02:00
2011-11-16 18:35:02 +01:00
/* Only used for shows that are repeating . Note that this will return
2011-11-23 18:47:44 +01:00
* true even for dates that only have a " modified " show instance ( does not
2011-11-18 18:20:25 +01:00
* check if the " modified_instance " column is set to true ) . This is intended
2011-11-23 18:47:44 +01:00
* behaviour .
*
* @ param $p_dateTime : Date for which we are checking if instance
2011-11-16 18:35:02 +01:00
* exists .
2011-11-23 18:47:44 +01:00
*
* @ return Boolean : true if show has an instance on $p_dateTime ,
2011-11-16 18:35:02 +01:00
* otherwise false . */
2012-07-16 03:17:13 +02:00
public function hasInstanceOnDate ( $p_dateTime )
{
2021-10-11 16:10:47 +02:00
return ! is_null ( $this -> getInstanceOnDate ( $p_dateTime ));
2011-04-12 06:14:26 +02:00
}
2011-04-25 23:24:53 +02:00
2011-11-16 18:35:02 +01:00
/* Only used for shows that are repeating . Note that this will return
2011-11-18 18:20:25 +01:00
* shows that have been " modified " ( does not check if the " modified_instance "
2011-11-16 18:35:02 +01:00
* column is set to true ) . This is intended behaviour .
2011-11-23 18:47:44 +01:00
*
2011-11-16 18:35:02 +01:00
* @ param $p_dateTime : Date for which we are getting an instance .
2011-11-23 18:47:44 +01:00
*
* @ return CcShowInstancesQuery : An propel object representing a
2011-11-16 18:35:02 +01:00
* row in the cc_show_instances table . */
2012-07-16 03:17:13 +02:00
public function getInstanceOnDate ( $p_dateTime )
{
2015-06-26 20:42:52 +02:00
$timestamp = $p_dateTime -> format ( DEFAULT_TIMESTAMP_FORMAT );
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 21:29:30 +02:00
SELECT id
FROM cc_show_instances
2012-09-12 18:16:53 +02:00
WHERE date ( starts ) = date ( : timestamp :: TIMESTAMP )
2012-09-07 21:29:30 +02:00
AND show_id = : showId
AND rebroadcast = 0 ;
SQL ;
2021-10-11 16:10:47 +02:00
2012-09-07 21:29:30 +02:00
try {
2021-10-11 16:10:47 +02:00
$row = Application_Common_Database :: prepareAndExecute (
$sql ,
2022-07-07 20:01:15 +02:00
[
':showId' => $this -> getId (),
':timestamp' => $timestamp ,
],
2021-10-11 16:10:47 +02:00
'column'
);
2012-09-07 21:29:30 +02:00
return CcShowInstancesQuery :: create ()
2022-01-23 19:15:55 +01:00
-> findPk ( $row );
2012-09-07 21:29:30 +02:00
} catch ( Exception $e ) {
return null ;
}
2011-04-12 06:14:26 +02:00
}
2021-10-11 16:10:47 +02:00
2014-08-15 21:41:55 +02:00
/**
* Creates show instances that are scheduled after the shows_populated_until
* value in cc_pref . If the show instances are linked their show content will
* get filled .
2021-10-11 16:10:47 +02:00
*
2014-08-15 21:41:55 +02:00
* This can occur when a user is viewing the next day / week / month in the
* calendar or when pypo is requesting the schedule after the shows_populated_until
* date and time .
2021-10-11 16:10:47 +02:00
*
* @ param mixed $needScheduleUntil
2014-08-15 21:41:55 +02:00
*/
2014-08-15 21:35:58 +02:00
public static function createAndFillShowInstancesPastPopulatedUntilDate ( $needScheduleUntil )
{
2015-09-02 16:40:38 +02:00
$con = Propel :: getConnection ( CcPrefPeer :: DATABASE_NAME );
2021-10-11 16:10:47 +02:00
2015-09-02 16:40:38 +02:00
try {
$con -> beginTransaction ();
2022-03-14 11:15:04 +01:00
// It is extremely important that we increase the transaction isolation level, so that if two
// requests cause the show schedule to be generated at the same time, one will be rolled back.
2021-10-11 16:10:47 +02:00
$con -> exec ( 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE' );
2015-09-02 16:40:38 +02:00
2022-03-14 11:15:04 +01:00
// UTC DateTime object
2015-09-02 16:40:38 +02:00
$showsPopUntil = Application_Model_Preference :: GetShowsPopulatedUntil ();
2022-03-14 11:15:04 +01:00
// if application is requesting shows past our previous populated until date, generate shows up until this point.
2015-09-02 16:40:38 +02:00
if ( is_null ( $showsPopUntil ) || $showsPopUntil -> getTimestamp () < $needScheduleUntil -> getTimestamp ()) {
$service_show = new Application_Service_ShowService ();
$ccShow = $service_show -> delegateInstanceCreation ( null , $needScheduleUntil , true );
Application_Model_Preference :: SetShowsPopulatedUntil ( $needScheduleUntil );
}
$con -> commit ();
} catch ( Exception $e ) {
$con -> rollBack ();
2022-03-14 11:15:04 +01:00
// throw $e;
2021-10-11 16:10:47 +02:00
Logging :: warn ( ' Did not create show instances due to transaction error . This is usually safe
and caused by two concurrent transactions . ' . $e -> getMessage ());
2014-08-15 21:35:58 +02:00
}
}
2011-04-25 23:24:53 +02:00
2011-03-30 23:27:14 +02:00
/**
2011-11-11 20:54:08 +01:00
* Get all the show instances in the given time range ( inclusive ) .
2011-03-30 23:27:14 +02:00
*
2023-05-25 15:06:18 +02:00
* @ param dateTime $start_timestamp
* In UTC time
* @ param dateTime $end_timestamp
* In UTC time
* @ param bool $onlyRecord
* @ param int $showId
* limits the results to instances of a given showId only
2021-10-11 16:10:47 +02:00
*
2011-10-24 19:46:16 +02:00
* @ return array
2011-03-30 23:27:14 +02:00
*/
2021-10-11 16:10:47 +02:00
public static function getShows ( $start_timestamp , $end_timestamp , $onlyRecord = false , $showId = null )
2011-03-30 23:27:14 +02:00
{
2014-08-15 21:35:58 +02:00
self :: createAndFillShowInstancesPastPopulatedUntilDate ( $end_timestamp );
2011-03-22 14:55:33 +01:00
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 22:26:05 +02:00
SELECT si1 . starts AS starts ,
si1 . ends AS ends ,
si1 . record AS record ,
si1 . rebroadcast AS rebroadcast ,
si2 . starts AS parent_starts ,
si1 . instance_id AS record_id ,
si1 . show_id AS show_id ,
show . name AS name ,
2014-09-19 00:21:27 +02:00
show . description AS description ,
2012-09-07 22:26:05 +02:00
show . color AS color ,
show . background_color AS background_color ,
2014-09-17 00:28:39 +02:00
show . image_path AS image_path ,
2013-05-09 18:14:49 +02:00
show . linked AS linked ,
2012-09-07 22:26:05 +02:00
si1 . file_id AS file_id ,
si1 . id AS instance_id ,
2014-09-19 19:00:44 +02:00
si1 . description AS instance_description ,
2012-09-07 22:26:05 +02:00
si1 . created AS created ,
si1 . last_scheduled AS last_scheduled ,
2021-01-06 13:20:23 +01:00
si1 . time_filled AS time_filled
2012-09-07 23:15:49 +02:00
FROM cc_show_instances AS si1
LEFT JOIN cc_show_instances AS si2 ON si1 . instance_id = si2 . id
LEFT JOIN cc_show AS show ON show . id = si1 . show_id
2012-09-07 22:26:05 +02:00
WHERE si1 . modified_instance = FALSE
SQL ;
2022-03-14 11:15:04 +01:00
// only want shows that are starting at the time or later.
2015-06-26 20:42:52 +02:00
$start_string = $start_timestamp -> format ( DEFAULT_TIMESTAMP_FORMAT );
$end_string = $end_timestamp -> format ( DEFAULT_TIMESTAMP_FORMAT );
2014-11-17 21:53:31 +01:00
2021-10-11 16:10:47 +02:00
$params = [];
2014-11-17 21:53:31 +01:00
if ( $showId ) {
2021-10-11 16:10:47 +02:00
$sql .= ' AND (si1.show_id = :show_id)' ;
$params [ ':show_id' ] = $showId ;
2014-11-17 21:53:31 +01:00
}
2011-10-24 19:46:16 +02:00
if ( $onlyRecord ) {
2021-10-11 16:10:47 +02:00
$sql .= ' AND (si1.starts >= :start::TIMESTAMP AND si1.starts < :end::TIMESTAMP)' ;
$sql .= ' AND (si1.record = 1)' ;
2011-10-24 19:46:16 +02:00
2014-11-17 21:53:31 +01:00
$params [ ':start' ] = $start_string ;
$params [ ':end' ] = $end_string ;
2012-09-07 22:26:05 +02:00
2021-10-11 16:10:47 +02:00
return Application_Common_Database :: prepareAndExecute ( $sql , $params , 'all' );
}
$sql .= ' ' . <<< 'SQL'
2012-09-07 23:23:32 +02:00
AND (( si1 . starts >= : start1 :: TIMESTAMP AND si1 . starts < : end1 :: TIMESTAMP )
OR ( si1 . ends > : start2 :: TIMESTAMP AND si1 . ends <= : end2 :: TIMESTAMP )
OR ( si1 . starts <= : start3 :: TIMESTAMP AND si1 . ends >= : end3 :: TIMESTAMP ))
2013-08-29 21:37:33 +02:00
ORDER BY si1 . starts
2012-09-07 23:23:32 +02:00
SQL ;
2021-10-11 16:10:47 +02:00
$params = array_merge (
$params ,
[
'start1' => $start_string ,
'start2' => $start_string ,
'start3' => $start_string ,
'end1' => $end_string ,
'end2' => $end_string ,
'end3' => $end_string ,
]
);
return Application_Common_Database :: prepareAndExecute ( $sql , $params , 'all' );
2011-10-24 19:46:16 +02:00
}
private static function setNextPop ( $next_date , $show_id , $day )
{
2021-10-11 16:10:47 +02:00
$nextInfo = explode ( ' ' , $next_date );
2011-10-24 19:46:16 +02:00
$repeatInfo = CcShowDaysQuery :: create ()
-> filterByDbShowId ( $show_id )
-> filterByDbDay ( $day )
2022-01-23 19:15:55 +01:00
-> findOne ();
2011-10-24 19:46:16 +02:00
$repeatInfo -> setDbNextPopDate ( $nextInfo [ 0 ])
2022-01-23 19:15:55 +01:00
-> save ();
2011-02-05 22:00:05 +01:00
}
2010-12-07 20:19:27 +01:00
2011-03-30 23:27:14 +02:00
/**
2023-05-25 15:06:18 +02:00
* @ param mixed $p_start
* @ param mixed $p_end
* @ param mixed $p_editable
2011-03-30 23:27:14 +02:00
*/
2021-10-11 16:10:47 +02:00
public static function & getFullCalendarEvents ( $p_start , $p_end , $p_editable = false )
2011-03-30 23:27:14 +02:00
{
2021-10-11 16:10:47 +02:00
$events = [];
2012-02-22 20:32:59 +01:00
$interval = $p_start -> diff ( $p_end );
2021-10-11 16:10:47 +02:00
$days = $interval -> format ( '%a' );
$shows = Application_Model_Show :: getShows ( $p_start , $p_end );
2012-10-19 19:22:00 +02:00
$content_count = Application_Model_ShowInstance :: getContentCount (
2021-10-11 16:10:47 +02:00
$p_start ,
$p_end
);
2013-01-23 22:12:16 +01:00
$isFull = Application_Model_ShowInstance :: getIsFull ( $p_start , $p_end );
2017-11-28 21:12:27 +01:00
$hasAutoPlaylist = Application_Model_ShowInstance :: getShowHasAutoplaylist ( $p_start , $p_end );
2013-12-04 21:06:07 +01:00
$displayTimezone = new DateTimeZone ( Application_Model_Preference :: GetUserTimezone ());
2021-10-11 16:10:47 +02:00
$utcTimezone = new DateTimeZone ( 'UTC' );
$now = new DateTime ( 'now' , $utcTimezone );
2012-07-23 01:18:53 +02:00
2013-01-24 18:00:31 +01:00
foreach ( $shows as & $show ) {
2021-10-11 16:10:47 +02:00
$options = [];
2011-06-06 20:05:35 +02:00
2021-10-11 16:10:47 +02:00
$options [ 'percent' ] = Application_Model_Show :: getPercentScheduled ( $show [ 'starts' ], $show [ 'ends' ], $show [ 'time_filled' ]);
2012-07-11 00:51:32 +02:00
2021-10-11 16:10:47 +02:00
if ( isset ( $show [ 'parent_starts' ])) {
$parentStartsDT = new DateTime ( $show [ 'parent_starts' ], $utcTimezone );
2012-05-22 17:51:53 +02:00
}
2012-09-04 20:55:23 +02:00
2021-10-11 16:10:47 +02:00
$startsDT = DateTime :: createFromFormat (
'Y-m-d G:i:s' ,
$show [ 'starts' ],
$utcTimezone
);
$endsDT = DateTime :: createFromFormat (
'Y-m-d G:i:s' ,
$show [ 'ends' ],
$utcTimezone
);
if ( $p_editable ) {
if ( $show [ 'record' ] && $now > $startsDT ) {
$options [ 'editable' ] = false ;
2022-07-07 20:01:15 +02:00
} elseif (
$show [ 'rebroadcast' ]
&& $now > $parentStartsDT
) {
2021-10-11 16:10:47 +02:00
$options [ 'editable' ] = false ;
2013-01-23 23:33:34 +01:00
} elseif ( $now < $endsDT ) {
2021-10-11 16:10:47 +02:00
$options [ 'editable' ] = true ;
2012-09-04 20:55:23 +02:00
}
2011-04-06 23:53:09 +02:00
}
2012-08-29 16:58:03 +02:00
2013-12-04 20:13:19 +01:00
$startsDT -> setTimezone ( $displayTimezone );
$endsDT -> setTimezone ( $displayTimezone );
2013-01-23 23:33:34 +01:00
2021-10-11 16:10:47 +02:00
$options [ 'show_empty' ] = ( array_key_exists (
$show [ 'instance_id' ],
$content_count
)) ? 0 : 1 ;
2013-01-23 22:12:16 +01:00
2013-12-14 00:27:14 +01:00
if ( array_key_exists ( $show [ 'instance_id' ], $isFull )) {
2021-10-11 16:10:47 +02:00
$options [ 'show_partial_filled' ] = ! $isFull [ $show [ 'instance_id' ]];
2013-12-14 00:27:14 +01:00
} else {
2021-10-11 16:10:47 +02:00
$options [ 'show_partial_filled' ] = true ;
2013-12-14 00:27:14 +01:00
}
2017-11-28 21:12:27 +01:00
if ( array_key_exists ( $show [ 'instance_id' ], $hasAutoPlaylist )) {
2021-10-11 16:10:47 +02:00
$options [ 'show_has_auto_playlist' ] = true ;
2018-01-04 04:01:46 +01:00
} else {
2021-10-11 16:10:47 +02:00
$options [ 'show_has_auto_playlist' ] = false ;
2017-11-28 21:12:27 +01:00
}
2012-09-04 20:55:23 +02:00
2021-10-11 16:10:47 +02:00
$event = [];
$event [ 'id' ] = intval ( $show [ 'instance_id' ]);
$event [ 'title' ] = $show [ 'name' ];
$event [ 'start' ] = $startsDT -> format ( DEFAULT_TIMESTAMP_FORMAT );
$event [ 'end' ] = $endsDT -> format ( DEFAULT_TIMESTAMP_FORMAT );
$event [ 'allDay' ] = false ;
$event [ 'showId' ] = intval ( $show [ 'show_id' ]);
$event [ 'linked' ] = intval ( $show [ 'linked' ]);
$event [ 'record' ] = intval ( $show [ 'record' ]);
$event [ 'rebroadcast' ] = intval ( $show [ 'rebroadcast' ]);
2022-03-14 11:15:04 +01:00
// for putting the now playing icon on the show.
2013-10-12 00:15:12 +02:00
if ( $now > $startsDT && $now < $endsDT ) {
2021-10-11 16:10:47 +02:00
$event [ 'nowPlaying' ] = true ;
} else {
$event [ 'nowPlaying' ] = false ;
2013-10-12 00:15:12 +02:00
}
2013-01-23 23:33:34 +01:00
2021-10-11 16:10:47 +02:00
if ( ! empty ( $show [ 'background_color' ])) {
$event [ 'color' ] = '#' . $show [ 'background_color' ];
2015-08-12 18:55:39 +02:00
} else {
2022-03-14 11:15:04 +01:00
$event [ 'color' ] = '#' . self :: getDefaultBackgroundColor ( $startsDT ); // DEFAULT_SHOW_COLOR;
2013-01-23 23:33:34 +01:00
}
2022-03-14 11:15:04 +01:00
// event colouring
2021-10-11 16:10:47 +02:00
if ( $show [ 'color' ] != '' ) {
$event [ 'textColor' ] = '#' . $show [ 'color' ];
2015-09-25 23:56:29 +02:00
} else {
2021-10-11 16:10:47 +02:00
$bg = $event [ 'color' ];
2022-03-14 11:15:04 +01:00
// Calculate the text colour (black or white) based on the brightness of the background.
2015-09-25 23:56:29 +02:00
$r = intval ( substr ( $bg , 1 , 2 ), 16 );
$g = intval ( substr ( $bg , 3 , 2 ), 16 );
$b = intval ( substr ( $bg , 5 , 2 ), 16 );
2021-10-11 16:10:47 +02:00
$brightness = 0.299 * floatval ( $r ) + 0.587 * floatval ( $g ) + 0.114 * floatval ( $b );
2015-09-25 23:56:29 +02:00
if ( $brightness > 130 ) {
2021-10-11 16:10:47 +02:00
$event [ 'textColor' ] = '#000000' ;
2015-09-25 23:56:29 +02:00
} else {
2021-10-11 16:10:47 +02:00
$event [ 'textColor' ] = '#fcfcfc' ;
2015-09-25 23:56:29 +02:00
}
}
2013-01-23 23:33:34 +01:00
foreach ( $options as $key => $value ) {
$event [ $key ] = $value ;
}
$events [] = $event ;
}
2021-10-11 16:10:47 +02:00
2011-02-05 22:00:05 +01:00
return $events ;
}
2012-04-01 21:51:03 +02:00
2015-08-29 00:16:55 +02:00
/** Get a palettized colour for the show. */
2021-10-11 16:10:47 +02:00
private static function getDefaultBackgroundColor ( $date )
{
2015-09-25 23:56:29 +02:00
$basePalette = [ 'A22BE8' , '2FFF8D' , 'FF743C' , '2ED4FF' , 'E8D82B' ];
// 'B23F11', 'FF7E4A', 'FF6C31'
/*
2015-08-29 00:16:55 +02:00
$palette = [[ '42d5a1' , '56bd99' , '65ab93' , '7b938b' ],
[ '42a4d5' , '569bbd' , '6594ab' , '7b8b93' ],
[ '4264d5' , '566fbd' , '6576ab' , '7b8193' ]];
2015-09-25 23:56:29 +02:00
*/
$palette = [];
2021-10-11 16:10:47 +02:00
for ( $baseColorIdx = 0 ; $baseColorIdx < count ( $basePalette ); ++ $baseColorIdx ) {
2015-09-25 23:56:29 +02:00
$dayPalette = [];
for ( $shade = 0.0 ; $shade < 0.8 ; $shade += 0.1 ) {
$origColour = $basePalette [ $baseColorIdx ];
$r = intval ( substr ( $origColour , 0 , 2 ), 16 );
$g = intval ( substr ( $origColour , 2 , 2 ), 16 );
$b = intval ( substr ( $origColour , 4 , 2 ), 16 );
$r = floatval ( $r ) * ( 1.0 - $shade );
$g = floatval ( $g ) * ( 1.0 - $shade );
$b = floatval ( $b ) * ( 1.0 - $shade );
2021-10-11 16:10:47 +02:00
$color = sprintf ( '%02x%02x%02x' , $r , $g , $b );
2015-09-25 23:56:29 +02:00
array_push ( $dayPalette , $color );
}
array_push ( $palette , $dayPalette );
}
2015-08-29 00:16:55 +02:00
2022-03-14 11:15:04 +01:00
// $hashValue = (md5($date->format('d'))[0] % $cols) + ((intval($date->format('h'))/24) % $rows);
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
$row = intval ( $date -> format ( 'w' )) % count ( $palette );
2015-08-29 00:16:55 +02:00
$foo = $date -> format ( 'H' );
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
$col = intval ( intval ( $date -> format ( 'H' )) / 24.0 * count ( $palette [ 0 ]));
2023-08-15 18:28:18 +02:00
2022-03-14 11:15:04 +01:00
// $color = $palette[$hashValue % sizeof($palette)];
2021-10-11 16:10:47 +02:00
return $palette [ $row ][ $col ];
2015-08-29 00:16:55 +02:00
}
2012-02-22 20:32:59 +01:00
/**
* Calculates the percentage of a show scheduled given the start and end times in date / time format
* and the time_filled as the total time the schow is scheduled for in time format .
2021-10-11 16:10:47 +02:00
*
2013-12-13 21:03:02 +01:00
* TODO when using propel properly this should be a method on the propel show instance model .
2021-10-11 16:10:47 +02:00
*
* @ param mixed $p_starts
* @ param mixed $p_ends
* @ param mixed $p_time_filled
*/
2012-07-16 03:17:13 +02:00
private static function getPercentScheduled ( $p_starts , $p_ends , $p_time_filled )
{
2022-02-08 10:14:59 +01:00
$utcTimezone = new DateTimeZone ( 'UTC' );
2014-11-17 21:53:31 +01:00
$startDt = new DateTime ( $p_starts , $utcTimezone );
$endDt = new DateTime ( $p_ends , $utcTimezone );
2021-10-11 16:10:47 +02:00
$durationSeconds = intval ( $endDt -> format ( 'U' )) - intval ( $startDt -> format ( 'U' ));
2013-12-13 21:03:02 +01:00
$time_filled = Application_Common_DateHelper :: playlistTimeToSeconds ( $p_time_filled );
2022-03-14 11:15:04 +01:00
if ( $durationSeconds != 0 ) { // Prevent division by zero if the show duration somehow becomes zero.
2021-10-11 16:10:47 +02:00
$percent = ceil (( $time_filled / $durationSeconds ) * 100 );
2013-12-13 22:10:36 +01:00
} else {
$percent = 0 ;
}
2021-10-11 16:10:47 +02:00
2012-02-22 20:32:59 +01:00
return $percent ;
}
2010-12-10 18:15:17 +01:00
CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time,
the SQL query was also comparing UTC timestamp with local timestamps,
causing widgets to display shows in the wrong day, etc.
Another problem was that "On air today" widget was simply calling
GetNextShows which returns shows within next 48 hours.
Fixed by:
1. Under models/Show.php:
In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions,
added code to convert UTC timestamp to local timestamp or vice versa,
depending on which one is more suitable, in SQL queries, thus
removing inconsistency in timezones. Also, before returning query result,
added code to convert result to local timezone.
In GetNextShows, added an optional parameter endTime to limit the interval
of shows to get. This is useful for the "On air today" widget.
2. Under models/DateHelper.php:
Added a few timezone functions to help converting timezones easier in Show.php.
3. Under controller/ApiController.php:
Added todayInfoAction which is to be used by "On Air Today" widget.
2011-11-04 21:57:24 +01:00
/**
2011-11-22 00:03:56 +01:00
* Given time $timeNow , returns the show being played right now .
* Times are all in UTC time .
2011-11-15 15:20:33 +01:00
*
2021-10-11 16:10:47 +02:00
* @ param string $timeNow - current time ( in UTC )
*
* @ return array - show being played right now
CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time,
the SQL query was also comparing UTC timestamp with local timestamps,
causing widgets to display shows in the wrong day, etc.
Another problem was that "On air today" widget was simply calling
GetNextShows which returns shows within next 48 hours.
Fixed by:
1. Under models/Show.php:
In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions,
added code to convert UTC timestamp to local timestamp or vice versa,
depending on which one is more suitable, in SQL queries, thus
removing inconsistency in timezones. Also, before returning query result,
added code to convert result to local timezone.
In GetNextShows, added an optional parameter endTime to limit the interval
of shows to get. This is useful for the "On air today" widget.
2. Under models/DateHelper.php:
Added a few timezone functions to help converting timezones easier in Show.php.
3. Under controller/ApiController.php:
Added todayInfoAction which is to be used by "On Air Today" widget.
2011-11-04 21:57:24 +01:00
*/
2021-10-11 16:10:47 +02:00
public static function getCurrentShow ( $timeNow = null )
2011-03-22 14:55:33 +01:00
{
2012-04-01 21:51:03 +02:00
$con = Propel :: getConnection ();
2012-07-16 03:17:13 +02:00
if ( $timeNow == null ) {
2015-06-26 20:42:52 +02:00
$timeNow = gmdate ( DEFAULT_TIMESTAMP_FORMAT );
2012-03-02 22:55:11 +01:00
}
2022-03-14 11:15:04 +01:00
// TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-04 19:12:35 +02:00
SELECT si . starts AS start_timestamp ,
si . ends AS end_timestamp ,
s . name ,
2014-09-19 00:21:27 +02:00
s . description ,
2012-09-04 19:12:35 +02:00
s . id ,
si . id AS instance_id ,
2014-09-19 19:00:44 +02:00
si . description AS instance_description ,
2012-09-04 19:12:35 +02:00
si . record ,
s . url ,
2014-09-17 00:28:39 +02:00
s . image_path ,
2012-09-04 19:12:35 +02:00
starts ,
ends
2012-09-05 22:21:59 +02:00
FROM cc_show_instances si
2012-09-05 22:06:10 +02:00
LEFT JOIN cc_show s
2012-09-06 22:18:28 +02:00
ON si . show_id = s . id
2012-09-04 19:12:35 +02:00
WHERE si . show_id = s . id
2012-09-04 20:54:34 +02:00
AND si . starts <= : timeNow1 :: timestamp
AND si . ends > : timeNow2 :: timestamp
AND modified_instance != TRUE
2012-09-04 19:12:35 +02:00
SQL ;
$stmt = $con -> prepare ( $sql );
$stmt -> bindParam ( ':timeNow1' , $timeNow );
$stmt -> bindParam ( ':timeNow2' , $timeNow );
if ( $stmt -> execute ()) {
$rows = $stmt -> fetchAll ();
} else {
$msg = implode ( ',' , $stmt -> errorInfo ());
2021-10-11 16:10:47 +02:00
throw new Exception ( " Error: { $msg } " );
2012-09-04 19:12:35 +02:00
}
2012-08-29 16:58:03 +02:00
2011-02-07 02:12:56 +01:00
return $rows ;
2011-02-05 00:22:15 +01:00
}
2011-03-22 14:55:33 +01:00
2014-10-24 21:11:27 +02:00
/**
* Gets the current show , previous and next with an n - day window from
* the given timeNow , so timeNow - 2 days and timeNow + $daysToRetrieve days .
2021-10-11 16:10:47 +02:00
*
2023-05-25 15:06:18 +02:00
* @ param $utcNow A DateTime object containing the current time in UTC
2021-10-11 16:10:47 +02:00
* @ param mixed $utcEndStr
* @ param mixed $showsToRetrieve
*
* @ return An array containing the previous show ,
* current show , and next show
2014-10-24 21:11:27 +02:00
*/
public static function getPrevCurrentNext ( $utcNow , $utcEndStr , $showsToRetrieve )
{
2022-03-14 11:15:04 +01:00
$timeZone = new DateTimeZone ( 'UTC' ); // This function works entirely in UTC.
2021-10-11 16:10:47 +02:00
assert ( get_class ( $utcNow ) === 'DateTime' );
2014-10-24 21:11:27 +02:00
assert ( $utcNow -> getTimeZone () == $timeZone );
2021-10-11 16:10:47 +02:00
2014-10-24 21:11:27 +02:00
$CC_CONFIG = Config :: getConfig ();
$con = Propel :: getConnection ();
2021-10-11 16:10:47 +02:00
// This will fetch the currently playing show first, then any
// upcoming shows within our interval, and finally move on to
2014-10-24 21:11:27 +02:00
// previous shows in the past 2 days.
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2014-10-24 21:11:27 +02:00
SELECT s . name ,
s . description ,
s . genre ,
s . id ,
si . id AS instance_id ,
si . record ,
s . url ,
s . image_path ,
starts ,
ends
FROM cc_show_instances si
LEFT JOIN cc_show s
ON si . show_id = s . id
WHERE si . show_id = s . id
AND si . starts >= : timeNow :: timestamp - INTERVAL '2 days'
AND si . starts < : timeEnd :: timestamp
AND modified_instance != TRUE
2015-06-08 22:38:17 +02:00
ORDER BY
CASE
2014-10-24 21:11:27 +02:00
WHEN si . ends > : timeNow :: timestamp
AND si . starts < : timeNow :: timestamp THEN 1
WHEN si . starts > : timeNow :: timestamp THEN 2
ELSE 3
2015-06-08 22:38:17 +02:00
END , si . starts
2014-10-24 21:11:27 +02:00
LIMIT : lim
SQL ;
$stmt = $con -> prepare ( $sql );
2021-10-11 16:10:47 +02:00
2015-06-26 20:42:52 +02:00
$utcNowStr = $utcNow -> format ( DEFAULT_TIMESTAMP_FORMAT );
2014-10-24 21:11:27 +02:00
$stmt -> bindValue ( ':timeNow' , $utcNowStr );
$stmt -> bindValue ( ':timeEnd' , $utcEndStr );
$stmt -> bindValue ( ':lim' , $showsToRetrieve );
2021-10-11 16:10:47 +02:00
2014-10-24 21:11:27 +02:00
if ( $stmt -> execute ()) {
// use PDO::FETCH_ASSOC to only get the associative values
// note that fetchAll() defaults to PDO::FETCH_BOTH, which we don't want
$rows = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
} else {
$msg = implode ( ',' , $stmt -> errorInfo ());
2021-10-11 16:10:47 +02:00
throw new Exception ( " Error: { $msg } " );
2014-10-24 21:11:27 +02:00
}
$numberOfRows = count ( $rows );
2021-10-11 16:10:47 +02:00
$results [ 'previousShow' ] = [];
$results [ 'currentShow' ] = null ;
$results [ 'nextShow' ] = [];
2014-10-24 21:11:27 +02:00
for ( $i = 0 ; $i < $numberOfRows ; ++ $i ) {
// all shows start/end times are stored in the database as UTC.
$showStartTime = new DateTime ( $rows [ $i ][ 'starts' ], $timeZone );
2021-10-11 16:10:47 +02:00
$showEndTime = new DateTime ( $rows [ $i ][ 'ends' ], $timeZone );
2014-10-24 21:11:27 +02:00
// Find the show that is within the current time.
2021-10-11 16:10:47 +02:00
if (( $showStartTime <= $utcNow ) && ( $showEndTime > $utcNow )) {
2014-10-24 21:11:27 +02:00
$results [ 'currentShow' ] = $rows [ $i ];
2021-10-11 16:10:47 +02:00
} elseif ( $showEndTime < $utcNow ) {
2014-10-24 21:11:27 +02:00
array_push ( $results [ 'previousShow' ], $rows [ $i ]);
2021-10-11 16:10:47 +02:00
} elseif ( $showStartTime > $utcNow ) {
2014-10-24 21:11:27 +02:00
array_push ( $results [ 'nextShow' ], $rows [ $i ]);
}
}
return $results ;
}
2021-10-11 16:10:47 +02:00
2012-03-13 15:21:01 +01:00
/**
2012-07-10 16:36:53 +02:00
* Gets the current show , previous and next with an 2 day window from
* the given timeNow , so timeNow - 2 days and timeNow + 2 days .
2014-10-24 21:11:27 +02:00
*
2021-10-11 16:10:47 +02:00
* @ param $utcNow A DateTime object containing the current time in UTC
*
2014-10-24 21:11:27 +02:00
* @ return An array ( with stupid sub - arrays ) containing the previous show id ,
2021-10-11 16:10:47 +02:00
* current show id , and next show id
*
2014-10-27 20:52:58 +01:00
* @ deprecated
2012-03-13 15:21:01 +01:00
*/
2014-10-24 21:11:27 +02:00
public static function getPrevCurrentNextOld ( $utcNow )
2012-03-13 15:21:01 +01:00
{
2022-03-14 11:15:04 +01:00
$timeZone = new DateTimeZone ( 'UTC' ); // This function works entirely in UTC.
2021-10-11 16:10:47 +02:00
assert ( get_class ( $utcNow ) === 'DateTime' );
2013-12-12 00:20:40 +01:00
assert ( $utcNow -> getTimeZone () == $timeZone );
2021-10-11 16:10:47 +02:00
2013-01-14 22:16:14 +01:00
$CC_CONFIG = Config :: getConfig ();
2012-04-01 21:51:03 +02:00
$con = Propel :: getConnection ();
2014-09-17 00:28:39 +02:00
2022-03-14 11:15:04 +01:00
// TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-04 19:12:35 +02:00
SELECT si . starts AS start_timestamp ,
si . ends AS end_timestamp ,
s . name ,
2014-09-19 00:21:27 +02:00
s . description ,
2012-09-04 19:12:35 +02:00
s . id ,
si . id AS instance_id ,
si . record ,
s . url ,
2014-09-17 00:28:39 +02:00
s . image_path ,
2012-09-04 19:12:35 +02:00
starts ,
ends
2012-09-05 22:21:59 +02:00
FROM cc_show_instances si
2012-09-05 22:06:10 +02:00
LEFT JOIN cc_show s
2012-09-06 22:18:28 +02:00
ON si . show_id = s . id
2012-09-04 19:12:35 +02:00
WHERE si . show_id = s . id
2012-09-04 20:54:34 +02:00
AND si . starts > : timeNow1 :: timestamp - INTERVAL '2 days'
AND si . ends < : timeNow2 :: timestamp + INTERVAL '2 days'
2012-09-04 19:12:35 +02:00
AND modified_instance != TRUE
ORDER BY si . starts
SQL ;
2021-10-11 16:10:47 +02:00
2012-09-04 19:12:35 +02:00
$stmt = $con -> prepare ( $sql );
2021-10-11 16:10:47 +02:00
2015-06-26 20:42:52 +02:00
$utcNowStr = $utcNow -> format ( DEFAULT_TIMESTAMP_FORMAT );
2013-12-12 00:20:40 +01:00
$stmt -> bindValue ( ':timeNow1' , $utcNowStr );
$stmt -> bindValue ( ':timeNow2' , $utcNowStr );
2021-10-11 16:10:47 +02:00
2012-09-04 19:12:35 +02:00
if ( $stmt -> execute ()) {
2014-10-24 21:11:27 +02:00
$rows = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
2012-09-04 19:12:35 +02:00
} else {
$msg = implode ( ',' , $stmt -> errorInfo ());
2021-10-11 16:10:47 +02:00
throw new Exception ( " Error: { $msg } " );
2012-09-04 19:12:35 +02:00
}
2021-10-11 16:10:47 +02:00
2012-03-13 15:21:01 +01:00
$numberOfRows = count ( $rows );
2021-10-11 16:10:47 +02:00
$results [ 'previousShow' ] = [];
$results [ 'currentShow' ] = [];
$results [ 'nextShow' ] = [];
2012-07-10 16:36:53 +02:00
for ( $i = 0 ; $i < $numberOfRows ; ++ $i ) {
2022-03-14 11:15:04 +01:00
// All shows start/end times are stored in the database as UTC.
2013-12-12 00:20:40 +01:00
$showStartTime = new DateTime ( $rows [ $i ][ 'starts' ], $timeZone );
2021-10-11 16:10:47 +02:00
$showEndTime = new DateTime ( $rows [ $i ][ 'ends' ], $timeZone );
2022-03-14 11:15:04 +01:00
// Find the show that is within the current time.
2021-10-11 16:10:47 +02:00
if (( $showStartTime <= $utcNow ) && ( $showEndTime > $utcNow )) {
if ( $i - 1 >= 0 ) {
$results [ 'previousShow' ][ 0 ] = [
'id' => $rows [ $i - 1 ][ 'id' ],
'instance_id' => $rows [ $i - 1 ][ 'instance_id' ],
'name' => $rows [ $i - 1 ][ 'name' ],
'description' => $rows [ $i - 1 ][ 'description' ],
'url' => $rows [ $i - 1 ][ 'url' ],
'start_timestamp' => $rows [ $i - 1 ][ 'start_timestamp' ],
'end_timestamp' => $rows [ $i - 1 ][ 'end_timestamp' ],
'starts' => $rows [ $i - 1 ][ 'starts' ],
'ends' => $rows [ $i - 1 ][ 'ends' ],
'record' => $rows [ $i - 1 ][ 'record' ],
'image_path' => $rows [ $i - 1 ][ 'image_path' ],
2022-07-07 20:01:15 +02:00
'type' => 'show' ,
];
2012-03-13 15:21:01 +01:00
}
2021-10-11 16:10:47 +02:00
$results [ 'currentShow' ][ 0 ] = $rows [ $i ];
if ( isset ( $rows [ $i + 1 ])) {
$results [ 'nextShow' ][ 0 ] = [
'id' => $rows [ $i + 1 ][ 'id' ],
'instance_id' => $rows [ $i + 1 ][ 'instance_id' ],
'name' => $rows [ $i + 1 ][ 'name' ],
'description' => $rows [ $i + 1 ][ 'description' ],
'url' => $rows [ $i + 1 ][ 'url' ],
'start_timestamp' => $rows [ $i + 1 ][ 'start_timestamp' ],
'end_timestamp' => $rows [ $i + 1 ][ 'end_timestamp' ],
'starts' => $rows [ $i + 1 ][ 'starts' ],
'ends' => $rows [ $i + 1 ][ 'ends' ],
'record' => $rows [ $i + 1 ][ 'record' ],
'image_path' => $rows [ $i + 1 ][ 'image_path' ],
2022-07-07 20:01:15 +02:00
'type' => 'show' ,
];
2012-03-13 15:21:01 +01:00
}
2021-10-11 16:10:47 +02:00
2012-03-13 15:21:01 +01:00
break ;
}
2022-03-14 11:15:04 +01:00
// Previous is any row that ends after time now capture it in case we need it later.
2021-10-11 16:10:47 +02:00
if ( $showEndTime < $utcNow ) {
2012-03-13 22:46:13 +01:00
$previousShowIndex = $i ;
2012-03-13 15:21:01 +01:00
}
2022-03-14 11:15:04 +01:00
// if we hit this we know we've gone to far and can stop looping.
2013-12-12 00:20:40 +01:00
if ( $showStartTime > $utcNow ) {
2021-10-11 16:10:47 +02:00
$results [ 'nextShow' ][ 0 ] = [
'id' => $rows [ $i ][ 'id' ],
'instance_id' => $rows [ $i ][ 'instance_id' ],
'name' => $rows [ $i ][ 'name' ],
'description' => $rows [ $i ][ 'description' ],
'url' => $rows [ $i ][ 'url' ],
'start_timestamp' => $rows [ $i ][ 'start_timestamp' ],
'end_timestamp' => $rows [ $i ][ 'end_timestamp' ],
'starts' => $rows [ $i ][ 'starts' ],
'ends' => $rows [ $i ][ 'ends' ],
'record' => $rows [ $i ][ 'record' ],
'image_path' => $rows [ $i ][ 'image_path' ],
2022-07-07 20:01:15 +02:00
'type' => 'show' ,
];
2021-10-11 16:10:47 +02:00
2012-03-13 15:21:01 +01:00
break ;
}
}
2022-03-14 11:15:04 +01:00
// If we didn't find a a current show because the time didn't fit we may still have
// found a previous show so use it.
2012-03-13 22:46:13 +01:00
if ( count ( $results [ 'previousShow' ]) == 0 && isset ( $previousShowIndex )) {
2021-10-11 16:10:47 +02:00
$results [ 'previousShow' ][ 0 ] = [
'id' => $rows [ $previousShowIndex ][ 'id' ],
'instance_id' => $rows [ $previousShowIndex ][ 'instance_id' ],
'name' => $rows [ $previousShowIndex ][ 'name' ],
'description' => $rows [ $previousShowIndex ][ 'description' ],
'start_timestamp' => $rows [ $previousShowIndex ][ 'start_timestamp' ],
'end_timestamp' => $rows [ $previousShowIndex ][ 'end_timestamp' ],
'starts' => $rows [ $previousShowIndex ][ 'starts' ],
'ends' => $rows [ $previousShowIndex ][ 'ends' ],
'record' => $rows [ $previousShowIndex ][ 'record' ],
2022-07-07 20:01:15 +02:00
'type' => 'show' ,
];
2012-03-13 22:46:13 +01:00
}
2021-10-11 16:10:47 +02:00
2012-03-13 15:21:01 +01:00
return $results ;
}
2012-04-01 21:51:03 +02:00
CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time,
the SQL query was also comparing UTC timestamp with local timestamps,
causing widgets to display shows in the wrong day, etc.
Another problem was that "On air today" widget was simply calling
GetNextShows which returns shows within next 48 hours.
Fixed by:
1. Under models/Show.php:
In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions,
added code to convert UTC timestamp to local timestamp or vice versa,
depending on which one is more suitable, in SQL queries, thus
removing inconsistency in timezones. Also, before returning query result,
added code to convert result to local timezone.
In GetNextShows, added an optional parameter endTime to limit the interval
of shows to get. This is useful for the "On air today" widget.
2. Under models/DateHelper.php:
Added a few timezone functions to help converting timezones easier in Show.php.
3. Under controller/ApiController.php:
Added todayInfoAction which is to be used by "On Air Today" widget.
2011-11-04 21:57:24 +01:00
/**
2011-11-22 00:03:56 +01:00
* Given a start time $timeStart and end time $timeEnd , returns the next $limit
2012-07-12 01:31:24 +02:00
* number of shows within the time interval
* If $timeEnd not given , shows within next 48 hours from $timeStart are returned
* If $limit not given , all shows within the intervals are returned
2011-11-22 00:03:56 +01:00
* Times are all in UTC time .
2011-11-15 15:20:33 +01:00
*
2021-10-11 16:10:47 +02:00
* @ param string $timeStart - interval start time ( in UTC )
* @ param int $limit - number of shows to return
* @ param string $timeEnd - interval end time ( in UTC )
*
* @ return array - the next $limit number of shows within the time interval
CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time,
the SQL query was also comparing UTC timestamp with local timestamps,
causing widgets to display shows in the wrong day, etc.
Another problem was that "On air today" widget was simply calling
GetNextShows which returns shows within next 48 hours.
Fixed by:
1. Under models/Show.php:
In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions,
added code to convert UTC timestamp to local timestamp or vice versa,
depending on which one is more suitable, in SQL queries, thus
removing inconsistency in timezones. Also, before returning query result,
added code to convert result to local timezone.
In GetNextShows, added an optional parameter endTime to limit the interval
of shows to get. This is useful for the "On air today" widget.
2. Under models/DateHelper.php:
Added a few timezone functions to help converting timezones easier in Show.php.
3. Under controller/ApiController.php:
Added todayInfoAction which is to be used by "On Air Today" widget.
2011-11-04 21:57:24 +01:00
*/
2021-10-11 16:10:47 +02:00
public static function getNextShows ( $timeStart , $limit = 'ALL' , $timeEnd = '' )
2011-03-22 14:55:33 +01:00
{
CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time,
the SQL query was also comparing UTC timestamp with local timestamps,
causing widgets to display shows in the wrong day, etc.
Another problem was that "On air today" widget was simply calling
GetNextShows which returns shows within next 48 hours.
Fixed by:
1. Under models/Show.php:
In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions,
added code to convert UTC timestamp to local timestamp or vice versa,
depending on which one is more suitable, in SQL queries, thus
removing inconsistency in timezones. Also, before returning query result,
added code to convert result to local timezone.
In GetNextShows, added an optional parameter endTime to limit the interval
of shows to get. This is useful for the "On air today" widget.
2. Under models/DateHelper.php:
Added a few timezone functions to help converting timezones easier in Show.php.
3. Under controller/ApiController.php:
Added todayInfoAction which is to be used by "On Air Today" widget.
2011-11-04 21:57:24 +01:00
// defaults to retrieving shows from next 2 days if no end time has
// been specified
2021-10-11 16:10:47 +02:00
if ( $timeEnd == '' ) {
$timeEnd = " ' { $timeStart } ' + INTERVAL '2 days' " ;
CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time,
the SQL query was also comparing UTC timestamp with local timestamps,
causing widgets to display shows in the wrong day, etc.
Another problem was that "On air today" widget was simply calling
GetNextShows which returns shows within next 48 hours.
Fixed by:
1. Under models/Show.php:
In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions,
added code to convert UTC timestamp to local timestamp or vice versa,
depending on which one is more suitable, in SQL queries, thus
removing inconsistency in timezones. Also, before returning query result,
added code to convert result to local timezone.
In GetNextShows, added an optional parameter endTime to limit the interval
of shows to get. This is useful for the "On air today" widget.
2. Under models/DateHelper.php:
Added a few timezone functions to help converting timezones easier in Show.php.
3. Under controller/ApiController.php:
Added todayInfoAction which is to be used by "On Air Today" widget.
2011-11-04 21:57:24 +01:00
}
2011-11-15 15:20:33 +01:00
2022-03-14 11:15:04 +01:00
// TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-04 19:12:35 +02:00
SELECT si . starts AS start_timestamp ,
si . ends AS end_timestamp ,
s . name ,
2014-09-19 00:21:27 +02:00
s . description ,
2012-09-04 19:12:35 +02:00
s . id ,
si . id AS instance_id ,
2014-09-19 19:00:44 +02:00
si . description AS instance_description ,
2012-09-04 19:12:35 +02:00
si . record ,
s . url ,
2014-09-17 00:28:39 +02:00
s . image_path ,
starts ,
2012-09-04 19:12:35 +02:00
ends
2012-09-05 22:02:23 +02:00
FROM cc_show_instances si
LEFT JOIN cc_show s
2012-09-06 22:18:28 +02:00
ON si . show_id = s . id
2012-09-05 22:02:23 +02:00
WHERE si . show_id = s . id
2012-09-04 20:54:34 +02:00
AND si . starts >= : timeStart :: timestamp
AND si . starts < : timeEnd :: timestamp
2012-09-04 19:12:35 +02:00
AND modified_instance != TRUE
ORDER BY si . starts
SQL ;
2012-09-17 20:32:33 +02:00
2022-03-14 11:15:04 +01:00
// PDO won't accept "ALL" as a limit value (complains it is not an
// integer, and so we must completely remove the limit clause if we
// want to show all results - MK
2021-10-11 16:10:47 +02:00
if ( $limit != 'ALL' ) {
$sql .= PHP_EOL . 'LIMIT :lim' ;
$params = [
':timeStart' => $timeStart ,
':timeEnd' => $timeEnd ,
2022-07-07 20:01:15 +02:00
':lim' => $limit ,
];
2012-09-17 20:32:33 +02:00
} else {
2021-10-11 16:10:47 +02:00
$params = [
':timeStart' => $timeStart ,
2022-07-07 20:01:15 +02:00
':timeEnd' => $timeEnd ,
];
2012-09-17 20:32:33 +02:00
}
2021-10-11 16:10:47 +02:00
return Application_Common_Database :: prepareAndExecute ( $sql , $params , 'all' );
CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time,
the SQL query was also comparing UTC timestamp with local timestamps,
causing widgets to display shows in the wrong day, etc.
Another problem was that "On air today" widget was simply calling
GetNextShows which returns shows within next 48 hours.
Fixed by:
1. Under models/Show.php:
In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions,
added code to convert UTC timestamp to local timestamp or vice versa,
depending on which one is more suitable, in SQL queries, thus
removing inconsistency in timezones. Also, before returning query result,
added code to convert result to local timezone.
In GetNextShows, added an optional parameter endTime to limit the interval
of shows to get. This is useful for the "On air today" widget.
2. Under models/DateHelper.php:
Added a few timezone functions to help converting timezones easier in Show.php.
3. Under controller/ApiController.php:
Added todayInfoAction which is to be used by "On Air Today" widget.
2011-11-04 21:57:24 +01:00
}
2011-11-15 15:20:33 +01:00
2012-07-10 16:36:53 +02:00
public static function getMaxLengths ()
{
2021-10-11 16:10:47 +02:00
$sql = <<< 'SQL'
2012-09-07 21:14:33 +02:00
SELECT column_name , character_maximum_length FROM information_schema . columns
WHERE table_name = 'cc_show' AND character_maximum_length > 0
SQL ;
2021-10-11 16:10:47 +02:00
$result = Application_Common_Database :: prepareAndExecute ( $sql );
$assocArray = [];
2012-04-01 21:51:03 +02:00
foreach ( $result as $row ) {
2011-10-25 22:49:44 +02:00
$assocArray [ $row [ 'column_name' ]] = $row [ 'character_maximum_length' ];
}
2021-10-11 16:10:47 +02:00
2011-10-24 19:27:53 +02:00
return $assocArray ;
}
2013-01-24 18:13:55 +01:00
2021-10-11 16:10:47 +02:00
public static function getStartEndCurrentMonthView ()
{
$utcTimeZone = new DateTimeZone ( 'UTC' );
2015-04-16 20:58:28 +02:00
2022-03-14 11:15:04 +01:00
// We have to get the start of the day in the user's timezone, and then convert that to UTC.
2021-10-11 16:10:47 +02:00
$start = new DateTime ( 'first day of this month' , new DateTimeZone ( Application_Model_Preference :: GetUserTimezone ()));
2015-04-16 20:58:28 +02:00
2022-03-14 11:15:04 +01:00
$start -> setTimezone ( $utcTimeZone ); // Covert it to UTC.
2021-10-11 16:10:47 +02:00
$monthInterval = new DateInterval ( 'P1M' );
$end = clone $start ;
2015-04-16 20:58:28 +02:00
$end -> add ( $monthInterval );
2013-01-24 18:13:55 +01:00
2021-10-11 16:10:47 +02:00
return [ $start , $end ];
2013-01-24 18:13:55 +01:00
}
2013-01-24 20:02:50 +01:00
2015-04-16 22:30:12 +02:00
/** Returns the start and end date that FullCalendar will display for today ' s month .
*
* FullCalendar displays 6 weeks , starting on a Sunday , for a total of 42 days . This function returns 42 days worth
* of data ( a few days before , and a few days after . )
*/
2021-10-11 16:10:47 +02:00
public static function getStartEndCurrentMonthPlusView ()
{
$utcTimeZone = new DateTimeZone ( 'UTC' );
2015-04-16 22:30:12 +02:00
2022-03-14 11:15:04 +01:00
// We have to get the start of the day in the user's timezone, and then convert that to UTC.
2021-10-11 16:10:47 +02:00
$start = new DateTime ( 'first day of this month' , new DateTimeZone ( Application_Model_Preference :: GetUserTimezone ()));
2015-04-16 22:30:12 +02:00
2015-04-16 22:45:20 +02:00
$dayOfWeekNumeric = $start -> format ( 'w' );
2022-03-14 11:15:04 +01:00
$start -> sub ( new DateInterval ( " P { $dayOfWeekNumeric } D " )); // Subtract the index of the day of the week the month starts on. (adds this many days from the previous month)
$start -> setTimezone ( $utcTimeZone ); // Covert it to UTC.
2015-04-16 22:30:12 +02:00
2022-03-14 11:15:04 +01:00
$fullCalendarMonthInterval = new DateInterval ( 'P42D' ); // 42 days
2021-10-11 16:10:47 +02:00
$end = clone $start ;
2015-04-16 22:30:12 +02:00
$end -> add ( $fullCalendarMonthInterval );
2021-10-11 16:10:47 +02:00
return [ $start , $end ];
2015-04-16 22:30:12 +02:00
}
2021-10-11 16:10:47 +02:00
public static function getStartEndCurrentWeekView ()
{
2015-04-16 20:58:28 +02:00
$weekStartDayNum = Application_Model_Preference :: GetWeekStartDay ();
2021-10-11 16:10:47 +02:00
$utcTimeZone = new DateTimeZone ( 'UTC' );
2013-01-24 20:02:50 +01:00
2022-03-14 11:15:04 +01:00
// We have to get the start of the week in the user's timezone, and then convert that to UTC.
2021-10-11 16:10:47 +02:00
$start = new DateTime ( 'Sunday last week' , new DateTimeZone ( Application_Model_Preference :: GetUserTimezone ()));
2022-03-14 11:15:04 +01:00
$start -> add ( new DateInterval ( " P { $weekStartDayNum } D " )); // Shift the start date to the station's "Week Starts on Day"
2015-04-16 20:58:28 +02:00
2022-03-14 11:15:04 +01:00
$start -> setTimezone ( $utcTimeZone ); // Covert it to UTC.
2021-10-11 16:10:47 +02:00
$weekInterval = new DateInterval ( 'P1W' );
$end = clone $start ;
2015-04-16 20:58:28 +02:00
$end -> add ( $weekInterval );
2021-10-11 16:10:47 +02:00
return [ $start , $end ];
2013-01-24 20:02:50 +01:00
}
2021-10-11 16:10:47 +02:00
public static function getStartEndCurrentDayView ()
{
$utcTimeZone = new DateTimeZone ( 'UTC' );
2015-04-16 20:58:28 +02:00
2022-03-14 11:15:04 +01:00
// We have to get the start of the day in the user's timezone, and then convert that to UTC.
2021-10-11 16:10:47 +02:00
$start = new DateTime ( 'today' , new DateTimeZone ( Application_Model_Preference :: GetUserTimezone ()));
2013-01-24 20:02:50 +01:00
2022-03-14 11:15:04 +01:00
$start -> setTimezone ( $utcTimeZone ); // Covert it to UTC.
2021-10-11 16:10:47 +02:00
$dayInterval = new DateInterval ( 'P1D' );
$end = clone $start ;
2015-04-16 20:58:28 +02:00
$end -> add ( $dayInterval );
2013-01-24 20:02:50 +01:00
2021-10-11 16:10:47 +02:00
return [ $start , $end ];
2013-01-24 20:02:50 +01:00
}
2011-02-05 00:22:15 +01:00
}