2011-09-23 18:33:28 +02:00
|
|
|
<?php
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
class Application_Model_ShowInstance
|
|
|
|
{
|
2011-09-23 18:33:28 +02:00
|
|
|
private $_instanceId;
|
|
|
|
private $_showInstance;
|
|
|
|
|
|
|
|
public function __construct($instanceId)
|
|
|
|
{
|
|
|
|
$this->_instanceId = $instanceId;
|
|
|
|
$this->_showInstance = CcShowInstancesQuery::create()->findPK($instanceId);
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (is_null($this->_showInstance)) {
|
2011-09-23 18:33:28 +02:00
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getShowId()
|
|
|
|
{
|
|
|
|
return $this->_showInstance->getDbShowId();
|
|
|
|
}
|
|
|
|
|
2012-09-10 17:06:11 +02:00
|
|
|
/* TODO: A little inconsistent because other models have a getId() method
|
|
|
|
to get PK --RG */
|
2011-09-23 18:33:28 +02:00
|
|
|
public function getShowInstanceId()
|
|
|
|
{
|
|
|
|
return $this->_instanceId;
|
|
|
|
}
|
2011-11-15 18:22:21 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getShow()
|
|
|
|
{
|
2011-09-23 18:33:28 +02:00
|
|
|
return new Application_Model_Show($this->getShowId());
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function deleteRebroadcasts()
|
|
|
|
{
|
2015-06-26 20:42:52 +02:00
|
|
|
$timestamp = gmdate(DEFAULT_TIMESTAMP_FORMAT);
|
2012-04-25 21:09:58 +02:00
|
|
|
$instance_id = $this->getShowInstanceId();
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-09-10 17:39:22 +02:00
|
|
|
DELETE FROM cc_show_instances
|
|
|
|
WHERE starts > :timestamp::TIMESTAMP
|
|
|
|
AND instance_id = :instanceId
|
|
|
|
AND rebroadcast = 1;
|
|
|
|
SQL;
|
2021-10-11 16:10:47 +02:00
|
|
|
Application_Common_Database::prepareAndExecute($sql, [
|
2012-09-10 17:39:22 +02:00
|
|
|
':instanceId' => $instance_id,
|
2022-07-07 20:01:15 +02:00
|
|
|
':timestamp' => $timestamp,
|
|
|
|
], 'execute');
|
2012-04-25 21:09:58 +02:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2011-11-26 06:06:17 +01:00
|
|
|
/* This function is weird. It should return a boolean, but instead returns
|
|
|
|
* an integer if it is a rebroadcast, or returns null if it isn't. You can convert
|
2011-12-02 13:31:54 +01:00
|
|
|
* it to boolean by using is_null(isRebroadcast), where true means isn't and false
|
2011-11-26 06:06:17 +01:00
|
|
|
* means that it is. */
|
2011-09-23 18:33:28 +02:00
|
|
|
public function isRebroadcast()
|
|
|
|
{
|
|
|
|
return $this->_showInstance->getDbOriginalShow();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isRecorded()
|
|
|
|
{
|
|
|
|
return $this->_showInstance->getDbRecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
$show = CcShowQuery::create()->findPK($this->getShowId());
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
return $show->getDbName();
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-09-18 01:49:22 +02:00
|
|
|
public function getImagePath()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$show = CcShowQuery::create()->findPK($this->getShowId());
|
|
|
|
|
|
|
|
return $show->getDbImagePath();
|
2014-09-18 01:49:22 +02:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
|
|
|
|
public function getGenre()
|
|
|
|
{
|
|
|
|
$show = CcShowQuery::create()->findPK($this->getShowId());
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
return $show->getDbGenre();
|
|
|
|
}
|
|
|
|
|
2017-02-13 15:35:09 +01:00
|
|
|
public function hasAutoPlaylist()
|
|
|
|
{
|
|
|
|
$show = CcShowQuery::create()->findPK($this->getShowId());
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $show->getDbHasAutoPlaylist();
|
2017-02-13 15:35:09 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2017-02-13 15:35:09 +01:00
|
|
|
public function getAutoPlaylistId()
|
|
|
|
{
|
|
|
|
$show = CcShowQuery::create()->findPK($this->getShowId());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2017-02-13 15:35:09 +01:00
|
|
|
return $show->getDbAutoPlaylistId();
|
|
|
|
}
|
2017-03-31 06:00:19 +02:00
|
|
|
|
|
|
|
public function getAutoPlaylistRepeat()
|
|
|
|
{
|
|
|
|
$show = CcShowQuery::create()->findPK($this->getShowId());
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $show->getDbAutoPlaylistRepeat();
|
2017-03-31 06:00:19 +02:00
|
|
|
}
|
|
|
|
|
2011-11-11 20:54:08 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Return the start time of the Show (UTC time).
|
|
|
|
*
|
|
|
|
* @param mixed $format
|
|
|
|
*
|
2015-06-26 20:42:52 +02:00
|
|
|
* @return string in format DEFAULT_TIMESTAMP_FORMAT (PHP time notation)
|
2011-11-11 20:54:08 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public function getShowInstanceStart($format = DEFAULT_TIMESTAMP_FORMAT)
|
2011-09-23 18:33:28 +02:00
|
|
|
{
|
2012-02-08 15:13:17 +01:00
|
|
|
return $this->_showInstance->getDbStarts($format);
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2011-11-11 20:54:08 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Return the end time of the Show (UTC time).
|
|
|
|
*
|
|
|
|
* @param mixed $format
|
|
|
|
*
|
2015-06-26 20:42:52 +02:00
|
|
|
* @return string in format DEFAULT_TIMESTAMP_FORMAT (PHP time notation)
|
2011-11-11 20:54:08 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public function getShowInstanceEnd($format = DEFAULT_TIMESTAMP_FORMAT)
|
2011-09-23 18:33:28 +02:00
|
|
|
{
|
2012-02-08 15:13:17 +01:00
|
|
|
return $this->_showInstance->getDbEnds($format);
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getStartDate()
|
|
|
|
{
|
2011-11-12 04:24:37 +01:00
|
|
|
$showStart = $this->getShowInstanceStart();
|
2021-10-11 16:10:47 +02:00
|
|
|
$showStartExplode = explode(' ', $showStart);
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
return $showStartExplode[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStartTime()
|
|
|
|
{
|
2011-11-12 04:24:37 +01:00
|
|
|
$showStart = $this->getShowInstanceStart();
|
2021-10-11 16:10:47 +02:00
|
|
|
$showStartExplode = explode(' ', $showStart);
|
2011-09-23 18:33:28 +02:00
|
|
|
|
|
|
|
return $showStartExplode[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRecordedFile()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$file_id = $this->_showInstance->getDbRecordedFile();
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2012-05-07 17:48:56 +02:00
|
|
|
if (isset($file_id)) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$file = Application_Model_StoredFile::RecallById($file_id);
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2015-03-30 17:31:07 +02:00
|
|
|
if (isset($file)) {
|
|
|
|
$filePaths = $file->getFilePaths();
|
|
|
|
if (file_exists($filePaths[0])) {
|
|
|
|
return $file;
|
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setShowStart($start)
|
|
|
|
{
|
|
|
|
$this->_showInstance->setDbStarts($start)
|
2022-01-23 19:15:55 +01:00
|
|
|
->save();
|
2011-09-26 21:19:04 +02:00
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setShowEnd($end)
|
|
|
|
{
|
|
|
|
$this->_showInstance->setDbEnds($end)
|
2022-01-23 19:15:55 +01:00
|
|
|
->save();
|
2011-09-26 21:19:04 +02:00
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2017-02-13 15:35:09 +01:00
|
|
|
public function setAutoPlaylistBuilt($bool)
|
|
|
|
{
|
|
|
|
$this->_showInstance->setDbAutoPlaylistBuilt($bool)
|
2022-01-23 19:15:55 +01:00
|
|
|
->save();
|
2017-02-13 15:35:09 +01:00
|
|
|
}
|
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
public function updateScheduledTime()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
|
|
|
|
$this->_showInstance->updateDbTimeFilled($con);
|
|
|
|
}
|
2011-11-15 18:22:21 +01:00
|
|
|
|
2011-11-15 04:37:34 +01:00
|
|
|
public function isDeleted()
|
|
|
|
{
|
2011-11-18 18:20:25 +01:00
|
|
|
$this->_showInstance->getDbModifiedInstance();
|
2011-11-15 04:37:34 +01:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2011-12-02 16:24:11 +01:00
|
|
|
/*
|
|
|
|
* @param $dateTime
|
|
|
|
* php Datetime object to add deltas to
|
|
|
|
*
|
|
|
|
* @param $deltaDay
|
|
|
|
* php int, delta days show moved
|
|
|
|
*
|
|
|
|
* @param $deltaMin
|
|
|
|
* php int, delta mins show moved
|
|
|
|
*
|
|
|
|
* @return $newDateTime
|
|
|
|
* php DateTime, $dateTime with the added time deltas.
|
|
|
|
*/
|
2012-08-24 21:27:04 +02:00
|
|
|
public static function addDeltas($dateTime, $deltaDay, $deltaMin)
|
2012-07-16 03:17:13 +02:00
|
|
|
{
|
2011-12-02 16:24:11 +01:00
|
|
|
$newDateTime = clone $dateTime;
|
|
|
|
|
|
|
|
$days = abs($deltaDay);
|
|
|
|
$mins = abs($deltaMin);
|
|
|
|
|
|
|
|
$dayInterval = new DateInterval("P{$days}D");
|
|
|
|
$minInterval = new DateInterval("PT{$mins}M");
|
|
|
|
|
|
|
|
if ($deltaDay > 0) {
|
|
|
|
$newDateTime->add($dayInterval);
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($deltaDay < 0) {
|
2011-12-02 16:24:11 +01:00
|
|
|
$newDateTime->sub($dayInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($deltaMin > 0) {
|
|
|
|
$newDateTime->add($minInterval);
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($deltaMin < 0) {
|
2011-12-02 16:24:11 +01:00
|
|
|
$newDateTime->sub($minInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $newDateTime;
|
|
|
|
}
|
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
/**
|
|
|
|
* Add a playlist as the last item of the current show.
|
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @param mixed $pl_id
|
|
|
|
* @param mixed $checkUserPerm
|
2011-09-23 18:33:28 +02:00
|
|
|
*/
|
2017-02-13 15:35:09 +01:00
|
|
|
public function addPlaylistToShow($pl_id, $checkUserPerm = true)
|
2011-09-23 18:33:28 +02:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$ts = intval($this->_showInstance->getDbLastScheduled('U')) ?: 0;
|
2012-02-27 14:33:56 +01:00
|
|
|
$id = $this->_showInstance->getDbId();
|
2017-04-01 06:56:55 +02:00
|
|
|
$lastid = $this->getLastAudioItemId();
|
2017-03-22 12:26:18 +01:00
|
|
|
$scheduler = new Application_Model_Scheduler($checkUserPerm);
|
2012-02-27 14:33:56 +01:00
|
|
|
$scheduler->scheduleAfter(
|
2021-10-11 16:10:47 +02:00
|
|
|
[['id' => $lastid, 'instance' => $id, 'timestamp' => $ts]],
|
|
|
|
[['id' => $pl_id, 'type' => 'playlist']]
|
2012-02-27 14:33:56 +01:00
|
|
|
);
|
2019-02-09 16:58:00 +01:00
|
|
|
// doing this to update the database schedule so that subsequent adds will work.
|
|
|
|
$con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
|
|
|
|
$this->_showInstance->updateScheduleStatus($con);
|
2017-02-13 15:35:09 +01:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2019-01-21 01:20:13 +01:00
|
|
|
/**
|
|
|
|
* Add a playlist as the first item of the current show.
|
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @param mixed $pl_id
|
|
|
|
* @param mixed $checkUserPerm
|
2019-01-21 01:20:13 +01:00
|
|
|
*/
|
|
|
|
public function addPlaylistToShowStart($pl_id, $checkUserPerm = true)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$ts = intval($this->_showInstance->getDbLastScheduled('U')) ?: 0;
|
2019-01-21 01:20:13 +01:00
|
|
|
$id = $this->_showInstance->getDbId();
|
|
|
|
$scheduler = new Application_Model_Scheduler($checkUserPerm);
|
|
|
|
$scheduler->scheduleAfter(
|
2021-10-11 16:10:47 +02:00
|
|
|
[['id' => 0, 'instance' => $id, 'timestamp' => $ts]],
|
|
|
|
[['id' => $pl_id, 'type' => 'playlist']]
|
2019-01-21 01:20:13 +01:00
|
|
|
);
|
2019-02-09 16:58:00 +01:00
|
|
|
// doing this to update the database schedule so that subsequent adds will work.
|
|
|
|
$con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
|
|
|
|
$this->_showInstance->updateScheduleStatus($con);
|
2019-01-21 01:20:13 +01:00
|
|
|
}
|
2017-04-01 06:56:55 +02:00
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
/**
|
|
|
|
* Add a media file as the last item in the show.
|
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @param int $file_id
|
|
|
|
* @param mixed $checkUserPerm
|
2011-09-23 18:33:28 +02:00
|
|
|
*/
|
2012-04-12 18:00:38 +02:00
|
|
|
public function addFileToShow($file_id, $checkUserPerm = true)
|
2011-09-23 18:33:28 +02:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$ts = intval($this->_showInstance->getDbLastScheduled('U')) ?: 0;
|
2012-02-27 14:33:56 +01:00
|
|
|
$id = $this->_showInstance->getDbId();
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2012-02-27 14:33:56 +01:00
|
|
|
$scheduler = new Application_Model_Scheduler();
|
2012-04-12 18:00:38 +02:00
|
|
|
$scheduler->setCheckUserPermissions($checkUserPerm);
|
2012-02-27 14:33:56 +01:00
|
|
|
$scheduler->scheduleAfter(
|
2021-10-11 16:10:47 +02:00
|
|
|
[['id' => 0, 'instance' => $id, 'timestamp' => $ts]],
|
|
|
|
[['id' => $file_id, 'type' => 'audioclip']]
|
2012-02-27 14:33:56 +01:00
|
|
|
);
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the given playlists to the show.
|
|
|
|
*
|
|
|
|
* @param array $plIds
|
2021-10-11 16:10:47 +02:00
|
|
|
* An array of playlist IDs
|
2011-09-23 18:33:28 +02:00
|
|
|
*/
|
2017-02-13 15:35:09 +01:00
|
|
|
public function scheduleShow($plIds)
|
2011-09-23 18:33:28 +02:00
|
|
|
{
|
|
|
|
foreach ($plIds as $plId) {
|
|
|
|
$this->addPlaylistToShow($plId);
|
|
|
|
}
|
2017-02-13 15:35:09 +01:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
|
|
|
|
public function clearShow()
|
|
|
|
{
|
|
|
|
CcScheduleQuery::create()
|
|
|
|
->filterByDbInstanceId($this->_instanceId)
|
2022-01-23 19:15:55 +01:00
|
|
|
->delete();
|
2011-09-26 21:19:04 +02:00
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
2011-09-23 18:33:28 +02:00
|
|
|
$this->updateScheduledTime();
|
|
|
|
}
|
|
|
|
|
2012-01-18 16:21:46 +01:00
|
|
|
private function checkToDeleteShow($showId)
|
|
|
|
{
|
2022-03-14 11:15:04 +01:00
|
|
|
// UTC DateTime object
|
2012-01-18 16:21:46 +01:00
|
|
|
$showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil();
|
|
|
|
|
|
|
|
$showDays = CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($showId)
|
2022-01-23 19:15:55 +01:00
|
|
|
->findOne();
|
2012-01-18 16:21:46 +01:00
|
|
|
|
|
|
|
$showEnd = $showDays->getDbLastShow();
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// there will always be more shows populated.
|
2012-01-18 16:21:46 +01:00
|
|
|
if (is_null($showEnd)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$lastShowStartDateTime = new DateTime("{$showEnd} {$showDays->getDbStartTime()}", new DateTimeZone($showDays->getDbTimezone()));
|
2022-03-14 11:15:04 +01:00
|
|
|
// end dates were non inclusive.
|
2012-01-18 16:21:46 +01:00
|
|
|
$lastShowStartDateTime = self::addDeltas($lastShowStartDateTime, -1, 0);
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// there's still some shows left to be populated.
|
2012-01-18 16:21:46 +01:00
|
|
|
if ($lastShowStartDateTime->getTimestamp() > $showsPopUntil->getTimestamp()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if there are any non deleted show instances remaining.
|
|
|
|
$showInstances = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbShowId($showId)
|
|
|
|
->filterByDbModifiedInstance(false)
|
|
|
|
->filterByDbRebroadcast(0)
|
2022-01-23 19:15:55 +01:00
|
|
|
->find();
|
2012-01-18 16:21:46 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (is_null($showInstances)) {
|
2012-01-18 16:21:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
2022-03-14 11:15:04 +01:00
|
|
|
// only 1 show instance left of the show, make it non repeating.
|
2021-10-11 16:10:47 +02:00
|
|
|
if (count($showInstances) === 1) {
|
2012-01-18 16:21:46 +01:00
|
|
|
$showInstance = $showInstances[0];
|
|
|
|
|
|
|
|
$showDaysOld = CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($showId)
|
2022-01-23 19:15:55 +01:00
|
|
|
->find();
|
2012-01-18 16:21:46 +01:00
|
|
|
|
|
|
|
$tz = $showDaysOld[0]->getDbTimezone();
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$startDate = new DateTime($showInstance->getDbStarts(), new DateTimeZone('UTC'));
|
2012-01-18 16:21:46 +01:00
|
|
|
$startDate->setTimeZone(new DateTimeZone($tz));
|
|
|
|
$endDate = self::addDeltas($startDate, 1, 0);
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// make a new rule for a non repeating show.
|
2012-01-18 16:21:46 +01:00
|
|
|
$showDayNew = new CcShowDays();
|
2021-10-11 16:10:47 +02:00
|
|
|
$showDayNew->setDbFirstShow($startDate->format('Y-m-d'));
|
|
|
|
$showDayNew->setDbLastShow($endDate->format('Y-m-d'));
|
|
|
|
$showDayNew->setDbStartTime($startDate->format('H:i:s'));
|
2012-01-18 16:21:46 +01:00
|
|
|
$showDayNew->setDbTimezone($tz);
|
|
|
|
$showDayNew->setDbDay($startDate->format('w'));
|
|
|
|
$showDayNew->setDbDuration($showDaysOld[0]->getDbDuration());
|
|
|
|
$showDayNew->setDbRepeatType(-1);
|
|
|
|
$showDayNew->setDbShowId($showDaysOld[0]->getDbShowId());
|
|
|
|
$showDayNew->setDbRecord($showDaysOld[0]->getDbRecord());
|
|
|
|
$showDayNew->save();
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// delete the old rules for repeating shows
|
2012-01-18 16:21:46 +01:00
|
|
|
$showDaysOld->delete();
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// remove the old repeating deleted instances.
|
2012-01-18 16:21:46 +01:00
|
|
|
$showInstances = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbShowId($showId)
|
|
|
|
->filterByDbModifiedInstance(true)
|
2022-01-23 19:15:55 +01:00
|
|
|
->delete();
|
2012-01-18 16:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-17 18:32:39 +02:00
|
|
|
public function delete($rabbitmqPush = true)
|
2011-09-23 18:33:28 +02:00
|
|
|
{
|
|
|
|
// see if it was recording show
|
2011-12-02 13:31:54 +01:00
|
|
|
$recording = $this->isRecorded();
|
2011-11-10 21:17:06 +01:00
|
|
|
// get show id
|
2011-12-02 13:31:54 +01:00
|
|
|
$showId = $this->getShowId();
|
|
|
|
|
|
|
|
$show = $this->getShow();
|
|
|
|
|
2015-06-26 20:42:52 +02:00
|
|
|
$current_timestamp = gmdate(DEFAULT_TIMESTAMP_FORMAT);
|
2011-12-02 13:31:54 +01:00
|
|
|
|
2011-12-13 13:04:03 +01:00
|
|
|
if ($current_timestamp <= $this->getShowInstanceEnd()) {
|
2011-12-02 13:31:54 +01:00
|
|
|
if ($show->isRepeating()) {
|
|
|
|
CcShowInstancesQuery::create()
|
|
|
|
->findPK($this->_instanceId)
|
|
|
|
->setDbModifiedInstance(true)
|
2022-01-23 19:15:55 +01:00
|
|
|
->save();
|
2011-12-02 13:31:54 +01:00
|
|
|
|
2012-01-18 16:21:46 +01:00
|
|
|
if ($this->isRebroadcast()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// delete the rebroadcasts of the removed recorded show.
|
2011-12-02 13:31:54 +01:00
|
|
|
if ($recording) {
|
|
|
|
CcShowInstancesQuery::create()
|
|
|
|
->filterByDbOriginalShow($this->_instanceId)
|
2022-01-23 19:15:55 +01:00
|
|
|
->delete();
|
2011-12-02 13:31:54 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
// Automatically delete all files scheduled in cc_schedules table.
|
2011-12-02 13:31:54 +01:00
|
|
|
CcScheduleQuery::create()
|
|
|
|
->filterByDbInstanceId($this->_instanceId)
|
2022-01-23 19:15:55 +01:00
|
|
|
->delete();
|
2012-01-18 16:21:46 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($this->checkToDeleteShow($showId)) {
|
2011-12-02 13:31:54 +01:00
|
|
|
CcShowQuery::create()
|
|
|
|
->filterByDbId($showId)
|
2022-01-23 19:15:55 +01:00
|
|
|
->delete();
|
2011-12-02 13:31:54 +01:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-01-17 14:11:12 +01:00
|
|
|
if ($this->isRebroadcast()) {
|
|
|
|
$this->_showInstance->delete();
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-01-17 14:11:12 +01:00
|
|
|
$show->delete();
|
|
|
|
}
|
2011-12-02 13:31:54 +01:00
|
|
|
}
|
2011-11-10 21:17:06 +01:00
|
|
|
}
|
2011-11-15 18:22:21 +01:00
|
|
|
|
2012-09-17 18:32:39 +02:00
|
|
|
if ($rabbitmqPush) {
|
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setRecordedFile($file_id)
|
|
|
|
{
|
|
|
|
$showInstance = CcShowInstancesQuery::create()
|
2022-01-23 19:15:55 +01:00
|
|
|
->findPK($this->_instanceId);
|
2011-09-23 18:33:28 +02:00
|
|
|
$showInstance->setDbRecordedFile($file_id)
|
2022-01-23 19:15:55 +01:00
|
|
|
->save();
|
2011-09-23 18:33:28 +02:00
|
|
|
|
|
|
|
$rebroadcasts = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbOriginalShow($this->_instanceId)
|
2022-01-23 19:15:55 +01:00
|
|
|
->find();
|
2011-09-23 18:33:28 +02:00
|
|
|
|
|
|
|
foreach ($rebroadcasts as $rebroadcast) {
|
2012-02-27 14:33:56 +01:00
|
|
|
try {
|
|
|
|
$rebroad = new Application_Model_ShowInstance($rebroadcast->getDbId());
|
2012-04-12 18:00:38 +02:00
|
|
|
$rebroad->addFileToShow($file_id, false);
|
2012-07-16 03:17:13 +02:00
|
|
|
} catch (Exception $e) {
|
2012-09-18 17:04:33 +02:00
|
|
|
Logging::info($e->getMessage());
|
2012-02-27 14:33:56 +01:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTimeScheduled()
|
|
|
|
{
|
|
|
|
$time = $this->_showInstance->getDbTimeFilled();
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($time != '00:00:00' && !empty($time)) {
|
|
|
|
$time_arr = explode('.', $time);
|
2012-04-17 22:52:59 +02:00
|
|
|
if (count($time_arr) > 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$time_arr[1] = '.' . $time_arr[1];
|
2012-04-17 22:52:59 +02:00
|
|
|
$milliseconds = number_format(round($time_arr[1], 2), 2);
|
|
|
|
$time = $time_arr[0] . substr($milliseconds, 1);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$time = $time_arr[0] . '.00';
|
2012-04-17 22:52:59 +02:00
|
|
|
}
|
2012-04-12 22:25:01 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$time = '00:00:00.00';
|
2012-02-24 15:07:04 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
return $time;
|
|
|
|
}
|
|
|
|
|
2012-02-08 15:13:17 +01:00
|
|
|
public function getTimeScheduledSecs()
|
2011-09-23 18:33:28 +02:00
|
|
|
{
|
|
|
|
$time_filled = $this->getTimeScheduled();
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-07-26 20:41:09 +02:00
|
|
|
return Application_Common_DateHelper::playlistTimeToSeconds($time_filled);
|
2012-02-08 15:13:17 +01:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2012-02-08 15:13:17 +01:00
|
|
|
public function getDurationSecs()
|
|
|
|
{
|
|
|
|
$ends = $this->getShowInstanceEnd(null);
|
|
|
|
$starts = $this->getShowInstanceStart(null);
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-03-01 12:13:21 +01:00
|
|
|
return intval($ends->format('U')) - intval($starts->format('U'));
|
2012-02-08 15:13:17 +01:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2018-11-24 23:08:39 +01:00
|
|
|
// should return the amount of seconds remaining to be scheduled in a show instance
|
|
|
|
public function getSecondsRemaining()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
return $this->getDurationSecs() - $this->getTimeScheduledSecs();
|
2018-11-24 23:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 15:13:17 +01:00
|
|
|
public function getPercentScheduled()
|
|
|
|
{
|
|
|
|
$durationSeconds = $this->getDurationSecs();
|
|
|
|
$timeSeconds = $this->getTimeScheduledSecs();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
if ($durationSeconds != 0) { // Prevent division by zero if the show duration is somehow zero.
|
2013-12-13 22:10:36 +01:00
|
|
|
$percent = ceil(($timeSeconds / $durationSeconds) * 100);
|
|
|
|
} else {
|
|
|
|
$percent = 0;
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
return $percent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getShowLength()
|
|
|
|
{
|
2012-02-24 15:07:04 +01:00
|
|
|
$start = $this->getShowInstanceStart(null);
|
|
|
|
$end = $this->getShowInstanceEnd(null);
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2012-02-24 15:07:04 +01:00
|
|
|
$interval = $start->diff($end);
|
2021-10-11 16:10:47 +02:00
|
|
|
$days = $interval->format('%d');
|
|
|
|
$hours = sprintf('%02d', $interval->format('%h'));
|
2012-04-12 23:12:43 +02:00
|
|
|
|
2012-04-12 23:07:27 +02:00
|
|
|
if ($days > 0) {
|
|
|
|
$totalHours = $days * 24 + $hours;
|
2022-03-14 11:15:04 +01:00
|
|
|
// $interval object does not have milliseconds so hard code to .00
|
2021-10-11 16:10:47 +02:00
|
|
|
$returnStr = $totalHours . ':' . $interval->format('%I:%S') . '.00';
|
2012-04-12 23:07:27 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$returnStr = $hours . ':' . $interval->format('%I:%S') . '.00';
|
2012-04-12 23:07:27 +02:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-04-12 23:07:27 +02:00
|
|
|
return $returnStr;
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getContentCount($p_start, $p_end)
|
2013-01-23 22:12:16 +01:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-10-19 19:22:00 +02:00
|
|
|
SELECT instance_id,
|
|
|
|
count(*) AS instance_count
|
|
|
|
FROM cc_schedule
|
|
|
|
WHERE ends > :p_start::TIMESTAMP
|
|
|
|
AND starts < :p_end::TIMESTAMP
|
2012-10-19 19:24:06 +02:00
|
|
|
GROUP BY instance_id
|
|
|
|
SQL;
|
2012-10-19 19:22:00 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$counts = Application_Common_Database::prepareAndExecute($sql, [
|
|
|
|
':p_start' => $p_start->format('Y-m-d G:i:s'),
|
2022-07-07 20:01:15 +02:00
|
|
|
':p_end' => $p_end->format('Y-m-d G:i:s'),
|
|
|
|
], 'all');
|
2012-10-19 19:24:06 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$real_counts = [];
|
2012-10-22 21:34:33 +02:00
|
|
|
foreach ($counts as $c) {
|
|
|
|
$real_counts[$c['instance_id']] = $c['instance_count'];
|
|
|
|
}
|
2012-10-19 19:24:06 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $real_counts;
|
2012-10-22 21:20:03 +02:00
|
|
|
}
|
2012-10-19 19:22:00 +02:00
|
|
|
|
2013-01-23 22:12:16 +01:00
|
|
|
public static function getIsFull($p_start, $p_end)
|
2013-01-07 18:41:28 +01:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2013-01-23 22:31:20 +01:00
|
|
|
SELECT id, ends-starts-'00:00:05' < time_filled as filled
|
2013-01-23 22:12:16 +01:00
|
|
|
from cc_show_instances
|
|
|
|
WHERE ends > :p_start::TIMESTAMP
|
|
|
|
AND starts < :p_end::TIMESTAMP
|
2013-01-07 18:41:28 +01:00
|
|
|
SQL;
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$res = Application_Common_Database::prepareAndExecute($sql, [
|
|
|
|
':p_start' => $p_start->format('Y-m-d G:i:s'),
|
2022-07-07 20:01:15 +02:00
|
|
|
':p_end' => $p_end->format('Y-m-d G:i:s'),
|
|
|
|
], 'all');
|
2013-01-23 22:12:16 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$isFilled = [];
|
2013-01-23 22:12:16 +01:00
|
|
|
foreach ($res as $r) {
|
|
|
|
$isFilled[$r['id']] = $r['filled'];
|
|
|
|
}
|
2013-01-07 18:41:28 +01:00
|
|
|
|
2013-01-23 22:12:16 +01:00
|
|
|
return $isFilled;
|
2013-01-07 18:41:28 +01:00
|
|
|
}
|
|
|
|
|
2017-11-28 21:12:27 +01:00
|
|
|
public static function getShowHasAutoplaylist($p_start, $p_end)
|
|
|
|
{
|
2017-12-17 16:47:38 +01:00
|
|
|
$con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
|
|
|
|
$con->beginTransaction();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2017-12-17 16:47:38 +01:00
|
|
|
try {
|
|
|
|
// query the show instances to find whether a show instance has an autoplaylist
|
|
|
|
$showInstances = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbEnds($p_end->format(DEFAULT_TIMESTAMP_FORMAT), Criteria::LESS_THAN)
|
|
|
|
->filterByDbStarts($p_start->format(DEFAULT_TIMESTAMP_FORMAT), Criteria::GREATER_THAN)
|
|
|
|
->leftJoinCcShow()
|
2018-01-04 04:01:46 +01:00
|
|
|
->where('CcShow.has_autoplaylist = ?', 'true')
|
2022-01-23 19:15:55 +01:00
|
|
|
->find($con);
|
2021-10-11 16:10:47 +02:00
|
|
|
$hasAutoplaylist = [];
|
2018-01-04 04:01:46 +01:00
|
|
|
foreach ($showInstances->toArray() as $ap) {
|
|
|
|
$hasAutoplaylist[$ap['DbId']] = true;
|
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $hasAutoplaylist;
|
|
|
|
} catch (Exception $e) {
|
2017-12-17 16:47:38 +01:00
|
|
|
$con->rollback();
|
|
|
|
Logging::info("Couldn't query show instances for calendar to find which had autoplaylists");
|
|
|
|
Logging::info($e->getMessage());
|
2017-11-28 21:12:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-19 17:32:35 +02:00
|
|
|
public function showEmpty()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-10-19 17:32:35 +02:00
|
|
|
SELECT s.starts
|
|
|
|
FROM cc_schedule AS s
|
|
|
|
WHERE s.instance_id = :instance_id
|
|
|
|
AND s.playout_status >= 0
|
|
|
|
AND ((s.stream_id IS NOT NULL)
|
|
|
|
OR (s.file_id IS NOT NULL)) LIMIT 1
|
|
|
|
SQL;
|
2021-10-11 16:10:47 +02:00
|
|
|
// TODO : use prepareAndExecute properly
|
|
|
|
$res = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[':instance_id' => $this->_instanceId],
|
|
|
|
'all'
|
|
|
|
);
|
|
|
|
// TODO : A bit retarded. fix this later
|
2012-10-19 17:32:35 +02:00
|
|
|
foreach ($res as $r) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return true;
|
2012-10-19 17:32:35 +02:00
|
|
|
}
|
|
|
|
|
2014-11-17 21:53:31 +01:00
|
|
|
public function getShowListContent($timezone = null)
|
2011-09-23 18:33:28 +02:00
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-08-10 00:14:53 +02:00
|
|
|
SELECT *
|
|
|
|
FROM (
|
|
|
|
(SELECT s.starts,
|
|
|
|
0::INTEGER as type ,
|
2012-10-19 17:05:12 +02:00
|
|
|
f.id AS item_id,
|
2012-08-10 00:14:53 +02:00
|
|
|
f.track_title,
|
2012-10-19 17:05:12 +02:00
|
|
|
f.album_title AS album,
|
|
|
|
f.genre AS genre,
|
|
|
|
f.length AS length,
|
|
|
|
f.artist_name AS creator,
|
|
|
|
f.file_exists AS EXISTS,
|
|
|
|
f.filepath AS filepath,
|
|
|
|
f.mime AS mime
|
2012-08-10 00:14:53 +02:00
|
|
|
FROM cc_schedule AS s
|
|
|
|
LEFT JOIN cc_files AS f ON f.id = s.file_id
|
2012-09-05 23:35:08 +02:00
|
|
|
WHERE s.instance_id = :instance_id1
|
2012-08-10 00:14:53 +02:00
|
|
|
AND s.playout_status >= 0
|
2012-11-05 15:30:21 +01:00
|
|
|
AND s.file_id IS NOT NULL
|
2012-12-03 17:45:06 +01:00
|
|
|
AND f.hidden = 'false')
|
2012-08-10 00:14:53 +02:00
|
|
|
UNION
|
|
|
|
(SELECT s.starts,
|
|
|
|
1::INTEGER as type,
|
|
|
|
ws.id AS item_id,
|
|
|
|
(ws.name || ': ' || ws.url) AS title,
|
2012-10-19 17:05:12 +02:00
|
|
|
null AS album,
|
|
|
|
null AS genre,
|
|
|
|
ws.length AS length,
|
|
|
|
sub.login AS creator,
|
|
|
|
't'::boolean AS EXISTS,
|
|
|
|
ws.url AS filepath,
|
2012-10-16 17:06:01 +02:00
|
|
|
ws.mime as mime
|
2012-08-10 00:14:53 +02:00
|
|
|
FROM cc_schedule AS s
|
|
|
|
LEFT JOIN cc_webstream AS ws ON ws.id = s.stream_id
|
|
|
|
LEFT JOIN cc_subjs AS sub ON ws.creator_id = sub.id
|
2012-09-05 23:35:08 +02:00
|
|
|
WHERE s.instance_id = :instance_id2
|
2012-08-10 00:14:53 +02:00
|
|
|
AND s.playout_status >= 0
|
|
|
|
AND s.stream_id IS NOT NULL)) AS temp
|
|
|
|
ORDER BY starts;
|
|
|
|
SQL;
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2012-09-05 23:35:08 +02:00
|
|
|
$stmt = $con->prepare($sql);
|
2021-10-11 16:10:47 +02:00
|
|
|
$stmt->execute([
|
2012-09-05 23:35:08 +02:00
|
|
|
':instance_id1' => $this->_instanceId,
|
2021-10-11 16:10:47 +02:00
|
|
|
':instance_id2' => $this->_instanceId,
|
|
|
|
]);
|
2012-09-05 23:35:08 +02:00
|
|
|
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-11-17 21:53:31 +01:00
|
|
|
if (isset($timezone)) {
|
|
|
|
$displayTimezone = new DateTimeZone($timezone);
|
2021-10-11 16:10:47 +02:00
|
|
|
} else {
|
2014-11-17 21:53:31 +01:00
|
|
|
$userTimezone = Application_Model_Preference::GetUserTimezone();
|
|
|
|
$displayTimezone = new DateTimeZone($userTimezone);
|
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$utcTimezone = new DateTimeZone('UTC');
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2012-02-24 15:07:04 +01:00
|
|
|
foreach ($results as &$row) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$dt = new DateTime($row['starts'], $utcTimezone);
|
2013-12-04 20:39:56 +01:00
|
|
|
$dt->setTimezone($displayTimezone);
|
2021-10-11 16:10:47 +02:00
|
|
|
$row['starts'] = $dt->format(DEFAULT_TIMESTAMP_FORMAT);
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2012-09-05 22:07:40 +02:00
|
|
|
if (isset($row['length'])) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$formatter = new LengthFormatter($row['length']);
|
|
|
|
$row['length'] = $formatter->format();
|
2012-09-05 22:07:40 +02:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2012-02-24 15:07:04 +01:00
|
|
|
return $results;
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2017-04-01 06:56:55 +02:00
|
|
|
public function getLastAudioItemId()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT id FROM cc_schedule '
|
|
|
|
. 'WHERE instance_id = :instanceId '
|
|
|
|
. 'ORDER BY ends DESC '
|
|
|
|
. 'LIMIT 1';
|
2017-04-01 06:56:55 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$query = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[':instanceId' => $this->_instanceId],
|
|
|
|
'column'
|
|
|
|
);
|
2017-04-01 06:56:55 +02:00
|
|
|
|
|
|
|
return ($query !== false) ? $query : null;
|
|
|
|
}
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
public function getLastAudioItemEnd()
|
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT ends FROM cc_schedule '
|
|
|
|
. 'WHERE instance_id = :instanceId '
|
|
|
|
. 'ORDER BY ends DESC '
|
|
|
|
. 'LIMIT 1';
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$query = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[':instanceId' => $this->_instanceId],
|
|
|
|
'column'
|
|
|
|
);
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-08-10 00:14:53 +02:00
|
|
|
return ($query !== false) ? $query : null;
|
2012-07-11 00:51:32 +02:00
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public static function GetLastShowInstance($p_timeNow)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-09-10 17:06:34 +02:00
|
|
|
SELECT si.id
|
|
|
|
FROM cc_show_instances si
|
|
|
|
WHERE si.ends < :timeNow::TIMESTAMP
|
|
|
|
AND si.modified_instance = 'f'
|
|
|
|
ORDER BY si.ends DESC LIMIT 1;
|
|
|
|
SQL;
|
2021-10-11 16:10:47 +02:00
|
|
|
$id = Application_Common_Database($sql, [
|
2022-07-07 20:01:15 +02:00
|
|
|
':timeNow' => $p_timeNow,
|
|
|
|
], 'column');
|
2011-09-23 18:33:28 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $id ? new Application_Model_ShowInstance($id) : null;
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function GetCurrentShowInstance($p_timeNow)
|
|
|
|
{
|
2012-02-02 20:11:03 +01:00
|
|
|
/* Orderby si.starts descending, because in some cases
|
|
|
|
* we can have multiple shows overlapping each other. In
|
|
|
|
* this case, the show that started later is the one that
|
|
|
|
* is actually playing, and so this is the one we want.
|
|
|
|
*/
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-09-10 17:17:45 +02:00
|
|
|
SELECT si.id
|
|
|
|
FROM cc_show_instances si
|
|
|
|
WHERE si.starts <= :timeNow1::TIMESTAMP
|
|
|
|
AND si.ends > :timeNow2::TIMESTAMP
|
|
|
|
AND si.modified_instance = 'f'
|
|
|
|
ORDER BY si.starts DESC LIMIT 1
|
|
|
|
SQL;
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$id = Application_Common_Database($sql, [
|
2012-09-10 17:17:45 +02:00
|
|
|
':timeNow1' => $p_timeNow,
|
2022-07-07 20:01:15 +02:00
|
|
|
':timeNow2' => $p_timeNow,
|
|
|
|
], 'column');
|
2012-09-10 17:17:45 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $id ? new Application_Model_ShowInstance($id) : null;
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function GetNextShowInstance($p_timeNow)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-09-10 17:25:44 +02:00
|
|
|
SELECT si.id
|
|
|
|
FROM cc_show_instances si
|
|
|
|
WHERE si.starts > :timeNow::TIMESTAMP
|
|
|
|
AND si.modified_instance = 'f'
|
|
|
|
ORDER BY si.starts
|
|
|
|
LIMIT 1
|
|
|
|
SQL;
|
2021-10-11 16:10:47 +02:00
|
|
|
$id = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
['timeNow' => $p_timeNow],
|
|
|
|
'column'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $id ? new Application_Model_ShowInstance($id) : null;
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
2011-11-15 18:22:21 +01:00
|
|
|
|
2011-09-23 18:33:28 +02:00
|
|
|
// returns number of show instances that ends later than $day
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function GetShowInstanceCount($day)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-09-10 17:29:28 +02:00
|
|
|
SELECT count(*) AS cnt
|
|
|
|
FROM cc_show_instances
|
2012-09-10 20:14:44 +02:00
|
|
|
WHERE ends < :day
|
2012-09-10 17:29:28 +02:00
|
|
|
SQL;
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
return Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[':day' => $day],
|
|
|
|
'column'
|
|
|
|
);
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-29 22:57:28 +02:00
|
|
|
// this returns end timestamp of all shows that are in the range and has live DJ set up
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function GetEndTimeOfNextShowWithLiveDJ($p_startTime, $p_endTime)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-09-10 17:39:22 +02:00
|
|
|
SELECT ends
|
|
|
|
FROM cc_show_instances AS si
|
|
|
|
JOIN cc_show AS sh ON si.show_id = sh.id
|
|
|
|
WHERE si.ends > :startTime::TIMESTAMP
|
|
|
|
AND si.ends < :endTime::TIMESTAMP
|
|
|
|
AND (sh.live_stream_using_airtime_auth
|
|
|
|
OR live_stream_using_custom_auth)
|
2012-09-10 18:04:33 +02:00
|
|
|
ORDER BY si.ends
|
2012-09-10 17:39:22 +02:00
|
|
|
SQL;
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
return Application_Common_Database::prepareAndExecute($sql, [
|
2012-09-10 17:39:22 +02:00
|
|
|
':startTime' => $p_startTime,
|
2022-07-07 20:01:15 +02:00
|
|
|
':endTime' => $p_endTime,
|
|
|
|
], 'all');
|
2012-03-22 21:23:59 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function isRepeating()
|
|
|
|
{
|
2012-09-10 17:27:39 +02:00
|
|
|
return $this->getShow()->isRepeating();
|
2012-04-04 20:53:26 +02:00
|
|
|
}
|
2024-02-02 20:17:23 +01:00
|
|
|
|
|
|
|
public function trimOverbooked()
|
|
|
|
{
|
|
|
|
// Remove all scheduled items that start time after the show has ended
|
|
|
|
$sql = <<<'SQL'
|
|
|
|
delete
|
|
|
|
from
|
|
|
|
cc_schedule
|
|
|
|
where
|
|
|
|
id in (
|
|
|
|
select
|
|
|
|
s.id
|
|
|
|
from
|
|
|
|
cc_schedule s
|
|
|
|
left join cc_show_instances si on
|
|
|
|
s.instance_id = si.id
|
|
|
|
where
|
|
|
|
si.id = :instance_id
|
|
|
|
and si.ends < s.starts
|
|
|
|
and s.playout_status = 0 -- playout_status = 0 double check that si.ends < s.starts
|
|
|
|
);
|
|
|
|
SQL;
|
|
|
|
|
|
|
|
return Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[':instance_id' => $this->_instanceId],
|
|
|
|
'execute'
|
|
|
|
);
|
|
|
|
}
|
2011-09-23 18:33:28 +02:00
|
|
|
}
|