2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
2013-10-24 23:44:53 +02:00
|
|
|
use Airtime\CcShowQuery;
|
|
|
|
use Airtime\CcShowInstancesPeer;
|
|
|
|
use Airtime\CcShowInstancesQuery;
|
|
|
|
use Airtime\CcSchedulePeer;
|
|
|
|
use Airtime\CcShowDaysQuery;
|
|
|
|
|
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
|
|
|
|
2011-04-12 17:54:24 +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);
|
2012-07-16 03:17:13 +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
|
|
|
|
2011-02-10 00:10:46 +01:00
|
|
|
return $show->getDbBackgroundColor();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-29 18:47:34 +02:00
|
|
|
public function getHosts()
|
|
|
|
{
|
2012-09-12 18:00:53 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
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
|
|
|
|
2012-09-06 20:14:05 +02:00
|
|
|
$hosts = Application_Common_Database::prepareAndExecute( $sql,
|
2012-09-06 20:16:10 +02:00
|
|
|
array( ':show_id' => $this->getId() ), 'all');
|
2011-03-29 18:47:34 +02:00
|
|
|
|
2012-09-12 17:54:37 +02:00
|
|
|
$res = array();
|
|
|
|
foreach ($hosts as $host) {
|
|
|
|
$res[] = $host['first_name']." ".$host['last_name'];
|
|
|
|
}
|
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()
|
|
|
|
{
|
2012-09-12 17:59:27 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
SELECT subjs_id
|
|
|
|
FROM cc_show_hosts
|
|
|
|
WHERE show_id = :show_id
|
|
|
|
SQL;
|
2012-03-02 22:55:11 +01:00
|
|
|
|
2012-09-06 20:17:24 +02:00
|
|
|
$hosts = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql, array( ':show_id' => $this->getId() ), 'all');
|
2012-03-02 22:55:11 +01:00
|
|
|
|
|
|
|
return $hosts;
|
|
|
|
}
|
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
|
|
|
{
|
2011-12-02 22:22:54 +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.
|
|
|
|
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) {
|
2012-11-15 21:52:51 +01:00
|
|
|
return _("Shows can have a max length of 24 hours.");
|
2011-12-12 12:11:31 +01:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2013-12-04 21:48:32 +01:00
|
|
|
$utcTimezone = new DateTimeZone("UTC");
|
|
|
|
$nowDateTime = new DateTime("now", $utcTimezone);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2013-12-02 13:19:31 +01:00
|
|
|
//keep track of cc_show_day entries we need to update
|
|
|
|
$showDayIds = array();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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()) {
|
|
|
|
|
|
|
|
//convert instance to local timezone
|
|
|
|
$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()
|
|
|
|
->filterByDbFirstShow($startsDT->format("Y-m-d"))
|
|
|
|
->filterByDbStartTime($startsDT->format("H:i:s"))
|
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->findOne();
|
|
|
|
|
|
|
|
/* 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();
|
|
|
|
|
|
|
|
//exlcude edited instances from resize
|
|
|
|
$showInstances = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->filterByDbModifiedInstance(false)
|
|
|
|
->filterByDbId($excludeIds, criteria::NOT_IN)
|
|
|
|
->find();
|
|
|
|
} elseif ($ccShowDay->getDbRepeatType() == -1) {
|
|
|
|
array_push($showDayIds, $ccShowDay->getDbId());
|
|
|
|
|
|
|
|
//treat edited instance as separate show for resize
|
|
|
|
$showInstances = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbId($instanceId)
|
|
|
|
->find();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ccShowDays = $ccShow->getCcShowDayss();
|
|
|
|
foreach ($ccShowDays as $day) {
|
|
|
|
array_push($showDayIds, $day->getDbId());
|
|
|
|
}
|
|
|
|
|
|
|
|
$showInstances = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->find($con);
|
|
|
|
}
|
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
|
|
|
|
2013-12-02 13:19:31 +01:00
|
|
|
//keep track of instance ids for update show instances start/end times
|
|
|
|
$instanceIds = array();
|
2013-12-04 21:48:32 +01:00
|
|
|
$displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
|
|
|
|
2013-12-02 13:19:31 +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);
|
|
|
|
$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
|
|
|
|
2013-12-02 13:19:31 +01:00
|
|
|
//$newStartsDateTime = Application_Model_ShowInstance::addDeltas($startsDateTime, $deltaDay, $deltaMin);
|
2012-09-07 17:18:10 +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()) {
|
2012-11-15 21:52:51 +01: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
|
|
|
|
2012-08-24 21:27:04 +02:00
|
|
|
//convert our new starts/ends to UTC.
|
2013-12-02 13:19:31 +01:00
|
|
|
//$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(
|
2013-12-02 13:19:31 +01:00
|
|
|
$startsDateTime, $newEndsDateTime, true, $si->getDbId());
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-24 21:27:04 +02:00
|
|
|
if ($overlapping) {
|
2012-11-15 21:52:51 +01:00
|
|
|
return _("Cannot schedule overlapping shows.\nNote: Resizing a repeating show ".
|
|
|
|
"affects all of its repeats.");
|
2012-08-24 21:27:04 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-16 16:32:04 +01:00
|
|
|
|
|
|
|
$hours = $deltaMin/60;
|
2012-09-07 17:18:10 +02:00
|
|
|
$hours = ($hours > 0) ? floor($hours) : ceil($hours);
|
|
|
|
$mins = abs($deltaMin % 60);
|
2011-11-16 16:32:04 +01:00
|
|
|
|
2013-12-02 13:19:31 +01:00
|
|
|
$sql_gen = "UPDATE cc_show_instances ".
|
|
|
|
"SET ends = (ends + :deltaDay1::INTERVAL + :interval1::INTERVAL) ".
|
|
|
|
"WHERE (id IN (".implode($instanceIds, ",").") ".
|
|
|
|
"AND ends > :current_timestamp1) ".
|
|
|
|
"AND ((ends + :deltaDay2::INTERVAL + :interval2::INTERVAL - starts) <= interval '24:00')";
|
2012-09-06 21:47:07 +02:00
|
|
|
|
|
|
|
Application_Common_Database::prepareAndExecute($sql_gen,
|
|
|
|
array(
|
|
|
|
':deltaDay1' => "$deltaDay days",
|
|
|
|
':interval1' => "$hours:$mins",
|
2013-12-04 18:20:16 +01:00
|
|
|
':current_timestamp1' => $nowDateTime->format("Y-m-d H:i:s"),
|
2012-09-06 21:47:07 +02:00
|
|
|
':deltaDay2' => "$deltaDay days",
|
2012-09-19 21:03:16 +02:00
|
|
|
':interval2' => "$hours:$mins"
|
|
|
|
), "execute");
|
|
|
|
|
2013-12-02 13:19:31 +01:00
|
|
|
$sql_gen = "UPDATE cc_show_days ".
|
|
|
|
"SET duration = (CAST(duration AS interval) + :deltaDay3::INTERVAL + :interval3::INTERVAL) ".
|
|
|
|
"WHERE id IN (".implode($showDayIds, ",").") ".
|
|
|
|
"AND ((CAST(duration AS interval) + :deltaDay4::INTERVAL + :interval4::INTERVAL) <= interval '24:00')";
|
2012-09-19 21:03:16 +02:00
|
|
|
|
|
|
|
Application_Common_Database::prepareAndExecute($sql_gen,
|
|
|
|
array(
|
2012-09-06 21:47:07 +02:00
|
|
|
':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 {
|
|
|
|
//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()
|
2013-12-04 18:20:16 +01:00
|
|
|
->filterByDbEnds($nowDateTime->format("Y-m-d H:i:s"), Criteria::GREATER_THAN)
|
2013-12-02 13:19:31 +01:00
|
|
|
->filterByDbId($instanceIds, Criteria::IN)
|
2012-03-01 14:59:06 +01:00
|
|
|
->find($con);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-02-12 23:21:37 +01:00
|
|
|
$timeinfo = explode(" ", $day_timestamp);
|
|
|
|
|
|
|
|
CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->update(array('DbLastShow' => $timeinfo[0]));
|
|
|
|
|
2012-09-12 18:05:03 +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;
|
2012-09-17 18:32:39 +02:00
|
|
|
|
|
|
|
$rows = Application_Common_Database::prepareAndExecute( $sql, array(
|
2012-09-12 18:05:03 +02:00
|
|
|
':dayTimestamp' => $day_timestamp,
|
2012-09-17 18:32:39 +02:00
|
|
|
':showId' => $this->getId()), 'all');
|
|
|
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
try {
|
|
|
|
$showInstance = new Application_Model_ShowInstance($row["id"]);
|
|
|
|
$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.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* true if originated from recording, otherwise false.
|
|
|
|
*/
|
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)
|
|
|
|
->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().
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* true if show has rebroadcasts, otherwise false.
|
|
|
|
*/
|
|
|
|
public function isRebroadcast()
|
|
|
|
{
|
|
|
|
$showInstancesRow = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->filterByDbRebroadcast(1)
|
2011-11-18 18:20:25 +01:00
|
|
|
->filterByDbModifiedInstance(false)
|
2011-04-12 06:14:26 +02:00
|
|
|
->findOne();
|
|
|
|
|
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
|
|
|
|
* "x days" and time would HH:MM:SS
|
|
|
|
*
|
|
|
|
* @return array
|
2011-04-25 23:24:53 +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()
|
|
|
|
{
|
2012-09-07 18:10:07 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
SELECT day_offset,
|
|
|
|
start_time
|
|
|
|
FROM cc_show_rebroadcast
|
|
|
|
WHERE show_id = :showId
|
|
|
|
ORDER BY day_offset
|
|
|
|
SQL;
|
|
|
|
return Application_Common_Database::prepareAndExecute( $sql,
|
|
|
|
array( ':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.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* true if repeating shows, otherwise false.
|
|
|
|
*/
|
|
|
|
public function isRepeating()
|
|
|
|
{
|
|
|
|
$showDaysRow = CcShowDaysQuery::create()
|
2012-01-18 16:21:46 +01:00
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->findOne();
|
2011-04-12 06:14:26 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (!is_null($showDaysRow)) {
|
2011-04-12 06:14:26 +02:00
|
|
|
return ($showDaysRow->getDbRepeatType() != -1);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2011-04-12 06:14:26 +02:00
|
|
|
return false;
|
2012-01-18 16:21:46 +01:00
|
|
|
}
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
/**
|
2013-10-10 11:43:45 +02:00
|
|
|
* Get the repeat type of the show. Show can have repeat type of
|
|
|
|
* "weekly", "every 2 weeks", "monthly", "monthly on the same weekday",
|
|
|
|
* "every 3 weeks" and "every 4 weeks". These values are represented
|
|
|
|
* by 0, 1, 2, 3, 4 and 5, respectively.
|
2011-04-12 06:14:26 +02:00
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
* Return the integer corresponding to the repeat type.
|
|
|
|
*/
|
|
|
|
public function getRepeatType()
|
|
|
|
{
|
|
|
|
$showDaysRow = CcShowDaysQuery::create()
|
2012-04-01 21:51:03 +02:00
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->findOne();
|
2011-04-12 06:14:26 +02:00
|
|
|
|
2013-01-14 22:16:14 +01:00
|
|
|
if (!is_null($showDaysRow))
|
2011-04-12 06:14:26 +02:00
|
|
|
return $showDaysRow->getDbRepeatType();
|
2012-09-04 21:31:09 +02:00
|
|
|
else
|
2011-04-12 06:14:26 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the end date for a repeating show in the format yyyy-mm-dd
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* Return the end date for the repeating show or the empty
|
|
|
|
* string if there is no end.
|
|
|
|
*/
|
2012-04-01 21:51:03 +02:00
|
|
|
public function getRepeatingEndDate()
|
|
|
|
{
|
2012-09-07 18:18:13 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
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
|
|
|
|
2012-09-07 18:18:13 +02:00
|
|
|
$query = Application_Common_Database::prepareAndExecute( $sql,
|
|
|
|
array( 'showId' => $this->getId() ), 'column' );
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-09-07 18:18:13 +02:00
|
|
|
/* TODO: Why return empty string instead of false? very confusing --RG
|
|
|
|
*/
|
2012-04-19 22:54:38 +02:00
|
|
|
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()
|
|
|
|
{
|
2012-09-07 18:22:49 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
DELETE
|
|
|
|
FROM cc_show_instances
|
|
|
|
WHERE starts > :timestamp::TIMESTAMP
|
|
|
|
AND show_id = :showId
|
|
|
|
SQL;
|
|
|
|
Application_Common_Database::prepareAndExecute( $sql,
|
2013-01-14 22:16:14 +01:00
|
|
|
array( ':timestamp' => gmdate("Y-m-d H:i:s"),
|
2012-09-07 18:22:49 +02:00
|
|
|
':showId' => $this->getId()), '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()
|
|
|
|
{
|
2012-09-07 18:29:42 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
DELETE
|
|
|
|
FROM cc_show_instances
|
|
|
|
WHERE starts > :timestamp::TIMESTAMP
|
|
|
|
AND show_id :showId
|
|
|
|
AND rebroadcast 1
|
|
|
|
SQL;
|
|
|
|
Application_Common_Database::prepareAndExecute( $sql,
|
|
|
|
array( ':showId' => $this->getId(),
|
|
|
|
':timestamp' => gmdate("Y-m-d H:i:s")), '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
|
2012-09-04 21:25:18 +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(
|
|
|
|
"SELECT first_show, start_time, timezone FROM cc_show_days"
|
|
|
|
." WHERE show_id = :showId"
|
2011-11-20 20:46:01 +01:00
|
|
|
." ORDER BY first_show"
|
2012-09-04 21:26:12 +02:00
|
|
|
." LIMIT 1");
|
|
|
|
|
|
|
|
$stmt->bindParam(':showId', $showId);
|
|
|
|
$stmt->execute();
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-09-04 21:26:12 +02:00
|
|
|
if (!$stmt) {
|
2011-04-12 06:14:26 +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
|
|
|
|
2012-09-04 21:26:12 +02:00
|
|
|
$dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"]));
|
|
|
|
$dt->setTimezone(new DateTimeZone("UTC"));
|
|
|
|
|
|
|
|
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
|
|
|
|
* The start date in the format YYYY-MM-DD
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getStartDate()
|
|
|
|
{
|
2012-07-11 00:51:32 +02:00
|
|
|
list($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
|
2011-11-20 20:46:01 +01:00
|
|
|
* The start time in the format HH:MM
|
2011-04-25 23:24:53 +02:00
|
|
|
*/
|
2011-11-20 20:46:01 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getStartTime()
|
|
|
|
{
|
2012-07-11 00:51:32 +02:00
|
|
|
list(,$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.
|
|
|
|
* 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
|
|
|
|
* The end date in the format YYYY-MM-DD
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getEndDate()
|
|
|
|
{
|
2012-09-04 21:26:12 +02:00
|
|
|
$startDate = $this->getStartDate();
|
|
|
|
$startTime = $this->getStartTime();
|
|
|
|
$duration = $this->getDuration();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-06-03 20:53:01 +02:00
|
|
|
$startDateTime = new DateTime($startDate.' '.$startTime);
|
2012-09-04 21:26:12 +02:00
|
|
|
$duration = explode(":", $duration);
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-06-03 20:53:01 +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
|
|
|
|
* The start time in the format HH:MM:SS
|
|
|
|
*/
|
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
|
|
|
|
2011-06-03 20:53:01 +02:00
|
|
|
$startDateTime = new DateTime($startDate.' '.$startTime);
|
|
|
|
$duration = explode(":", $duration);
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-06-03 20:53:01 +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.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* true if the StartDate is in the past, false otherwise
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function isStartDateTimeInPast()
|
|
|
|
{
|
2013-12-10 22:45:05 +01:00
|
|
|
return (gmdate("Y-m-d H:i:s") > ($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
|
2011-11-15 15:20:33 +01:00
|
|
|
* A simple array containing all ID's of show instance
|
2011-11-12 04:55:46 +01:00
|
|
|
* scheduled in the future.
|
2011-04-25 23:24:53 +02:00
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getAllFutureInstanceIds()
|
|
|
|
{
|
2012-09-07 20:30:59 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
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;
|
|
|
|
$rows = Application_Common_Database::prepareAndExecute($sql,
|
|
|
|
array( ':showId' => $this->getId(),
|
|
|
|
':timestamp' => gmdate("Y-m-d H:i:s")), "all");
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-09-12 18:09:38 +02:00
|
|
|
$res = array();
|
|
|
|
foreach ($rows as $r) {
|
|
|
|
$res[] = $r['id'];
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2011-04-12 06:14:26 +02:00
|
|
|
//need to update cc_show_instances, cc_show_days
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2013-12-10 22:45:05 +01:00
|
|
|
$timestamp = gmdate("Y-m-d H:i:s");
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-09-04 20:55:23 +02:00
|
|
|
$stmt = $con->prepare("UPDATE cc_show_days "
|
2012-09-06 21:55:29 +02:00
|
|
|
."SET duration = :add_show_duration "
|
2012-09-04 20:55:23 +02:00
|
|
|
."WHERE show_id = :add_show_id" );
|
|
|
|
$stmt->execute( array(
|
2012-09-06 21:55:29 +02:00
|
|
|
':add_show_duration' => $p_data['add_show_duration'],
|
|
|
|
':add_show_id' => $p_data['add_show_id']
|
2012-09-04 20:55:23 +02:00
|
|
|
));
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-09-06 23:23:39 +02:00
|
|
|
|
2012-09-06 22:17:14 +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;
|
|
|
|
|
2013-01-14 22:16:14 +01:00
|
|
|
Application_Common_Database::prepareAndExecute( $sql, array(
|
2012-09-06 23:23:39 +02:00
|
|
|
':add_show_duration' => $p_data['add_show_duration'],
|
|
|
|
':show_id' => $p_data['add_show_id'],
|
|
|
|
':timestamp' => $timestamp), "execute");
|
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 getDuration($format=false)
|
|
|
|
{
|
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();
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2011-10-25 22:49:44 +02:00
|
|
|
$info = explode(':',$showDay->getDbDuration());
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-04-27 20:07:14 +02:00
|
|
|
return str_pad(intval($info[0]),2,'0',STR_PAD_LEFT).'h '.str_pad(intval($info[1]),2,'0',STR_PAD_LEFT).'m';
|
2011-06-03 20:53:01 +02:00
|
|
|
}
|
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(
|
|
|
|
$this->getId())->find();
|
2012-09-12 18:09:38 +02:00
|
|
|
$res = array();
|
|
|
|
foreach ($showDays as $showDay) {
|
|
|
|
$res[] = $showDay->getDbDay();
|
|
|
|
}
|
|
|
|
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()
|
|
|
|
{
|
2011-04-12 06:14:26 +02:00
|
|
|
return (!is_null($this->getInstance()));
|
|
|
|
}
|
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()
|
|
|
|
{
|
2011-11-16 18:35:02 +01:00
|
|
|
$showInstance = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbShowId($this->getId())
|
|
|
|
->findOne();
|
2011-11-23 18:47:44 +01:00
|
|
|
|
2011-11-16 18:35:02 +01:00
|
|
|
return $showInstance;
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-02-21 23:58:05 +01:00
|
|
|
/**
|
|
|
|
* returns info about live stream override info
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function getLiveStreamInfo()
|
|
|
|
{
|
2012-02-21 23:58:05 +01:00
|
|
|
$info = array();
|
2012-09-07 21:12:46 +02:00
|
|
|
if ($this->getId() == null) {
|
2012-02-21 23:58:05 +01:00
|
|
|
return $info;
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-02-21 23:58:05 +01:00
|
|
|
$ccShow = CcShowQuery::create()->findPK($this->_showId);
|
|
|
|
$info['custom_username'] = $ccShow->getDbLiveStreamUser();
|
|
|
|
$info['cb_airtime_auth'] = $ccShow->getDbLiveStreamUsingAirtimeAuth();
|
2012-09-04 21:26:12 +02:00
|
|
|
$info['cb_custom_auth'] = $ccShow->getDbLiveStreamUsingCustomAuth();
|
2012-03-02 22:55:11 +01:00
|
|
|
$info['custom_username'] = $ccShow->getDbLiveStreamUser();
|
|
|
|
$info['custom_password'] = $ccShow->getDbLiveStreamPass();
|
2012-02-21 23:58:05 +01:00
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2011-11-11 16:58:27 +01: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)
|
|
|
|
{
|
2011-11-11 16:58:27 +01:00
|
|
|
$timestamp = $p_dateTime->format("Y-m-d H:i:s");
|
2012-09-07 21:29:30 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
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;
|
|
|
|
try {
|
|
|
|
$row = Application_Common_Database::prepareAndExecute( $sql,
|
2012-09-12 18:18:06 +02:00
|
|
|
array( ':showId' => $this->getId(),
|
|
|
|
':timestamp' => $timestamp ), 'column');
|
2012-09-07 21:29:30 +02:00
|
|
|
return CcShowInstancesQuery::create()
|
|
|
|
->findPk($row);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-04-12 06:14:26 +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
|
|
|
*
|
2011-11-11 20:54:08 +01:00
|
|
|
* @param DateTime $start_timestamp
|
|
|
|
* In UTC time.
|
|
|
|
* @param DateTime $end_timestamp
|
|
|
|
* In UTC time.
|
2012-07-16 03:17:13 +02:00
|
|
|
* @param unknown_type $excludeInstance
|
|
|
|
* @param boolean $onlyRecord
|
2011-10-24 19:46:16 +02:00
|
|
|
* @return array
|
2011-03-30 23:27:14 +02:00
|
|
|
*/
|
2012-09-07 22:26:05 +02:00
|
|
|
public static function getShows($start_timestamp, $end_timestamp, $onlyRecord=FALSE)
|
2011-03-30 23:27:14 +02:00
|
|
|
{
|
2011-11-15 18:22:21 +01:00
|
|
|
//UTC DateTime object
|
2011-10-24 19:46:16 +02:00
|
|
|
$showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil();
|
|
|
|
//if application is requesting shows past our previous populated until date, generate shows up until this point.
|
2011-11-11 20:54:08 +01:00
|
|
|
if (is_null($showsPopUntil) || $showsPopUntil->getTimestamp() < $end_timestamp->getTimestamp()) {
|
2013-03-25 21:28:53 +01:00
|
|
|
$service_show = new Application_Service_ShowService();
|
2013-04-25 15:00:37 +02:00
|
|
|
$ccShow = $service_show->delegateInstanceCreation(null, $end_timestamp, true);
|
2011-10-24 19:46:16 +02:00
|
|
|
Application_Model_Preference::SetShowsPopulatedUntil($end_timestamp);
|
2011-03-30 23:27:14 +02:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2012-09-07 22:26:05 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
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,
|
|
|
|
show.color AS color,
|
|
|
|
show.background_color AS background_color,
|
2013-05-09 18:14:49 +02:00
|
|
|
show.linked AS linked,
|
2014-01-22 21:47:35 +01:00
|
|
|
si1.media_id AS media_id,
|
2012-09-07 22:26:05 +02:00
|
|
|
si1.id AS instance_id,
|
|
|
|
si1.created AS created,
|
|
|
|
si1.last_scheduled AS last_scheduled,
|
2014-01-22 21:47:35 +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;
|
2011-10-24 19:46:16 +02:00
|
|
|
//only want shows that are starting at the time or later.
|
2011-11-11 20:54:08 +01:00
|
|
|
$start_string = $start_timestamp->format("Y-m-d H:i:s");
|
|
|
|
$end_string = $end_timestamp->format("Y-m-d H:i:s");
|
2011-10-24 19:46:16 +02:00
|
|
|
if ($onlyRecord) {
|
2012-09-10 17:25:21 +02:00
|
|
|
$sql .= " AND (si1.starts >= :start::TIMESTAMP AND si1.starts < :end::TIMESTAMP)";
|
2012-09-07 22:53:16 +02:00
|
|
|
$sql .= " AND (si1.record = 1)";
|
2011-10-24 19:46:16 +02:00
|
|
|
|
2012-09-07 22:53:16 +02:00
|
|
|
return Application_Common_Database::prepareAndExecute( $sql,
|
|
|
|
array( ':start' => $start_string,
|
|
|
|
':end' => $end_string ), 'all');
|
2012-09-07 22:26:05 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-09-07 23:23:32 +02:00
|
|
|
$sql .= " ". <<<SQL
|
|
|
|
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;
|
2012-09-07 22:53:16 +02:00
|
|
|
return Application_Common_Database::prepareAndExecute( $sql,
|
|
|
|
array(
|
|
|
|
'start1' => $start_string,
|
|
|
|
'start2' => $start_string,
|
|
|
|
'start3' => $start_string,
|
|
|
|
'end1' => $end_string,
|
|
|
|
'end2' => $end_string,
|
|
|
|
'end3' => $end_string
|
|
|
|
), 'all');
|
2011-10-24 19:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function setNextPop($next_date, $show_id, $day)
|
|
|
|
{
|
|
|
|
$nextInfo = explode(" ", $next_date);
|
|
|
|
|
|
|
|
$repeatInfo = CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($show_id)
|
|
|
|
->filterByDbDay($day)
|
|
|
|
->findOne();
|
|
|
|
|
|
|
|
$repeatInfo->setDbNextPopDate($nextInfo[0])
|
|
|
|
->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
|
|
|
/**
|
|
|
|
*
|
2011-11-11 20:54:08 +01:00
|
|
|
* @param DateTime $start
|
|
|
|
* -in UTC time
|
|
|
|
* @param DateTime $end
|
|
|
|
* -in UTC time
|
2011-03-30 23:27:14 +02:00
|
|
|
* @param boolean $editable
|
|
|
|
*/
|
2012-07-23 01:14:29 +02:00
|
|
|
public static function &getFullCalendarEvents($p_start, $p_end, $p_editable=false)
|
2011-03-30 23:27:14 +02:00
|
|
|
{
|
2012-09-07 22:58:49 +02:00
|
|
|
$events = array();
|
2012-02-22 20:32:59 +01:00
|
|
|
$interval = $p_start->diff($p_end);
|
2012-09-07 22:58:49 +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(
|
|
|
|
$p_start, $p_end);
|
2013-01-23 22:12:16 +01:00
|
|
|
$isFull = Application_Model_ShowInstance::getIsFull($p_start, $p_end);
|
2013-12-04 21:06:07 +01:00
|
|
|
|
|
|
|
$displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
2013-12-04 21:48:32 +01: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) {
|
2011-11-16 18:35:02 +01:00
|
|
|
$options = array();
|
2011-06-06 20:05:35 +02:00
|
|
|
|
2011-11-16 18:35:02 +01:00
|
|
|
//only bother calculating percent for week or day view.
|
2012-04-01 21:51:03 +02:00
|
|
|
if (intval($days) <= 7) {
|
2012-02-22 20:32:59 +01:00
|
|
|
$options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]);
|
2011-11-16 18:35:02 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-22 17:51:53 +02:00
|
|
|
if (isset($show["parent_starts"])) {
|
2013-12-04 21:48:32 +01:00
|
|
|
$parentStartsDT = new DateTime($show["parent_starts"], $utcTimezone);
|
2012-05-22 17:51:53 +02:00
|
|
|
}
|
2012-09-04 20:55:23 +02:00
|
|
|
|
2013-01-14 22:16:14 +01:00
|
|
|
$startsDT = DateTime::createFromFormat("Y-m-d G:i:s",
|
2013-12-04 21:48:32 +01:00
|
|
|
$show["starts"], $utcTimezone);
|
2012-09-04 20:55:23 +02:00
|
|
|
$endsDT = DateTime::createFromFormat("Y-m-d G:i:s",
|
2013-12-04 21:48:32 +01:00
|
|
|
$show["ends"], $utcTimezone);
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-09-04 20:55:23 +02:00
|
|
|
if( $p_editable ) {
|
2013-01-23 23:33:34 +01:00
|
|
|
if ($show["record"] && $now > $startsDT) {
|
2012-09-04 20:55:23 +02:00
|
|
|
$options["editable"] = false;
|
|
|
|
} elseif ($show["rebroadcast"] &&
|
2013-01-23 23:33:34 +01:00
|
|
|
$now > $parentStartsDT) {
|
2012-09-04 20:55:23 +02:00
|
|
|
$options["editable"] = false;
|
2013-01-23 23:33:34 +01:00
|
|
|
} elseif ($now < $endsDT) {
|
2012-09-04 20:55:23 +02:00
|
|
|
$options["editable"] = true;
|
|
|
|
}
|
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
|
|
|
|
2012-10-19 19:22:00 +02:00
|
|
|
$options["show_empty"] = (array_key_exists($show['instance_id'],
|
2012-10-22 21:20:03 +02:00
|
|
|
$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)) {
|
|
|
|
$options["show_partial_filled"] = !$isFull[$show['instance_id']];
|
|
|
|
} else {
|
|
|
|
$options["show_partial_filled"] = true;
|
|
|
|
}
|
2012-09-04 20:55:23 +02:00
|
|
|
|
2013-01-23 23:33:34 +01:00
|
|
|
$event = array();
|
|
|
|
|
|
|
|
$event["id"] = intval($show["instance_id"]);
|
|
|
|
$event["title"] = $show["name"];
|
|
|
|
$event["start"] = $startsDT->format("Y-m-d H:i:s");
|
|
|
|
$event["end"] = $endsDT->format("Y-m-d H:i:s");
|
|
|
|
$event["allDay"] = false;
|
|
|
|
$event["showId"] = intval($show["show_id"]);
|
2013-05-09 18:14:49 +02:00
|
|
|
$event["linked"] = intval($show["linked"]);
|
2013-01-23 23:33:34 +01:00
|
|
|
$event["record"] = intval($show["record"]);
|
|
|
|
$event["rebroadcast"] = intval($show["rebroadcast"]);
|
2014-01-22 21:47:35 +01:00
|
|
|
//$event["soundcloud_id"] = is_null($show["soundcloud_id"])
|
|
|
|
// ? -1 : $show["soundcloud_id"];
|
2013-10-12 00:15:12 +02:00
|
|
|
|
|
|
|
//for putting the now playing icon on the show.
|
|
|
|
if ($now > $startsDT && $now < $endsDT) {
|
|
|
|
$event["nowPlaying"] = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$event["nowPlaying"] = false;
|
|
|
|
}
|
2013-01-23 23:33:34 +01:00
|
|
|
|
|
|
|
//event colouring
|
|
|
|
if ($show["color"] != "") {
|
|
|
|
$event["textColor"] = "#".$show["color"];
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2013-01-23 23:33:34 +01:00
|
|
|
if ($show["background_color"] != "") {
|
|
|
|
$event["color"] = "#".$show["background_color"];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($options as $key => $value) {
|
|
|
|
$event[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$events[] = $event;
|
|
|
|
}
|
2011-02-05 22:00:05 +01:00
|
|
|
return $events;
|
|
|
|
}
|
2012-04-01 21:51:03 +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.
|
2013-12-13 21:03:02 +01:00
|
|
|
*
|
|
|
|
* TODO when using propel properly this should be a method on the propel show instance model.
|
2012-02-22 20:32:59 +01:00
|
|
|
**/
|
2012-07-16 03:17:13 +02:00
|
|
|
private static function getPercentScheduled($p_starts, $p_ends, $p_time_filled)
|
|
|
|
{
|
2013-12-13 21:03:02 +01:00
|
|
|
$utcTimezone = new DatetimeZone("UTC");
|
|
|
|
$startDt = new DateTime($p_starts, $utcTimezone);
|
|
|
|
$endDt = new DateTime($p_ends, $utcTimezone);
|
|
|
|
$durationSeconds = intval($endDt->format("U")) - intval($startDt->format("U"));
|
|
|
|
$time_filled = Application_Common_DateHelper::playlistTimeToSeconds($p_time_filled);
|
2013-12-13 22:12:26 +01:00
|
|
|
if ($durationSeconds != 0) { //Prevent division by zero if the show duration somehow becomes zero.
|
2013-12-13 22:10:36 +01:00
|
|
|
$percent = ceil(( $time_filled / $durationSeconds) * 100);
|
|
|
|
} else {
|
|
|
|
$percent = 0;
|
|
|
|
}
|
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
|
|
|
*
|
2012-07-16 03:17:13 +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
|
|
|
*/
|
2012-09-04 19:12:35 +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) {
|
2013-12-10 22:45:05 +01:00
|
|
|
$timeNow = gmdate("Y-m-d H:i:s");
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2011-11-18 17:59:15 +01:00
|
|
|
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
|
2012-09-04 19:12:35 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
SELECT si.starts AS start_timestamp,
|
|
|
|
si.ends AS end_timestamp,
|
|
|
|
s.name,
|
|
|
|
s.id,
|
|
|
|
si.id AS instance_id,
|
|
|
|
si.record,
|
|
|
|
s.url,
|
|
|
|
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());
|
|
|
|
throw new Exception("Error: $msg");
|
|
|
|
}
|
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
|
|
|
}
|
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
|
|
|
*
|
2012-07-16 03:17:13 +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
|
|
|
*/
|
2012-09-04 19:12:35 +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
|
2012-04-01 21:51:03 +02:00
|
|
|
if ($timeEnd == "") {
|
2011-11-22 00:03:56 +01:00
|
|
|
$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
|
|
|
|
2011-11-18 17:59:15 +01:00
|
|
|
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
|
2012-09-04 19:12:35 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
SELECT si.starts AS start_timestamp,
|
|
|
|
si.ends AS end_timestamp,
|
|
|
|
s.name,
|
|
|
|
s.id,
|
|
|
|
si.id AS instance_id,
|
|
|
|
si.record,
|
|
|
|
s.url,
|
|
|
|
starts,
|
|
|
|
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
|
|
|
|
|
|
|
//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
|
|
|
|
if ($limit != "ALL") {
|
|
|
|
$sql .= PHP_EOL."LIMIT :lim";
|
|
|
|
$params = array(
|
2012-09-13 00:36:27 +02:00
|
|
|
':timeStart' => $timeStart,
|
|
|
|
':timeEnd' => $timeEnd,
|
2012-09-17 20:32:33 +02:00
|
|
|
':lim' => $limit);
|
|
|
|
} else {
|
|
|
|
$params = array(
|
|
|
|
':timeStart' => $timeStart,
|
|
|
|
':timeEnd' => $timeEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2012-09-07 21:14:33 +02:00
|
|
|
$sql = <<<SQL
|
|
|
|
SELECT column_name, character_maximum_length FROM information_schema.columns
|
|
|
|
WHERE table_name = 'cc_show' AND character_maximum_length > 0
|
|
|
|
SQL;
|
2013-05-09 21:53:12 +02:00
|
|
|
$result = Application_Common_Database::prepareAndExecute($sql);
|
2011-10-25 22:49:44 +02:00
|
|
|
$assocArray = array();
|
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'];
|
|
|
|
}
|
2011-10-24 19:27:53 +02:00
|
|
|
return $assocArray;
|
|
|
|
}
|
2013-01-24 18:13:55 +01:00
|
|
|
|
|
|
|
public static function getStartEndCurrentMonthView() {
|
|
|
|
$first_day_of_calendar_month_view = mktime(0, 0, 0, date("n"), 1);
|
|
|
|
$weekStart = Application_Model_Preference::GetWeekStartDay();
|
|
|
|
while (date('w', $first_day_of_calendar_month_view) != $weekStart) {
|
|
|
|
$first_day_of_calendar_month_view -= 60*60*24;
|
|
|
|
}
|
2013-01-24 20:02:50 +01:00
|
|
|
$last_day_of_calendar_view = $first_day_of_calendar_month_view + 3600*24*42;
|
2013-01-24 18:13:55 +01:00
|
|
|
|
|
|
|
$start = new DateTime("@".$first_day_of_calendar_month_view);
|
|
|
|
$end = new DateTime("@".$last_day_of_calendar_view);
|
|
|
|
|
|
|
|
return array($start, $end);
|
|
|
|
}
|
2013-01-24 20:02:50 +01:00
|
|
|
|
|
|
|
public static function getStartEndCurrentWeekView() {
|
|
|
|
$first_day_of_calendar_week_view = mktime(0, 0, 0, date("n"), date("j"));
|
|
|
|
$weekStart = Application_Model_Preference::GetWeekStartDay();
|
|
|
|
while (date('w', $first_day_of_calendar_week_view) != $weekStart) {
|
|
|
|
$first_day_of_calendar_week_view -= 60*60*24;
|
|
|
|
}
|
|
|
|
$last_day_of_calendar_view = $first_day_of_calendar_week_view + 3600*24*7;
|
|
|
|
|
|
|
|
$start = new DateTime("@".$first_day_of_calendar_week_view);
|
|
|
|
$end = new DateTime("@".$last_day_of_calendar_view);
|
|
|
|
|
|
|
|
return array($start, $end);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getStartEndCurrentDayView() {
|
|
|
|
$today = mktime(0, 0, 0, date("n"), date("j"));
|
|
|
|
$tomorrow = $today + 3600*24;
|
|
|
|
|
|
|
|
$start = new DateTime("@".$today);
|
|
|
|
$end = new DateTime("@".$tomorrow);
|
|
|
|
|
|
|
|
return array($start, $end);
|
|
|
|
}
|
2011-02-05 00:22:15 +01:00
|
|
|
}
|