2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
class Application_Model_Show
|
|
|
|
{
|
2011-04-12 17:54:24 +02:00
|
|
|
private $_showId;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-03-29 18:47:34 +02:00
|
|
|
|
2011-03-30 23:27:14 +02:00
|
|
|
$sql = "SELECT first_name, last_name
|
2011-03-29 18:47:34 +02:00
|
|
|
FROM cc_show_hosts LEFT JOIN cc_subjs ON cc_show_hosts.subjs_id = cc_subjs.id
|
2011-04-12 17:54:24 +02:00
|
|
|
WHERE show_id = {$this->_showId}";
|
2011-03-29 18:47:34 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$hosts = $con->query($sql)->fetchAll();
|
2011-03-29 18:47:34 +02:00
|
|
|
|
|
|
|
$res = array();
|
2012-04-01 21:51:03 +02:00
|
|
|
foreach ($hosts as $host) {
|
2011-03-30 23:27:14 +02:00
|
|
|
$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-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-03-02 22:55:11 +01:00
|
|
|
|
|
|
|
$sql = "SELECT subjs_id
|
|
|
|
FROM cc_show_hosts
|
|
|
|
WHERE show_id = {$this->_showId}";
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$hosts = $con->query($sql)->fetchAll();
|
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();
|
|
|
|
}
|
|
|
|
|
2011-11-16 16:32:04 +01:00
|
|
|
public function resizeShow($deltaDay, $deltaMin)
|
|
|
|
{
|
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) {
|
2011-12-13 11:10:04 +01:00
|
|
|
return "Shows can have a max length of 24 hours.";
|
2011-12-12 12:11:31 +01:00
|
|
|
}
|
2011-11-16 16:32:04 +01:00
|
|
|
|
|
|
|
$hours = $deltaMin/60;
|
2012-03-01 14:59:06 +01:00
|
|
|
if ($hours > 0) {
|
2011-11-16 16:32:04 +01:00
|
|
|
$hours = floor($hours);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2011-11-16 16:32:04 +01:00
|
|
|
$hours = ceil($hours);
|
2012-03-01 14:59:06 +01:00
|
|
|
}
|
2011-11-16 16:32:04 +01:00
|
|
|
|
|
|
|
$mins = abs($deltaMin%60);
|
|
|
|
|
|
|
|
//current timesamp in UTC.
|
2011-12-12 12:11:31 +01:00
|
|
|
$current_timestamp = gmdate("Y-m-d H:i:s");
|
2011-11-16 16:32:04 +01:00
|
|
|
|
|
|
|
//update all cc_show_instances that are in the future.
|
|
|
|
$sql = "UPDATE cc_show_instances SET ends = (ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}')
|
2012-04-16 20:57:53 +02:00
|
|
|
WHERE (show_id = {$this->_showId} AND ends > '$current_timestamp')
|
2011-12-12 12:11:31 +01:00
|
|
|
AND ((ends + interval '{$deltaDay} days' + interval '{$hours}:{$mins}' - starts) <= interval '24:00');";
|
2011-11-16 16:32:04 +01:00
|
|
|
|
|
|
|
//update cc_show_days so future shows can be created with the new duration.
|
2011-12-12 12:11:31 +01:00
|
|
|
//only setting new duration if it is less than or equal to 24 hours.
|
2011-11-16 16:32:04 +01:00
|
|
|
$sql = $sql . " UPDATE cc_show_days SET duration = (CAST(duration AS interval) + interval '{$deltaDay} days' + interval '{$hours}:{$mins}')
|
2011-12-12 12:11:31 +01:00
|
|
|
WHERE show_id = {$this->_showId}
|
|
|
|
AND ((CAST(duration AS interval) + interval '{$deltaDay} days' + interval '{$hours}:{$mins}') <= interval '24:00')";
|
2011-11-16 16:32:04 +01:00
|
|
|
|
|
|
|
//do both the queries at once.
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
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.
|
|
|
|
$instances = CcShowInstancesQuery::create()
|
2012-05-04 17:49:58 +02:00
|
|
|
->filterByDbEnds($current_timestamp, Criteria::GREATER_THAN)
|
2012-03-01 14:59:06 +01:00
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->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();
|
|
|
|
Logging::log("Couldn't update schedule status.");
|
|
|
|
Logging::log($e->getMessage());
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-02-12 23:21:37 +01:00
|
|
|
|
|
|
|
$timeinfo = explode(" ", $day_timestamp);
|
|
|
|
|
|
|
|
CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->update(array('DbLastShow' => $timeinfo[0]));
|
|
|
|
|
2011-11-16 18:35:02 +01:00
|
|
|
$sql = "UPDATE cc_show_instances
|
2011-11-18 18:20:25 +01:00
|
|
|
SET modified_instance = TRUE
|
2011-04-12 17:54:24 +02:00
|
|
|
WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}";
|
2011-02-12 23:21:37 +01:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-11-10 21:35:27 +01:00
|
|
|
// check if we can safely delete the show
|
|
|
|
$showInstancesRow = CcShowInstancesQuery::create()
|
|
|
|
->filterByDbShowId($this->_showId)
|
2011-11-18 18:20:25 +01:00
|
|
|
->filterByDbModifiedInstance(false)
|
2011-11-10 21:35:27 +01:00
|
|
|
->findOne();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (is_null($showInstancesRow)) {
|
2011-11-10 21:35:27 +01:00
|
|
|
$sql = "DELETE FROM cc_show WHERE id = {$this->_showId}";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-11-10 21:35:27 +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
|
|
|
/**
|
2011-11-12 04:55:46 +01:00
|
|
|
* This function is called when a repeating show is edited and the
|
|
|
|
* days that is repeats on have changed. More specifically, a day
|
|
|
|
* that the show originally repeated on has been "unchecked".
|
2011-11-15 15:20:33 +01:00
|
|
|
*
|
2011-11-12 04:55:46 +01:00
|
|
|
* Removes Show Instances that occur on days of the week specified
|
2011-04-12 06:14:26 +02:00
|
|
|
* by input array. For example, if array contains one value of "0",
|
2011-11-15 15:20:33 +01:00
|
|
|
* (0 = Sunday, 1=Monday) then all show instances that occur on
|
2011-11-12 04:55:46 +01:00
|
|
|
* Sunday are removed.
|
2011-04-12 06:14:26 +02:00
|
|
|
*
|
|
|
|
* @param array p_uncheckedDays
|
2011-11-25 16:07:03 +01:00
|
|
|
* An array specifying which days should be removed. (in the local timezone)
|
2011-04-12 06:14:26 +02:00
|
|
|
*/
|
|
|
|
public function removeUncheckedDaysInstances($p_uncheckedDays)
|
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-11-25 16:07:03 +01:00
|
|
|
//need to convert local doftw to UTC doftw (change made for 2.0 since shows are stored in UTC)
|
|
|
|
$daysRemovedUTC = array();
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-11-25 16:07:03 +01:00
|
|
|
$showDays = CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($this->getId())
|
|
|
|
->find();
|
2011-11-26 13:31:42 +01:00
|
|
|
|
|
|
|
Logging::log("Unchecked days:");
|
2012-07-16 03:17:13 +02:00
|
|
|
foreach ($p_uncheckedDays as $day) {
|
2011-11-26 13:31:42 +01:00
|
|
|
Logging::log($day);
|
|
|
|
}
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
foreach ($showDays as $showDay) {
|
2012-03-25 18:57:20 +02:00
|
|
|
//Logging::log("Local show day is: {$showDay->getDbDay()}");
|
|
|
|
//Logging::log("First show day is: {$showDay->getDbFirstShow()}");
|
|
|
|
//Logging::log("Id show days is: {$showDay->getDbId()}");
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2012-02-22 20:32:59 +01:00
|
|
|
if (in_array($showDay->getDbDay(), $p_uncheckedDays)) {
|
|
|
|
$showDay->reload();
|
|
|
|
//Logging::log("Local show day is: {$showDay->getDbDay()}");
|
|
|
|
//Logging::log("First show day is: {$showDay->getDbFirstShow()}");
|
|
|
|
//Logging::log("Id show days is: {$showDay->getDbId()}");
|
|
|
|
$startDay = new DateTime("{$showDay->getDbFirstShow()} {$showDay->getDbStartTime()}", new DateTimeZone($showDay->getDbTimezone()));
|
2012-03-25 18:57:20 +02:00
|
|
|
//Logging::log("Show start day: {$startDay->format('Y-m-d H:i:s')}");
|
2011-11-25 16:07:03 +01:00
|
|
|
$startDay->setTimezone(new DateTimeZone("UTC"));
|
2012-03-25 18:57:20 +02:00
|
|
|
//Logging::log("Show start day UTC: {$startDay->format('Y-m-d H:i:s')}");
|
2011-11-26 13:31:42 +01:00
|
|
|
$daysRemovedUTC[] = $startDay->format('w');
|
2012-03-25 18:57:20 +02:00
|
|
|
//Logging::log("UTC show day is: {$startDay->format('w')}");
|
2012-02-22 20:32:59 +01:00
|
|
|
}
|
2011-11-25 16:07:03 +01:00
|
|
|
}
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-11-25 16:07:03 +01:00
|
|
|
$uncheckedDaysImploded = implode(",", $daysRemovedUTC);
|
2011-04-12 06:14:26 +02:00
|
|
|
$showId = $this->getId();
|
2011-04-14 20:17:56 +02:00
|
|
|
|
2011-11-24 19:39:08 +01:00
|
|
|
$timestamp = gmdate("Y-m-d H:i:s");
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$sql = "DELETE FROM cc_show_instances"
|
|
|
|
." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)"
|
2011-04-14 20:17:56 +02:00
|
|
|
." AND starts > TIMESTAMP '$timestamp'"
|
2011-04-12 06:14:26 +02:00
|
|
|
." AND show_id = $showId";
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-04-25 23:24:53 +02: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 absolute start date for a recorded
|
|
|
|
* shows rebroadcasts. For example start date format would be
|
|
|
|
* YYYY-MM-DD and time would HH:MM
|
|
|
|
*
|
|
|
|
* @return array
|
2011-04-25 23:24:53 +02:00
|
|
|
* array of associate arrays containing "start_date" and "start_time"
|
2011-04-14 20:17:56 +02:00
|
|
|
*/
|
2011-04-12 23:29:35 +02:00
|
|
|
public function getRebroadcastsAbsolute()
|
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 23:29:35 +02:00
|
|
|
$showId = $this->getId();
|
2011-04-13 17:23:58 +02:00
|
|
|
|
2011-12-02 12:06:09 +01:00
|
|
|
$sql = "SELECT starts FROM cc_show_instances "
|
2012-01-17 12:45:05 +01:00
|
|
|
."WHERE instance_id = (SELECT id FROM cc_show_instances WHERE show_id = $showId ORDER BY starts LIMIT 1) AND rebroadcast = 1 "
|
2011-12-02 12:06:09 +01:00
|
|
|
."ORDER BY starts";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-03-25 18:57:20 +02:00
|
|
|
//Logging::log($sql);
|
2012-01-17 12:45:05 +01:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$rebroadcasts = $con->query($sql)->fetchAll();
|
2011-12-02 12:06:09 +01:00
|
|
|
|
|
|
|
$rebroadcastsLocal = array();
|
|
|
|
//get each rebroadcast show in cc_show_instances, convert to current timezone to get start date/time.
|
|
|
|
$i = 0;
|
|
|
|
foreach ($rebroadcasts as $show) {
|
|
|
|
$startDateTime = new DateTime($show["starts"], new DateTimeZone("UTC"));
|
|
|
|
$startDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
|
|
|
|
|
|
|
$rebroadcastsLocal[$i]["start_date"] = $startDateTime->format("Y-m-d");
|
|
|
|
$rebroadcastsLocal[$i]["start_time"] = $startDateTime->format("H:i");
|
|
|
|
|
|
|
|
$i = $i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rebroadcastsLocal;
|
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-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 23:29:35 +02:00
|
|
|
$showId = $this->getId();
|
|
|
|
$sql = "SELECT day_offset, start_time FROM cc_show_rebroadcast "
|
|
|
|
."WHERE show_id = $showId "
|
|
|
|
."ORDER BY day_offset";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
return $con->query($sql)->fetchAll();
|
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
|
|
|
/**
|
|
|
|
* Get the repeat type of the show. Show can have repeat
|
|
|
|
* type of "weekly", "bi-weekly" and "monthly". These values
|
2011-04-25 23:24:53 +02:00
|
|
|
* are represented by 0, 1, and 2 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
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (!is_null($showDaysRow)) {
|
2011-04-12 06:14:26 +02:00
|
|
|
return $showDaysRow->getDbRepeatType();
|
|
|
|
} else
|
2012-07-16 03:17:13 +02:00
|
|
|
|
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-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$showId = $this->getId();
|
|
|
|
$sql = "SELECT last_show FROM cc_show_days"
|
2011-04-22 06:58:01 +02:00
|
|
|
." WHERE show_id = $showId"
|
2011-04-22 03:50:50 +02:00
|
|
|
." ORDER BY last_show DESC";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$query = $con->query($sql)->fetchColumn(0);
|
2012-07-16 03:17:13 +02:00
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-04-12 23:29:35 +02:00
|
|
|
|
2012-01-17 12:45:05 +01:00
|
|
|
$timestamp = gmdate("Y-m-d H:i:s");
|
2011-04-14 20:17:56 +02:00
|
|
|
|
2011-04-12 23:29:35 +02:00
|
|
|
$showId = $this->getId();
|
2011-04-14 20:17:56 +02:00
|
|
|
$sql = "DELETE FROM cc_show_instances"
|
|
|
|
." WHERE starts > TIMESTAMP '$timestamp'"
|
|
|
|
." AND show_id = $showId";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
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()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-06-06 18:20:44 +02:00
|
|
|
|
2012-01-17 12:45:05 +01:00
|
|
|
$timestamp = gmdate("Y-m-d H:i:s");
|
2011-06-06 18:20:44 +02:00
|
|
|
|
|
|
|
$showId = $this->getId();
|
|
|
|
$sql = "DELETE FROM cc_show_instances"
|
|
|
|
." WHERE starts > TIMESTAMP '$timestamp'"
|
|
|
|
." AND show_id = $showId"
|
|
|
|
." AND rebroadcast = 1";
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-06-06 18:20:44 +02:00
|
|
|
}
|
2011-04-14 20:17:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes all show instances of current show after a
|
2011-11-12 04:55:46 +01:00
|
|
|
* certain date. Note that although not enforced, $p_date
|
|
|
|
* should never be in the past, as we never want to allow
|
|
|
|
* deletion of shows that have already occured.
|
2011-04-14 20:17:56 +02:00
|
|
|
*
|
|
|
|
* @param string $p_date
|
2011-05-31 00:12:57 +02:00
|
|
|
* The date which to delete after, if null deletes from the current timestamp.
|
2011-04-14 20:17:56 +02:00
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function removeAllInstancesFromDate($p_date=null)
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-04-12 06:14:26 +02:00
|
|
|
|
2012-01-17 12:45:05 +01:00
|
|
|
$timestamp = gmdate("Y-m-d H:i:s");
|
2011-04-14 20:17:56 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (is_null($p_date)) {
|
2012-04-13 23:45:28 +02:00
|
|
|
$date = new Application_Common_DateHelper;
|
2011-05-31 00:12:57 +02:00
|
|
|
$p_date = $date->getDate();
|
|
|
|
}
|
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$showId = $this->getId();
|
|
|
|
$sql = "DELETE FROM cc_show_instances "
|
2011-05-26 21:41:47 +02:00
|
|
|
." WHERE date(starts) >= DATE '$p_date'"
|
2011-04-14 20:17:56 +02:00
|
|
|
." AND starts > TIMESTAMP '$timestamp'"
|
|
|
|
." AND show_id = $showId";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-05-31 00:12:57 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-04-14 20:17:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes all show instances of current show before a
|
2011-11-15 15:20:33 +01:00
|
|
|
* certain date.
|
|
|
|
*
|
2011-11-12 04:55:46 +01:00
|
|
|
* This function is used in the case where a repeating show is being
|
|
|
|
* edited and the start date of the first show has been changed more
|
|
|
|
* into the future. In this case, delete any show instances that
|
|
|
|
* exist before the new start date.
|
2011-04-14 20:17:56 +02:00
|
|
|
*
|
|
|
|
* @param string $p_date
|
|
|
|
* The date which to delete before
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public function removeAllInstancesBeforeDate($p_date)
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-04-12 17:54:24 +02:00
|
|
|
|
2012-01-17 12:45:05 +01:00
|
|
|
$timestamp = gmdate("Y-m-d H:i:s");
|
2011-04-14 20:17:56 +02:00
|
|
|
|
2011-04-12 17:54:24 +02:00
|
|
|
$showId = $this->getId();
|
|
|
|
$sql = "DELETE FROM cc_show_instances "
|
2011-04-14 20:17:56 +02:00
|
|
|
." WHERE date(starts) < DATE '$p_date'"
|
|
|
|
." AND starts > TIMESTAMP '$timestamp'"
|
|
|
|
." AND show_id = $showId";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-04-12 17:54:24 +02:00
|
|
|
}
|
2012-07-11 00:51:32 +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
|
|
|
|
* The start date in the format YYYY-MM-DD
|
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();
|
2011-11-20 20:46:01 +01:00
|
|
|
$sql = "SELECT first_show, start_time, timezone FROM cc_show_days"
|
2011-04-22 03:50:50 +02:00
|
|
|
." WHERE show_id = $showId"
|
2011-11-20 20:46:01 +01:00
|
|
|
." ORDER BY first_show"
|
|
|
|
." LIMIT 1";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$query = $con->query($sql);
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($query->rowCount() == 0) {
|
2011-04-12 06:14:26 +02:00
|
|
|
return "";
|
|
|
|
} else {
|
2012-04-01 21:51:03 +02:00
|
|
|
$rows = $query->fetchAll();
|
2011-11-20 20:46:01 +01:00
|
|
|
$row = $rows[0];
|
2011-11-23 18:47:44 +01:00
|
|
|
|
2011-11-20 20:46:01 +01:00
|
|
|
$dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"]));
|
|
|
|
$dt->setTimezone(new DateTimeZone("UTC"));
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-04-25 00:22:39 +02:00
|
|
|
return $dt->format("Y-m-d H:i");
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-23 18:47:44 +01:00
|
|
|
|
2012-04-25 00:22:39 +02:00
|
|
|
/**
|
|
|
|
* Get the start date of the current show in UTC timezone.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* 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()
|
|
|
|
{
|
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('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()
|
|
|
|
{
|
2012-04-13 23:45:28 +02:00
|
|
|
$date = new Application_Common_DateHelper;
|
2011-11-20 20:46:01 +01:00
|
|
|
$current_timestamp = $date->getUtcTimestamp();
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-11-12 04:55:46 +01:00
|
|
|
return ($current_timestamp > ($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()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-04-14 20:17:56 +02:00
|
|
|
|
2012-04-13 23:45:28 +02:00
|
|
|
$date = new Application_Common_DateHelper;
|
2011-04-14 20:17:56 +02:00
|
|
|
$timestamp = $date->getTimestamp();
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$showId = $this->getId();
|
2011-04-14 20:17:56 +02:00
|
|
|
$sql = "SELECT id from cc_show_instances"
|
2011-04-12 17:54:24 +02:00
|
|
|
." WHERE show_id = $showId"
|
2011-11-16 18:59:01 +01:00
|
|
|
." AND starts > TIMESTAMP '$timestamp'"
|
2011-11-18 18:20:25 +01:00
|
|
|
." AND modified_instance != TRUE";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$rows = $con->query($sql)->fetchAll();
|
2011-04-12 06:14:26 +02:00
|
|
|
|
|
|
|
$instance_ids = array();
|
2012-04-01 21:51:03 +02:00
|
|
|
foreach ($rows as $row) {
|
2011-04-12 06:14:26 +02:00
|
|
|
$instance_ids[] = $row["id"];
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
return $instance_ids;
|
|
|
|
}
|
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();
|
2011-04-14 20:17:56 +02:00
|
|
|
|
2012-04-13 23:45:28 +02:00
|
|
|
$date = new Application_Common_DateHelper;
|
2012-04-17 21:43:18 +02:00
|
|
|
$timestamp = $date->getUtcTimestamp();
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$sql = "UPDATE cc_show_days "
|
|
|
|
."SET duration = '$p_data[add_show_duration]' "
|
|
|
|
."WHERE show_id = $p_data[add_show_id]";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$sql = "UPDATE cc_show_instances "
|
|
|
|
."SET ends = starts + INTERVAL '$p_data[add_show_duration]' "
|
2011-04-12 17:54:24 +02:00
|
|
|
."WHERE show_id = $p_data[add_show_id] "
|
2012-04-17 21:43:18 +02:00
|
|
|
."AND ends > TIMESTAMP '$timestamp'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
private function updateStartDateTime($p_data, $p_endDate)
|
|
|
|
{
|
2011-04-12 06:14:26 +02:00
|
|
|
//need to update cc_schedule, cc_show_instances, cc_show_days
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-04-14 20:17:56 +02:00
|
|
|
|
2012-04-13 23:45:28 +02:00
|
|
|
$date = new Application_Common_DateHelper;
|
2011-04-14 20:17:56 +02:00
|
|
|
$timestamp = $date->getTimestamp();
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-11-26 13:31:42 +01:00
|
|
|
//TODO fix this from overwriting info.
|
2011-04-12 06:14:26 +02:00
|
|
|
$sql = "UPDATE cc_show_days "
|
|
|
|
."SET start_time = TIME '$p_data[add_show_start_time]', "
|
|
|
|
."first_show = DATE '$p_data[add_show_start_date]', ";
|
2012-07-16 03:17:13 +02:00
|
|
|
if (strlen ($p_endDate) == 0) {
|
2011-04-12 06:14:26 +02:00
|
|
|
$sql .= "last_show = NULL ";
|
|
|
|
} else {
|
|
|
|
$sql .= "last_show = DATE '$p_endDate' ";
|
|
|
|
}
|
|
|
|
$sql .= "WHERE show_id = $p_data[add_show_id]";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-11-20 20:46:01 +01:00
|
|
|
$dtOld = new DateTime($this->getStartDate()." ".$this->getStartTime(), new DateTimeZone("UTC"));
|
|
|
|
$dtNew = new DateTime($p_data['add_show_start_date']." ".$p_data['add_show_start_time'], new DateTimeZone(date_default_timezone_get()));
|
|
|
|
$diff = $dtOld->getTimestamp() - $dtNew->getTimestamp();
|
2011-04-12 06:14:26 +02:00
|
|
|
|
|
|
|
$sql = "UPDATE cc_show_instances "
|
|
|
|
."SET starts = starts + INTERVAL '$diff sec', "
|
|
|
|
."ends = ends + INTERVAL '$diff sec' "
|
2011-04-12 17:54:24 +02:00
|
|
|
."WHERE show_id = $p_data[add_show_id] "
|
2011-04-25 23:24:53 +02:00
|
|
|
."AND starts > TIMESTAMP '$timestamp'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 17:54:24 +02:00
|
|
|
$showInstanceIds = $this->getAllFutureInstanceIds();
|
2012-07-16 03:17:13 +02:00
|
|
|
if (count($showInstanceIds) > 0 && $diff != 0) {
|
2011-04-12 06:14:26 +02:00
|
|
|
$showIdsImploded = implode(",", $showInstanceIds);
|
|
|
|
$sql = "UPDATE cc_schedule "
|
|
|
|
."SET starts = starts + INTERVAL '$diff sec', "
|
|
|
|
."ends = ends + INTERVAL '$diff sec' "
|
2011-04-25 23:24:53 +02:00
|
|
|
."WHERE instance_id IN ($showIdsImploded)";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
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()
|
|
|
|
{
|
2011-04-12 06:14:26 +02:00
|
|
|
$showDays = CcShowDaysQuery::create()->filterByDbShowId($this->getId())->find();
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$days = array();
|
2012-07-16 03:17:13 +02:00
|
|
|
foreach ($showDays as $showDay) {
|
2011-04-12 06:14:26 +02:00
|
|
|
array_push($days, $showDay->getDbDay());
|
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
return $days;
|
|
|
|
}
|
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-07-16 03:17:13 +02:00
|
|
|
if ($this->_showId == 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();
|
|
|
|
$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-07-16 03:17:13 +02:00
|
|
|
|
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)
|
|
|
|
{
|
2012-04-01 21:51:03 +02:00
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
2011-11-11 16:58:27 +01:00
|
|
|
$timestamp = $p_dateTime->format("Y-m-d H:i:s");
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$showId = $this->getId();
|
|
|
|
$sql = "SELECT id FROM cc_show_instances"
|
2011-10-25 22:49:44 +02:00
|
|
|
." WHERE date(starts) = date(TIMESTAMP '$timestamp') "
|
2012-05-23 20:55:55 +02:00
|
|
|
." AND show_id = $showId AND rebroadcast = 0";
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-04-24 23:52:07 +02:00
|
|
|
$query = $con->query($sql);
|
|
|
|
$row = ($query !== false) ? $query->fetchColumn(0) : null;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-11-16 18:35:02 +01:00
|
|
|
return CcShowInstancesQuery::create()
|
|
|
|
->findPk($row);
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-06-06 18:01:37 +02:00
|
|
|
public function deletePossiblyInvalidInstances($p_data, $p_endDate, $isRecorded, $repeatType)
|
2011-04-12 06:14:26 +02:00
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($p_data['add_show_repeats'] != $this->isRepeating()) {
|
2011-06-06 18:01:37 +02:00
|
|
|
//repeat option was toggled
|
|
|
|
$this->deleteAllInstances();
|
2011-05-31 00:12:57 +02:00
|
|
|
}
|
2011-04-12 06:14:26 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($p_data['add_show_duration'] != $this->getDuration()) {
|
2011-04-12 06:14:26 +02:00
|
|
|
//duration has changed
|
2011-06-06 18:01:37 +02:00
|
|
|
$this->updateDurationTime($p_data);
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-06-06 18:56:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($p_data['add_show_repeats']) {
|
2011-06-06 18:01:37 +02:00
|
|
|
if (($repeatType == 1 || $repeatType == 2) &&
|
|
|
|
$p_data['add_show_start_date'] != $this->getStartDate()){
|
|
|
|
|
2011-06-03 20:51:17 +02:00
|
|
|
//start date has changed when repeat type is bi-weekly or monthly.
|
|
|
|
//This screws up the repeating positions of show instances, so lets
|
2011-06-06 18:01:37 +02:00
|
|
|
//just delete them for now. (CC-2351)
|
|
|
|
|
|
|
|
$this->deleteAllInstances();
|
2011-06-03 20:51:17 +02:00
|
|
|
}
|
2011-06-06 18:01:37 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($repeatType != $this->getRepeatType()) {
|
2011-04-12 06:14:26 +02:00
|
|
|
//repeat type changed.
|
2011-06-06 18:01:37 +02:00
|
|
|
$this->deleteAllInstances();
|
2011-06-03 20:51:17 +02:00
|
|
|
} else {
|
2011-04-12 06:14:26 +02:00
|
|
|
//repeat type is the same, check if the days of the week are the same
|
|
|
|
$repeatingDaysChanged = false;
|
2011-06-06 18:01:37 +02:00
|
|
|
$showDaysArray = $this->getShowDays();
|
2012-07-16 03:17:13 +02:00
|
|
|
if (count($p_data['add_show_day_check']) == count($showDaysArray)) {
|
2011-04-12 06:14:26 +02:00
|
|
|
//same number of days checked, lets see if they are the same numbers
|
|
|
|
$intersect = array_intersect($p_data['add_show_day_check'], $showDaysArray);
|
2012-07-16 03:17:13 +02:00
|
|
|
if (count($intersect) != count($p_data['add_show_day_check'])) {
|
2011-04-12 06:14:26 +02:00
|
|
|
$repeatingDaysChanged = true;
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2011-04-12 06:14:26 +02:00
|
|
|
$repeatingDaysChanged = true;
|
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($repeatingDaysChanged) {
|
2011-04-12 06:14:26 +02:00
|
|
|
$daysRemoved = array_diff($showDaysArray, $p_data['add_show_day_check']);
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (count($daysRemoved) > 0) {
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-06-06 18:01:37 +02:00
|
|
|
$this->removeUncheckedDaysInstances($daysRemoved);
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
|
|
|
}
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2012-02-22 20:32:59 +01:00
|
|
|
if ($p_data['add_show_start_date'] != $this->getStartDate()
|
|
|
|
|| $p_data['add_show_start_time'] != $this->getStartTime()){
|
|
|
|
//start date/time has changed
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2012-02-22 20:32:59 +01:00
|
|
|
$newDate = strtotime($p_data['add_show_start_date']);
|
|
|
|
$oldDate = strtotime($this->getStartDate());
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($newDate > $oldDate) {
|
2012-02-22 20:32:59 +01:00
|
|
|
$this->removeAllInstancesBeforeDate($p_data['add_show_start_date']);
|
|
|
|
}
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2012-02-22 20:32:59 +01:00
|
|
|
$this->updateStartDateTime($p_data, $p_endDate);
|
|
|
|
}
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
//Check if end date for the repeat option has changed. If so, need to take care
|
|
|
|
//of deleting possible invalid Show Instances.
|
2012-07-16 03:17:13 +02:00
|
|
|
if ((strlen($this->getRepeatingEndDate()) == 0) == $p_data['add_show_no_end']) {
|
2011-04-12 06:14:26 +02:00
|
|
|
//show "Never Ends" option was toggled.
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($p_data['add_show_no_end']) {
|
|
|
|
} else {
|
2011-06-06 18:01:37 +02:00
|
|
|
$this->removeAllInstancesFromDate($p_endDate);
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($this->getRepeatingEndDate() != $p_data['add_show_end_date']) {
|
2011-04-12 06:14:26 +02:00
|
|
|
//end date was changed.
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
$newDate = strtotime($p_data['add_show_end_date']);
|
2011-06-06 18:01:37 +02:00
|
|
|
$oldDate = strtotime($this->getRepeatingEndDate());
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($newDate < $oldDate) {
|
2011-06-06 18:01:37 +02:00
|
|
|
$this->removeAllInstancesFromDate($p_endDate);
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 23:27:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a show.
|
|
|
|
*
|
2011-05-30 18:24:39 +02:00
|
|
|
* Note: end dates are non inclusive.
|
2011-03-30 23:27:14 +02:00
|
|
|
*
|
2012-07-16 03:17:13 +02:00
|
|
|
* @param array $data
|
2011-03-30 23:27:14 +02:00
|
|
|
* @return int
|
|
|
|
* Show ID
|
|
|
|
*/
|
|
|
|
public static function create($data)
|
2011-04-12 17:54:24 +02:00
|
|
|
{
|
2011-10-24 19:46:16 +02:00
|
|
|
$startDateTime = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time']);
|
2011-10-25 22:49:44 +02:00
|
|
|
$utcStartDateTime = clone $startDateTime;
|
2011-08-19 00:13:43 +02:00
|
|
|
$utcStartDateTime->setTimezone(new DateTimeZone('UTC'));
|
|
|
|
|
2011-04-12 17:54:24 +02:00
|
|
|
if ($data['add_show_no_end']) {
|
2011-08-19 00:13:43 +02:00
|
|
|
$endDate = NULL;
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($data['add_show_repeats']) {
|
2011-08-15 20:22:33 +02:00
|
|
|
$endDateTime = new DateTime($data['add_show_end_date']);
|
2011-10-24 19:46:16 +02:00
|
|
|
//$endDateTime->setTimezone(new DateTimeZone('UTC'));
|
2011-08-15 20:22:33 +02:00
|
|
|
$endDateTime->add(new DateInterval("P1D"));
|
2011-08-19 00:13:43 +02:00
|
|
|
$endDate = $endDateTime->format("Y-m-d");
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2011-08-15 20:22:33 +02:00
|
|
|
$endDateTime = new DateTime($data['add_show_start_date']);
|
2011-10-24 19:46:16 +02:00
|
|
|
//$endDateTime->setTimezone(new DateTimeZone('UTC'));
|
2011-08-15 20:22:33 +02:00
|
|
|
$endDateTime->add(new DateInterval("P1D"));
|
2011-08-19 00:13:43 +02:00
|
|
|
$endDate = $endDateTime->format("Y-m-d");
|
2011-04-12 17:54:24 +02:00
|
|
|
}
|
2010-12-08 21:40:53 +01:00
|
|
|
|
2011-10-24 19:46:16 +02:00
|
|
|
//What we are doing here is checking if the show repeats or if
|
2011-10-25 22:49:44 +02:00
|
|
|
//any repeating days have been checked. If not, then by default
|
|
|
|
//the "selected" DOW is the initial day.
|
2011-11-24 19:39:08 +01:00
|
|
|
//DOW in local time.
|
|
|
|
$startDow = date("w", $startDateTime->getTimestamp());
|
2011-04-12 17:54:24 +02:00
|
|
|
if (!$data['add_show_repeats']) {
|
|
|
|
$data['add_show_day_check'] = array($startDow);
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($data['add_show_repeats'] && $data['add_show_day_check'] == "") {
|
2011-02-11 01:36:39 +01:00
|
|
|
$data['add_show_day_check'] = array($startDow);
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
2010-12-10 21:44:36 +01:00
|
|
|
|
2011-02-06 05:21:52 +01:00
|
|
|
//find repeat type or set to a non repeating show.
|
2011-04-13 05:28:37 +02:00
|
|
|
$repeatType = ($data['add_show_repeats']) ? $data['add_show_repeat_type'] : -1;
|
2011-02-11 01:36:39 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($data['add_show_id'] == -1) {
|
2011-04-12 06:14:26 +02:00
|
|
|
$ccShow = new CcShow();
|
|
|
|
} else {
|
|
|
|
$ccShow = CcShowQuery::create()->findPK($data['add_show_id']);
|
2011-03-15 17:05:41 +01:00
|
|
|
}
|
2011-04-12 17:54:24 +02:00
|
|
|
$ccShow->setDbName($data['add_show_name']);
|
|
|
|
$ccShow->setDbDescription($data['add_show_description']);
|
2011-04-12 06:14:26 +02:00
|
|
|
$ccShow->setDbUrl($data['add_show_url']);
|
|
|
|
$ccShow->setDbGenre($data['add_show_genre']);
|
2011-04-12 17:54:24 +02:00
|
|
|
$ccShow->setDbColor($data['add_show_color']);
|
|
|
|
$ccShow->setDbBackgroundColor($data['add_show_background_color']);
|
2012-02-21 23:58:05 +01:00
|
|
|
$ccShow->setDbLiveStreamUsingAirtimeAuth($data['cb_airtime_auth'] == 1?true:false);
|
|
|
|
$ccShow->setDbLiveStreamUsingCustomAuth($data['cb_custom_auth'] == 1?true:false);
|
|
|
|
$ccShow->setDbLiveStreamUser($data['custom_username']);
|
|
|
|
$ccShow->setDbLiveStreamPass($data['custom_password']);
|
2011-04-12 17:54:24 +02:00
|
|
|
$ccShow->save();
|
2011-04-12 06:14:26 +02:00
|
|
|
|
|
|
|
$showId = $ccShow->getDbId();
|
2011-04-12 23:29:35 +02:00
|
|
|
|
2011-09-02 21:24:35 +02:00
|
|
|
$isRecorded = (isset($data['add_show_record']) && $data['add_show_record']) ? 1 : 0;
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($data['add_show_id'] != -1) {
|
2011-09-23 16:54:20 +02:00
|
|
|
$show = new Application_Model_Show($showId);
|
2011-08-19 00:13:43 +02:00
|
|
|
$show->deletePossiblyInvalidInstances($data, $endDate, $isRecorded, $repeatType);
|
2011-03-15 17:05:41 +01:00
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
//check if we are adding or updating a show, and if updating
|
|
|
|
//erase all the show's show_days information first.
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($data['add_show_id'] != -1) {
|
2011-04-12 06:14:26 +02:00
|
|
|
CcShowDaysQuery::create()->filterByDbShowId($data['add_show_id'])->delete();
|
2011-04-13 05:28:37 +02:00
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-02-09 00:22:51 +01:00
|
|
|
//don't set day for monthly repeat type, it's invalid.
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2) {
|
2011-02-09 00:22:51 +01:00
|
|
|
$showDay = new CcShowDays();
|
2011-10-24 19:46:16 +02:00
|
|
|
$showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
|
2011-08-19 00:13:43 +02:00
|
|
|
$showDay->setDbLastShow($endDate);
|
2011-10-24 19:46:16 +02:00
|
|
|
$showDay->setDbStartTime($startDateTime->format("H:i:s"));
|
2011-10-25 22:49:44 +02:00
|
|
|
$showDay->setDbTimezone(date_default_timezone_get());
|
2011-04-12 17:54:24 +02:00
|
|
|
$showDay->setDbDuration($data['add_show_duration']);
|
2011-04-12 23:29:35 +02:00
|
|
|
$showDay->setDbRepeatType($repeatType);
|
2011-04-12 17:54:24 +02:00
|
|
|
$showDay->setDbShowId($showId);
|
2011-03-15 17:05:41 +01:00
|
|
|
$showDay->setDbRecord($isRecorded);
|
2011-04-12 17:54:24 +02:00
|
|
|
$showDay->save();
|
2011-08-15 20:22:33 +02:00
|
|
|
} else {
|
2011-02-09 00:22:51 +01:00
|
|
|
foreach ($data['add_show_day_check'] as $day) {
|
2011-10-25 22:49:44 +02:00
|
|
|
$daysAdd=0;
|
|
|
|
$startDateTimeClone = clone $startDateTime;
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($startDow !== $day) {
|
2011-04-12 17:54:24 +02:00
|
|
|
if ($startDow > $day)
|
|
|
|
$daysAdd = 6 - $startDow + 1 + $day;
|
|
|
|
else
|
|
|
|
$daysAdd = $day - $startDow;
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-10-24 19:46:16 +02:00
|
|
|
$startDateTimeClone->add(new DateInterval("P".$daysAdd."D"));
|
2011-04-12 17:54:24 +02:00
|
|
|
}
|
2011-10-24 19:46:16 +02:00
|
|
|
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
|
2011-04-12 17:54:24 +02:00
|
|
|
$showDay = new CcShowDays();
|
2011-10-24 19:46:16 +02:00
|
|
|
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
|
2011-08-19 00:13:43 +02:00
|
|
|
$showDay->setDbLastShow($endDate);
|
2011-10-24 19:46:16 +02:00
|
|
|
$showDay->setDbStartTime($startDateTimeClone->format("H:i"));
|
2011-10-25 22:49:44 +02:00
|
|
|
$showDay->setDbTimezone(date_default_timezone_get());
|
2011-04-12 17:54:24 +02:00
|
|
|
$showDay->setDbDuration($data['add_show_duration']);
|
|
|
|
$showDay->setDbDay($day);
|
2011-04-12 23:29:35 +02:00
|
|
|
$showDay->setDbRepeatType($repeatType);
|
2011-04-12 17:54:24 +02:00
|
|
|
$showDay->setDbShowId($showId);
|
2011-03-15 17:05:41 +01:00
|
|
|
$showDay->setDbRecord($isRecorded);
|
2011-04-12 17:54:24 +02:00
|
|
|
$showDay->save();
|
2011-02-09 00:22:51 +01:00
|
|
|
}
|
2011-04-12 17:54:24 +02:00
|
|
|
}
|
2011-02-09 00:22:51 +01:00
|
|
|
}
|
2011-03-15 17:05:41 +01:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
//check if we are adding or updating a show, and if updating
|
2011-05-30 18:24:39 +02:00
|
|
|
//erase all the show's future show_rebroadcast information first.
|
2012-07-16 03:17:13 +02:00
|
|
|
if (($data['add_show_id'] != -1) && isset($data['add_show_rebroadcast']) && $data['add_show_rebroadcast']) {
|
2011-05-30 18:24:39 +02:00
|
|
|
CcShowRebroadcastQuery::create()
|
|
|
|
->filterByDbShowId($data['add_show_id'])
|
|
|
|
->delete();
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-03-15 20:20:10 +01:00
|
|
|
//adding rows to cc_show_rebroadcast
|
2011-05-31 00:12:57 +02:00
|
|
|
if (($isRecorded && $data['add_show_rebroadcast']) && ($repeatType != -1)) {
|
2011-04-14 17:31:44 +02:00
|
|
|
for ($i=1; $i<=10; $i++) {
|
2011-03-30 23:27:14 +02:00
|
|
|
if ($data['add_show_rebroadcast_date_'.$i]) {
|
2011-03-18 05:20:38 +01:00
|
|
|
$showRebroad = new CcShowRebroadcast();
|
|
|
|
$showRebroad->setDbDayOffset($data['add_show_rebroadcast_date_'.$i]);
|
|
|
|
$showRebroad->setDbStartTime($data['add_show_rebroadcast_time_'.$i]);
|
|
|
|
$showRebroad->setDbShowId($showId);
|
|
|
|
$showRebroad->save();
|
|
|
|
}
|
2011-03-15 20:20:10 +01:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($isRecorded && $data['add_show_rebroadcast'] && ($repeatType == -1)) {
|
2011-04-14 17:31:44 +02:00
|
|
|
for ($i=1; $i<=10; $i++) {
|
|
|
|
if ($data['add_show_rebroadcast_date_absolute_'.$i]) {
|
2011-08-15 20:22:33 +02:00
|
|
|
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
|
2011-04-14 17:31:44 +02:00
|
|
|
$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
|
2011-04-12 17:54:24 +02:00
|
|
|
$r = $con->query($sql);
|
|
|
|
$offset_days = $r->fetchColumn(0);
|
2011-03-15 20:20:10 +01:00
|
|
|
|
|
|
|
$showRebroad = new CcShowRebroadcast();
|
|
|
|
$showRebroad->setDbDayOffset($offset_days." days");
|
2011-04-14 17:31:44 +02:00
|
|
|
$showRebroad->setDbStartTime($data['add_show_rebroadcast_time_absolute_'.$i]);
|
2011-03-15 20:20:10 +01:00
|
|
|
$showRebroad->setDbShowId($showId);
|
|
|
|
$showRebroad->save();
|
|
|
|
}
|
|
|
|
}
|
2011-03-15 17:05:41 +01:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2011-04-12 06:14:26 +02:00
|
|
|
//check if we are adding or updating a show, and if updating
|
|
|
|
//erase all the show's show_rebroadcast information first.
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($data['add_show_id'] != -1) {
|
2011-04-12 06:14:26 +02:00
|
|
|
CcShowHostsQuery::create()->filterByDbShow($data['add_show_id'])->delete();
|
|
|
|
}
|
2011-03-30 23:27:14 +02:00
|
|
|
if (is_array($data['add_show_hosts'])) {
|
2011-02-11 17:52:11 +01:00
|
|
|
//add selected hosts to cc_show_hosts table.
|
2011-04-12 17:54:24 +02:00
|
|
|
foreach ($data['add_show_hosts'] as $host) {
|
|
|
|
$showHost = new CcShowHosts();
|
|
|
|
$showHost->setDbShow($showId);
|
|
|
|
$showHost->setDbHost($host);
|
|
|
|
$showHost->save();
|
|
|
|
}
|
2011-02-11 17:52:11 +01:00
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-03-01 14:59:06 +01:00
|
|
|
if ($data['add_show_id'] != -1) {
|
|
|
|
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
|
|
|
$con->beginTransaction();
|
|
|
|
|
|
|
|
//current timesamp in UTC.
|
|
|
|
$current_timestamp = gmdate("Y-m-d H:i:s");
|
|
|
|
|
|
|
|
try {
|
|
|
|
//update the status flag in cc_schedule.
|
|
|
|
$instances = CcShowInstancesQuery::create()
|
2012-04-16 18:31:15 +02:00
|
|
|
->filterByDbEnds($current_timestamp, Criteria::GREATER_THAN)
|
2012-03-01 14:59:06 +01:00
|
|
|
->filterByDbShowId($data['add_show_id'])
|
|
|
|
->find($con);
|
|
|
|
|
|
|
|
foreach ($instances as $instance) {
|
2012-03-13 22:46:13 +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();
|
|
|
|
Logging::log("Couldn't update schedule status.");
|
|
|
|
Logging::log($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-23 16:54:20 +02:00
|
|
|
Application_Model_Show::populateShowUntil($showId);
|
2011-09-26 21:19:04 +02:00
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-03-30 23:27:14 +02:00
|
|
|
return $showId;
|
2011-04-12 17:54:24 +02:00
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-03-30 23:27:14 +02:00
|
|
|
/**
|
2011-10-24 19:46:16 +02:00
|
|
|
* Generate repeating show instances for a single show up to the given date.
|
2012-04-17 21:43:18 +02:00
|
|
|
* It will always try to use enddate from DB but if that's empty, it will use
|
|
|
|
* time now.
|
2011-04-02 00:25:00 +02:00
|
|
|
*
|
2011-10-24 19:46:16 +02:00
|
|
|
* @param int $p_showId
|
2011-03-30 23:27:14 +02:00
|
|
|
*/
|
2012-04-17 21:43:18 +02:00
|
|
|
public static function populateShowUntil($p_showId)
|
2011-03-22 14:55:33 +01:00
|
|
|
{
|
2012-04-01 21:51:03 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-04-19 23:03:13 +02:00
|
|
|
$date = Application_Model_Preference::GetShowsPopulatedUntil();
|
2010-12-09 23:02:37 +01:00
|
|
|
|
2012-04-17 21:43:18 +02:00
|
|
|
if (is_null($date)) {
|
|
|
|
$p_populateUntilDateTime = new DateTime("now", new DateTimeZone('UTC'));
|
|
|
|
Application_Model_Preference::SetShowsPopulatedUntil($p_populateUntilDateTime);
|
|
|
|
} else {
|
|
|
|
$p_populateUntilDateTime = $date;
|
2011-04-04 06:02:35 +02:00
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-10-24 19:46:16 +02:00
|
|
|
$sql = "SELECT * FROM cc_show_days WHERE show_id = $p_showId";
|
2012-04-01 21:51:03 +02:00
|
|
|
$res = $con->query($sql)->fetchAll();
|
2011-03-05 17:53:29 +01:00
|
|
|
|
2012-04-25 21:09:58 +02:00
|
|
|
foreach ($res as $showDaysRow) {
|
|
|
|
Application_Model_Show::populateShow($showDaysRow, $p_populateUntilDateTime);
|
2011-03-05 17:53:29 +01:00
|
|
|
}
|
2011-10-24 19:46:16 +02:00
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-10-25 22:49:44 +02:00
|
|
|
/**
|
|
|
|
* We are going to use cc_show_days as a template, to generate Show Instances. This function
|
|
|
|
* is basically a dispatcher that looks at the show template, and sends it to the correct function
|
|
|
|
* so that Show Instance generation can begin. After the all show instances have been created, pushes
|
|
|
|
* the schedule to Pypo.
|
|
|
|
*
|
|
|
|
* @param array $p_showRow
|
|
|
|
* A row from cc_show_days table
|
2012-04-17 21:43:18 +02:00
|
|
|
* @param DateTime $p_populateUntilDateTime
|
2011-10-25 22:49:44 +02:00
|
|
|
* DateTime object in UTC time.
|
2011-11-15 15:20:33 +01:00
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
private static function populateShow($p_showDaysRow, $p_populateUntilDateTime)
|
|
|
|
{
|
|
|
|
if ($p_showDaysRow["repeat_type"] == -1) {
|
2012-04-25 21:09:58 +02:00
|
|
|
Application_Model_Show::populateNonRepeatingShow($p_showDaysRow, $p_populateUntilDateTime);
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($p_showDaysRow["repeat_type"] == 0) {
|
2012-04-25 21:09:58 +02:00
|
|
|
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P7D');
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($p_showDaysRow["repeat_type"] == 1) {
|
2012-04-25 21:09:58 +02:00
|
|
|
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P14D');
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($p_showDaysRow["repeat_type"] == 2) {
|
2012-04-25 21:09:58 +02:00
|
|
|
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P1M');
|
2011-10-24 19:46:16 +02:00
|
|
|
}
|
2011-10-25 22:49:44 +02:00
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
2011-02-09 00:22:51 +01:00
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-10-25 22:49:44 +02:00
|
|
|
/**
|
|
|
|
* Creates a single show instance. If the show is recorded, it may have multiple
|
|
|
|
* rebroadcast dates, and so this function will create those as well.
|
|
|
|
*
|
|
|
|
* @param array $p_showRow
|
|
|
|
* A row from cc_show_days table
|
2012-04-17 21:43:18 +02:00
|
|
|
* @param DateTime $p_populateUntilDateTime
|
2011-10-25 22:49:44 +02:00
|
|
|
* DateTime object in UTC time.
|
2011-11-15 15:20:33 +01:00
|
|
|
*/
|
2012-04-17 21:43:18 +02:00
|
|
|
private static function populateNonRepeatingShow($p_showRow, $p_populateUntilDateTime)
|
2011-03-22 14:55:33 +01:00
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-10-25 22:49:44 +02:00
|
|
|
$show_id = $p_showRow["show_id"];
|
|
|
|
$first_show = $p_showRow["first_show"]; //non-UTC
|
|
|
|
$start_time = $p_showRow["start_time"]; //non-UTC
|
|
|
|
$duration = $p_showRow["duration"];
|
|
|
|
$day = $p_showRow["day"];
|
|
|
|
$record = $p_showRow["record"];
|
|
|
|
$timezone = $p_showRow["timezone"];
|
2011-10-24 19:46:16 +02:00
|
|
|
$start = $first_show." ".$start_time;
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2011-11-23 18:47:44 +01:00
|
|
|
//start & end UTC DateTimes for the show.
|
|
|
|
list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start, $duration, $timezone);
|
2012-04-17 21:43:18 +02:00
|
|
|
if ($utcStartDateTime->getTimestamp() < $p_populateUntilDateTime->getTimestamp()) {
|
2011-11-23 18:47:44 +01:00
|
|
|
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
|
2011-06-02 21:56:54 +02:00
|
|
|
|
2011-09-23 16:54:20 +02:00
|
|
|
$show = new Application_Model_Show($show_id);
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($show->hasInstance()) {
|
2011-04-14 23:57:08 +02:00
|
|
|
$ccShowInstance = $show->getInstance();
|
|
|
|
$newInstance = false;
|
2011-10-25 22:49:44 +02:00
|
|
|
} else {
|
2011-04-14 23:57:08 +02:00
|
|
|
$ccShowInstance = new CcShowInstances();
|
|
|
|
$newInstance = true;
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-06-06 18:01:37 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) {
|
2011-05-30 21:07:44 +02:00
|
|
|
$ccShowInstance->setDbShowId($show_id);
|
2011-10-25 22:49:44 +02:00
|
|
|
$ccShowInstance->setDbStarts($utcStartDateTime);
|
|
|
|
$ccShowInstance->setDbEnds($utcEndDateTime);
|
2011-05-30 21:07:44 +02:00
|
|
|
$ccShowInstance->setDbRecord($record);
|
|
|
|
$ccShowInstance->save();
|
|
|
|
}
|
2011-02-05 22:00:05 +01:00
|
|
|
|
2011-04-14 23:57:08 +02:00
|
|
|
$show_instance_id = $ccShowInstance->getDbId();
|
2011-09-23 16:54:20 +02:00
|
|
|
$showInstance = new Application_Model_ShowInstance($show_instance_id);
|
2011-03-15 20:20:10 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (!$newInstance) {
|
2011-04-14 23:57:08 +02:00
|
|
|
$showInstance->correctScheduleStartTimes();
|
|
|
|
}
|
2011-04-25 23:24:53 +02:00
|
|
|
|
2011-03-15 20:20:10 +01:00
|
|
|
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
|
2012-04-01 21:51:03 +02:00
|
|
|
$rebroadcasts = $con->query($sql)->fetchAll();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($showInstance->isRecorded()) {
|
2012-07-11 00:51:32 +02:00
|
|
|
$showInstance->deleteRebroadcasts();
|
|
|
|
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
|
2012-04-25 21:09:58 +02:00
|
|
|
}
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-10-25 22:49:44 +02:00
|
|
|
/**
|
2011-11-15 15:20:33 +01:00
|
|
|
* Creates a 1 or more than 1 show instances (user has stated this show repeats). If the show
|
|
|
|
* is recorded, it may have multiple rebroadcast dates, and so this function will create
|
2011-10-25 22:49:44 +02:00
|
|
|
* those as well.
|
|
|
|
*
|
|
|
|
* @param array $p_showRow
|
|
|
|
* A row from cc_show_days table
|
2012-04-17 21:43:18 +02:00
|
|
|
* @param DateTime $p_populateUntilDateTime
|
2011-11-15 15:20:33 +01:00
|
|
|
* DateTime object in UTC time. "shows_populated_until" date YY-mm-dd in cc_pref
|
2011-10-25 22:49:44 +02:00
|
|
|
* @param string $p_interval
|
2011-11-15 15:20:33 +01:00
|
|
|
* Period of time between repeating shows (in php DateInterval notation 'P7D')
|
|
|
|
*/
|
2012-04-25 21:09:58 +02:00
|
|
|
private static function populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, $p_interval)
|
2011-03-30 23:27:14 +02:00
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-04-25 21:09:58 +02:00
|
|
|
$show_id = $p_showDaysRow["show_id"];
|
|
|
|
$next_pop_date = $p_showDaysRow["next_pop_date"];
|
|
|
|
$first_show = $p_showDaysRow["first_show"]; //non-UTC
|
|
|
|
$last_show = $p_showDaysRow["last_show"]; //non-UTC
|
|
|
|
$start_time = $p_showDaysRow["start_time"]; //non-UTC
|
|
|
|
$duration = $p_showDaysRow["duration"];
|
|
|
|
$day = $p_showDaysRow["day"];
|
|
|
|
$record = $p_showDaysRow["record"];
|
|
|
|
$timezone = $p_showDaysRow["timezone"];
|
2011-10-24 19:46:16 +02:00
|
|
|
|
2011-11-23 18:47:44 +01:00
|
|
|
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
|
2011-02-06 05:21:52 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (isset($next_pop_date)) {
|
2011-10-24 23:26:45 +02:00
|
|
|
$start = $next_pop_date." ".$start_time;
|
2011-10-24 19:46:16 +02:00
|
|
|
} else {
|
|
|
|
$start = $first_show." ".$start_time;
|
2011-02-06 05:21:52 +01:00
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-04-13 23:45:28 +02:00
|
|
|
$utcStartDateTime = Application_Common_DateHelper::ConvertToUtcDateTime($start, $timezone);
|
2011-11-15 15:20:33 +01:00
|
|
|
//convert $last_show into a UTC DateTime object, or null if there is no last show.
|
2012-04-13 23:45:28 +02:00
|
|
|
$utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-03-15 17:05:41 +01:00
|
|
|
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
|
2012-04-01 21:51:03 +02:00
|
|
|
$rebroadcasts = $con->query($sql)->fetchAll();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-09-23 16:54:20 +02:00
|
|
|
$show = new Application_Model_Show($show_id);
|
2011-02-09 00:22:51 +01:00
|
|
|
|
2012-04-19 23:03:13 +02:00
|
|
|
while ($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp()
|
2011-11-15 15:20:33 +01:00
|
|
|
&& (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){
|
|
|
|
|
2012-06-13 17:35:14 +02:00
|
|
|
list($utcStartDateTime, $utcEndDateTime) = self::createUTCStartEndDateTime($start, $duration, $timezone);
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($show->hasInstanceOnDate($utcStartDateTime)) {
|
2011-10-25 22:49:44 +02:00
|
|
|
$ccShowInstance = $show->getInstanceOnDate($utcStartDateTime);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($ccShowInstance->getDbModifiedInstance()) {
|
2012-06-08 23:58:21 +02:00
|
|
|
//show instance on this date has been deleted.
|
2012-06-13 00:51:22 +02:00
|
|
|
list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);
|
2012-06-08 23:58:21 +02:00
|
|
|
continue;
|
2012-04-25 21:09:58 +02:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2011-04-14 23:57:08 +02:00
|
|
|
$newInstance = false;
|
2011-04-12 06:14:26 +02:00
|
|
|
} else {
|
2011-04-14 23:57:08 +02:00
|
|
|
$ccShowInstance = new CcShowInstances();
|
|
|
|
$newInstance = true;
|
2011-04-12 06:14:26 +02:00
|
|
|
}
|
2011-06-06 18:01:37 +02:00
|
|
|
|
2011-06-02 21:56:54 +02:00
|
|
|
/* When editing the start/end time of a repeating show, we don't want to
|
2011-06-06 18:01:37 +02:00
|
|
|
* change shows that started in the past. So check the start time.
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) {
|
2011-05-30 18:24:39 +02:00
|
|
|
$ccShowInstance->setDbShowId($show_id);
|
2011-10-25 22:49:44 +02:00
|
|
|
$ccShowInstance->setDbStarts($utcStartDateTime);
|
|
|
|
$ccShowInstance->setDbEnds($utcEndDateTime);
|
2011-05-30 18:24:39 +02:00
|
|
|
$ccShowInstance->setDbRecord($record);
|
|
|
|
$ccShowInstance->save();
|
|
|
|
}
|
2011-04-14 23:57:08 +02:00
|
|
|
|
2011-11-11 16:58:27 +01:00
|
|
|
|
2011-04-14 23:57:08 +02:00
|
|
|
$show_instance_id = $ccShowInstance->getDbId();
|
2011-09-23 16:54:20 +02:00
|
|
|
$showInstance = new Application_Model_ShowInstance($show_instance_id);
|
2011-02-09 00:22:51 +01:00
|
|
|
|
2011-10-25 22:49:44 +02:00
|
|
|
/* If we are updating a show then make sure that the scheduled content within
|
|
|
|
* the show is updated to the correct time. */
|
2012-07-16 03:17:13 +02:00
|
|
|
if (!$newInstance) {
|
2011-04-14 23:57:08 +02:00
|
|
|
$showInstance->correctScheduleStartTimes();
|
|
|
|
}
|
2011-03-15 17:05:41 +01:00
|
|
|
|
2012-04-25 21:09:58 +02:00
|
|
|
$showInstance->deleteRebroadcasts();
|
|
|
|
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
|
2012-06-13 00:51:22 +02:00
|
|
|
list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-06-08 23:58:21 +02:00
|
|
|
}
|
2011-11-23 19:11:48 +01:00
|
|
|
|
2012-06-08 23:58:21 +02:00
|
|
|
Application_Model_Show::setNextPop($start, $show_id, $day);
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
private static function advanceRepeatingDate($p_interval, $start, $timezone)
|
|
|
|
{
|
2012-07-06 21:40:16 +02:00
|
|
|
$startDt = new DateTime($start, new DateTimeZone($timezone));
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($p_interval == 'P1M') {
|
2012-06-08 23:58:21 +02:00
|
|
|
/* When adding months, there is a problem if we are on January 31st and add one month with PHP.
|
|
|
|
* What ends up happening is that since February 31st doesn't exist, the date returned is
|
|
|
|
* March 3rd. For now let's ignore the day and assume we are always working with the
|
|
|
|
* first of each month, and use PHP to add 1 month to this (this will take care of rolling
|
|
|
|
* over the years 2011->2012, etc.). Then let's append the actual day, and use the php
|
|
|
|
* checkdate() function, to see if it is valid. If not, then we'll just skip this month. */
|
2011-11-23 19:11:48 +01:00
|
|
|
|
2012-06-13 02:18:06 +02:00
|
|
|
/* pass in only the year and month (not the day) */
|
2012-06-08 23:58:21 +02:00
|
|
|
$dt = new DateTime($startDt->format("Y-m"), new DateTimeZone($timezone));
|
2011-11-23 19:11:48 +01:00
|
|
|
|
2012-06-13 02:18:06 +02:00
|
|
|
|
2012-06-08 23:58:21 +02:00
|
|
|
/* Keep adding 1 month, until we find the next month that contains the day
|
|
|
|
* we are looking for (31st day for example) */
|
|
|
|
do {
|
2011-11-23 00:03:47 +01:00
|
|
|
$dt->add(new DateInterval($p_interval));
|
2012-07-16 03:17:13 +02:00
|
|
|
} while (!checkdate($dt->format("m"), $startDt->format("d"), $dt->format("Y")));
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-06-08 23:58:21 +02:00
|
|
|
$dt->setDate($dt->format("Y"), $dt->format("m"), $startDt->format("d"));
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-06-08 23:58:21 +02:00
|
|
|
} else {
|
|
|
|
$dt = new DateTime($start, new DateTimeZone($timezone));
|
|
|
|
$dt->add(new DateInterval($p_interval));
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-06-13 02:18:06 +02:00
|
|
|
$start = $dt->format("Y-m-d H:i:s");
|
|
|
|
|
|
|
|
$dt->setTimezone(new DateTimeZone('UTC'));
|
|
|
|
$utcStartDateTime = $dt;
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-06-13 00:51:22 +02:00
|
|
|
return array($start, $utcStartDateTime);
|
2011-10-25 22:49:44 +02:00
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-11-23 18:47:44 +01:00
|
|
|
/*
|
|
|
|
* @param $p_start
|
|
|
|
* timestring format "Y-m-d H:i:s" (not UTC)
|
|
|
|
* @param $p_duration
|
|
|
|
* string time interval (h)h:(m)m(:ss)
|
|
|
|
* @param $p_timezone
|
|
|
|
* string "Europe/Prague"
|
|
|
|
* @param $p_offset
|
|
|
|
* array (days, hours, mins) used for rebroadcast shows.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* array of 2 DateTime objects, start/end time of the show in UTC.
|
|
|
|
*/
|
|
|
|
private static function createUTCStartEndDateTime($p_start, $p_duration, $p_timezone=null, $p_offset=null)
|
|
|
|
{
|
|
|
|
$timezone = $p_timezone ? $p_timezone : date_default_timezone_get();
|
|
|
|
|
|
|
|
$startDateTime = new DateTime($p_start, new DateTimeZone($timezone));
|
|
|
|
if (isset($p_offset)) {
|
|
|
|
$startDateTime->add(new DateInterval("P{$p_offset["days"]}DT{$p_offset["hours"]}H{$p_offset["mins"]}M"));
|
|
|
|
}
|
2011-11-23 19:11:48 +01:00
|
|
|
//convert time to UTC
|
|
|
|
$startDateTime->setTimezone(new DateTimeZone('UTC'));
|
2011-11-23 18:47:44 +01:00
|
|
|
|
2011-11-23 19:11:48 +01:00
|
|
|
$endDateTime = clone $startDateTime;
|
2011-11-23 18:47:44 +01:00
|
|
|
$duration = explode(":", $p_duration);
|
|
|
|
list($hours, $mins) = array_slice($duration, 0, 2);
|
|
|
|
$endDateTime->add(new DateInterval("PT{$hours}H{$mins}M"));
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-11-23 18:47:44 +01:00
|
|
|
return array($startDateTime, $endDateTime);
|
|
|
|
}
|
|
|
|
|
2011-11-15 15:20:33 +01:00
|
|
|
/* Create rebroadcast instances for a created show marked for recording
|
|
|
|
*
|
2011-11-23 18:47:44 +01:00
|
|
|
* @param $p_rebroadcasts
|
|
|
|
* rows gotten from the db table cc_show_rebroadcasts, tells airtime when to schedule the rebroadcasts.
|
|
|
|
* @param $p_currentUtcTimestamp
|
|
|
|
* a timestring in format "Y-m-d H:i:s", current UTC time.
|
|
|
|
* @param $p_showId
|
|
|
|
* int of the show it belongs to (from cc_show)
|
|
|
|
* @param $p_showInstanceId
|
|
|
|
* the instance id of the created recorded show instance
|
2011-11-15 15:20:33 +01:00
|
|
|
* (from cc_show_instances), used to associate rebroadcasts to this show.
|
2011-11-23 18:47:44 +01:00
|
|
|
* @param $p_startTime
|
|
|
|
* a timestring in format "Y-m-d H:i:s" in the timezone, not UTC of the rebroadcasts' parent recorded show.
|
|
|
|
* @param $p_duration
|
|
|
|
* string time interval (h)h:(m)m:(ss) length of the show.
|
|
|
|
* @param $p_timezone
|
|
|
|
* string of user's timezone "Europe/Prague"
|
2011-11-15 15:20:33 +01:00
|
|
|
*
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
private static function createRebroadcastInstances($p_rebroadcasts, $p_currentUtcTimestamp, $p_showId, $p_showInstanceId, $p_startTime, $p_duration, $p_timezone=null)
|
|
|
|
{
|
2011-11-23 18:47:44 +01:00
|
|
|
//Y-m-d
|
|
|
|
//use only the date part of the show start time stamp for the offsets to work properly.
|
|
|
|
$date = explode(" ", $p_startTime);
|
|
|
|
$start_date = $date[0];
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
foreach ($p_rebroadcasts as $rebroadcast) {
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2011-11-23 18:47:44 +01:00
|
|
|
$days = explode(" ", $rebroadcast["day_offset"]);
|
|
|
|
$time = explode(":", $rebroadcast["start_time"]);
|
|
|
|
$offset = array("days"=>$days[0], "hours"=>$time[0], "mins"=>$time[1]);
|
2011-03-15 17:05:41 +01:00
|
|
|
|
2011-11-23 18:47:44 +01:00
|
|
|
list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start_date, $p_duration, $p_timezone, $offset);
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($utcStartDateTime->format("Y-m-d H:i:s") > $p_currentUtcTimestamp) {
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-10-25 22:49:44 +02:00
|
|
|
$newRebroadcastInstance = new CcShowInstances();
|
|
|
|
$newRebroadcastInstance->setDbShowId($p_showId);
|
2011-11-23 18:47:44 +01:00
|
|
|
$newRebroadcastInstance->setDbStarts($utcStartDateTime);
|
|
|
|
$newRebroadcastInstance->setDbEnds($utcEndDateTime);
|
2011-10-25 22:49:44 +02:00
|
|
|
$newRebroadcastInstance->setDbRecord(0);
|
|
|
|
$newRebroadcastInstance->setDbRebroadcast(1);
|
|
|
|
$newRebroadcastInstance->setDbOriginalShow($p_showInstanceId);
|
|
|
|
$newRebroadcastInstance->save();
|
2011-03-15 17:05:41 +01:00
|
|
|
}
|
2011-02-09 00:22:51 +01:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
2010-12-16 21:15:43 +01: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
|
|
|
*/
|
2011-10-24 19:46:16 +02:00
|
|
|
public static function getShows($start_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=FALSE)
|
2011-03-30 23:27:14 +02:00
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-04-01 00:54:26 +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()) {
|
2011-10-24 19:46:16 +02:00
|
|
|
Application_Model_Show::populateAllShowsInRange($showsPopUntil, $end_timestamp);
|
|
|
|
Application_Model_Preference::SetShowsPopulatedUntil($end_timestamp);
|
2011-03-30 23:27:14 +02:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2012-05-22 17:51:53 +02:00
|
|
|
$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, si1.file_id AS file_id, si1.id AS instance_id,
|
2012-07-23 01:14:29 +02:00
|
|
|
si1.created AS created, si1.last_scheduled AS last_scheduled, si1.time_filled AS time_filled, f.soundcloud_id
|
2012-05-22 17:51:53 +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-07-23 01:14:29 +02:00
|
|
|
LEFT JOIN cc_files AS f ON f.id = si1.file_id
|
2012-05-22 17:51:53 +02:00
|
|
|
WHERE si1.modified_instance = FALSE";
|
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-05-22 17:51:53 +02:00
|
|
|
$sql = $sql." AND (si1.starts >= '{$start_string}' AND si1.starts < timestamp '{$end_string}')";
|
|
|
|
$sql = $sql." AND (si1.record = 1)";
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2011-10-24 19:46:16 +02:00
|
|
|
|
2012-05-22 17:51:53 +02:00
|
|
|
$sql = $sql." AND ((si1.starts >= '{$start_string}' AND si1.starts < '{$end_string}')
|
|
|
|
OR (si1.ends > '{$start_string}' AND si1.ends <= '{$end_string}')
|
|
|
|
OR (si1.starts <= '{$start_string}' AND si1.ends >= '{$end_string}'))";
|
2011-10-24 19:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($excludeInstance)) {
|
2012-07-16 03:17:13 +02:00
|
|
|
foreach ($excludeInstance as $instance) {
|
2012-05-22 17:51:53 +02:00
|
|
|
$sql_exclude[] = "si1.id != {$instance}";
|
2011-10-24 19:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$exclude = join(" OR ", $sql_exclude);
|
|
|
|
|
|
|
|
$sql = $sql." AND ({$exclude})";
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
2011-10-24 19:46:16 +02:00
|
|
|
|
2012-08-21 22:33:37 +02:00
|
|
|
$result = $con->query($sql)->fetchAll();
|
2012-04-01 21:51:03 +02:00
|
|
|
return $result;
|
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
|
|
|
/**
|
|
|
|
* Generate all the repeating shows in the given range.
|
|
|
|
*
|
2011-11-11 20:54:08 +01:00
|
|
|
* @param DateTime $p_startTimestamp
|
|
|
|
* In UTC format.
|
|
|
|
* @param DateTime $p_endTimestamp
|
|
|
|
* In UTC format.
|
2011-03-30 23:27:14 +02:00
|
|
|
*/
|
|
|
|
public static function populateAllShowsInRange($p_startTimestamp, $p_endTimestamp)
|
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-11-11 20:54:08 +01:00
|
|
|
$endTimeString = $p_endTimestamp->format("Y-m-d H:i:s");
|
|
|
|
if (!is_null($p_startTimestamp)) {
|
|
|
|
$startTimeString = $p_startTimestamp->format("Y-m-d H:i:s");
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2011-11-11 20:54:08 +01:00
|
|
|
$today_timestamp = new DateTime("now", new DateTimeZone("UTC"));
|
2012-01-18 16:21:46 +01:00
|
|
|
$startTimeString = $today_timestamp->format("Y-m-d H:i:s");
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
|
|
|
|
2012-01-18 16:21:46 +01:00
|
|
|
$sql = "SELECT * FROM cc_show_days
|
|
|
|
WHERE last_show IS NULL
|
|
|
|
OR first_show < '{$endTimeString}' AND last_show > '{$startTimeString}'";
|
|
|
|
|
2012-03-25 18:57:20 +02:00
|
|
|
//Logging::log($sql);
|
2012-04-01 21:51:03 +02:00
|
|
|
$res = $con->query($sql)->fetchAll();
|
2011-03-30 23:27:14 +02:00
|
|
|
foreach ($res as $row) {
|
2011-10-24 19:46:16 +02:00
|
|
|
Application_Model_Show::populateShow($row, $p_endTimestamp);
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
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
|
|
|
{
|
2011-02-05 22:00:05 +01:00
|
|
|
$events = array();
|
2012-02-22 20:32:59 +01:00
|
|
|
$interval = $p_start->diff($p_end);
|
2011-04-06 23:53:09 +02:00
|
|
|
$days = $interval->format('%a');
|
2012-02-22 20:32:59 +01:00
|
|
|
$shows = Application_Model_Show::getShows($p_start, $p_end);
|
2012-05-07 18:19:18 +02:00
|
|
|
$nowEpoch = time();
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-07-23 01:14:29 +02:00
|
|
|
$timezone = date_default_timezone_get();
|
2012-07-23 01:18:53 +02:00
|
|
|
|
2011-02-05 22:00:05 +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"])) {
|
|
|
|
$parentStartsDT = new DateTime($show["parent_starts"], new DateTimeZone("UTC"));
|
|
|
|
$parentStartsEpoch = intval($parentStartsDT->format("U"));
|
|
|
|
}
|
2012-07-23 01:14:29 +02:00
|
|
|
$startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], new DateTimeZone("UTC"));
|
|
|
|
$endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], new DateTimeZone("UTC"));
|
|
|
|
|
|
|
|
$startsEpochStr = $startsDT->format("U");
|
|
|
|
$endsEpochStr = $endsDT->format("U");
|
2012-05-07 18:19:18 +02:00
|
|
|
|
2012-07-23 01:14:29 +02:00
|
|
|
$startsEpoch = intval($startsEpochStr);
|
|
|
|
$endsEpoch = intval($endsEpochStr);
|
|
|
|
|
|
|
|
$startsDT->setTimezone(new DateTimeZone($timezone));
|
|
|
|
$endsDT->setTimezone(new DateTimeZone($timezone));
|
2012-05-07 18:19:18 +02:00
|
|
|
|
2012-05-22 17:51:53 +02:00
|
|
|
if ($p_editable && $show["record"] && $nowEpoch > $startsEpoch) {
|
2012-05-07 18:19:18 +02:00
|
|
|
$options["editable"] = false;
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($p_editable && $show["rebroadcast"] && $nowEpoch > $parentStartsEpoch) {
|
|
|
|
$options["editable"] = false;
|
|
|
|
} elseif ($p_editable && $nowEpoch < $endsEpoch) {
|
2011-11-16 18:35:02 +01:00
|
|
|
$options["editable"] = true;
|
2011-04-06 23:53:09 +02:00
|
|
|
}
|
2012-08-07 20:57:04 +02:00
|
|
|
|
|
|
|
$showInstance = new Application_Model_ShowInstance($show["instance_id"]);
|
|
|
|
$showContent = $showInstance->getShowListContent();
|
|
|
|
if (empty($showContent)) {
|
|
|
|
$options["show_empty"] = 1;
|
|
|
|
} else {
|
|
|
|
$options["show_empty"] = 0;
|
|
|
|
}
|
|
|
|
|
2012-07-23 01:14:29 +02:00
|
|
|
$events[] = &self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr);
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
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.
|
|
|
|
**/
|
2012-07-16 03:17:13 +02:00
|
|
|
private static function getPercentScheduled($p_starts, $p_ends, $p_time_filled)
|
|
|
|
{
|
2012-04-01 21:51:03 +02:00
|
|
|
$durationSeconds = (strtotime($p_ends) - strtotime($p_starts));
|
|
|
|
$time_filled = Application_Model_Schedule::WallTimeToMillisecs($p_time_filled) / 1000;
|
2012-02-22 20:32:59 +01:00
|
|
|
$percent = ceil(( $time_filled / $durationSeconds) * 100);
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-02-22 20:32:59 +01:00
|
|
|
return $percent;
|
|
|
|
}
|
2010-12-10 18:15:17 +01:00
|
|
|
|
2012-07-23 01:14:29 +02:00
|
|
|
private static function &makeFullCalendarEvent(&$show, $options=array(), $startDateTime, $endDateTime, $startsEpoch, $endsEpoch)
|
2011-04-12 06:14:26 +02:00
|
|
|
{
|
2011-03-15 21:39:52 +01:00
|
|
|
$event = array();
|
2010-12-10 18:15:17 +01:00
|
|
|
|
2012-02-09 23:41:12 +01:00
|
|
|
$event["id"] = intval($show["instance_id"]);
|
2011-04-12 17:54:24 +02:00
|
|
|
$event["title"] = $show["name"];
|
2011-08-15 22:11:50 +02:00
|
|
|
$event["start"] = $startDateTime->format("Y-m-d H:i:s");
|
2012-07-23 01:14:29 +02:00
|
|
|
$event["startUnix"] = $startsEpoch;
|
2011-08-15 22:11:50 +02:00
|
|
|
$event["end"] = $endDateTime->format("Y-m-d H:i:s");
|
2012-07-23 01:14:29 +02:00
|
|
|
$event["endUnix"] = $endsEpoch;
|
2011-04-12 17:54:24 +02:00
|
|
|
$event["allDay"] = false;
|
2012-02-09 23:41:12 +01:00
|
|
|
$event["showId"] = intval($show["show_id"]);
|
2011-03-15 21:39:52 +01:00
|
|
|
$event["record"] = intval($show["record"]);
|
|
|
|
$event["rebroadcast"] = intval($show["rebroadcast"]);
|
2012-07-23 01:14:29 +02:00
|
|
|
$event["soundcloud_id"] = is_null($show["soundcloud_id"]) ? -1 : $show["soundcloud_id"];
|
2010-12-10 18:15:17 +01:00
|
|
|
|
2011-04-05 00:40:59 +02:00
|
|
|
//event colouring
|
2012-03-01 00:19:59 +01:00
|
|
|
if ($show["color"] != "") {
|
2011-04-05 00:40:59 +02:00
|
|
|
$event["textColor"] = "#".$show["color"];
|
|
|
|
}
|
2012-07-23 01:14:29 +02:00
|
|
|
|
2012-03-01 00:19:59 +01:00
|
|
|
if ($show["background_color"] != "") {
|
2011-04-05 00:40:59 +02:00
|
|
|
$event["color"] = "#".$show["background_color"];
|
2011-04-25 23:24:53 +02:00
|
|
|
}
|
2012-07-23 01:14:29 +02:00
|
|
|
|
2012-03-01 00:19:59 +01:00
|
|
|
foreach ($options as $key => $value) {
|
2011-04-12 17:54:24 +02:00
|
|
|
$event[$key] = $value;
|
|
|
|
}
|
2012-07-23 01:14:29 +02:00
|
|
|
|
2011-04-12 17:54:24 +02:00
|
|
|
return $event;
|
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-12-02 12:06:09 +01:00
|
|
|
/* Takes in a UTC DateTime object.
|
2011-11-26 06:06:17 +01:00
|
|
|
* Converts this to local time, since cc_show days
|
|
|
|
* requires local time. */
|
2012-07-16 03:17:13 +02:00
|
|
|
public function setShowFirstShow($p_dt)
|
|
|
|
{
|
2011-11-26 06:06:17 +01:00
|
|
|
//clone object since we are modifying it and it was passed by reference.
|
|
|
|
$dt = clone $p_dt;
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-11-26 06:06:17 +01:00
|
|
|
$dt->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-09-07 23:30:25 +02:00
|
|
|
$showDay = CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->findOne();
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-04-18 20:00:40 +02:00
|
|
|
$showDay->setDbFirstShow($dt)->setDbStartTime($dt)
|
2011-09-07 23:30:25 +02:00
|
|
|
->save();
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2012-03-25 18:57:20 +02:00
|
|
|
//Logging::log("setting show's first show.");
|
2011-09-07 23:30:25 +02:00
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-11-26 06:06:17 +01:00
|
|
|
/* Takes in a UTC DateTime object
|
|
|
|
* Converts this to local time, since cc_show days
|
|
|
|
* requires local time. */
|
2012-07-16 03:17:13 +02:00
|
|
|
public function setShowLastShow($p_dt)
|
|
|
|
{
|
2011-11-26 06:06:17 +01:00
|
|
|
//clone object since we are modifying it and it was passed by reference.
|
|
|
|
$dt = clone $p_dt;
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-11-26 06:06:17 +01:00
|
|
|
$dt->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-11-26 06:06:17 +01:00
|
|
|
//add one day since the Last Show date in CcShowDays is non-inclusive.
|
|
|
|
$dt->add(new DateInterval("P1D"));
|
2011-12-02 12:06:09 +01:00
|
|
|
|
2011-09-07 23:30:25 +02:00
|
|
|
$showDay = CcShowDaysQuery::create()
|
|
|
|
->filterByDbShowId($this->_showId)
|
|
|
|
->findOne();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-11-26 06:06:17 +01:00
|
|
|
$showDay->setDbLastShow($dt)
|
2011-09-07 23:30:25 +02:00
|
|
|
->save();
|
|
|
|
}
|
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
|
|
|
/**
|
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-03-02 22:55:11 +01:00
|
|
|
public static function GetCurrentShow($timeNow=null)
|
2011-03-22 14:55:33 +01:00
|
|
|
{
|
2012-04-01 21:51:03 +02:00
|
|
|
global $CC_CONFIG;
|
|
|
|
$con = Propel::getConnection();
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($timeNow == null) {
|
2012-04-13 23:45:28 +02:00
|
|
|
$date = new Application_Common_DateHelper;
|
2012-07-11 00:51:32 +02:00
|
|
|
$timeNow = $date->getUtcTimestamp();
|
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-07-10 16:36:53 +02:00
|
|
|
$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"
|
2011-02-07 02:12:56 +01:00
|
|
|
." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
|
|
|
|
." WHERE si.show_id = s.id"
|
2011-11-15 21:45:08 +01:00
|
|
|
." AND si.starts <= TIMESTAMP '$timeNow'"
|
2011-11-26 03:33:42 +01:00
|
|
|
." AND si.ends > TIMESTAMP '$timeNow'"
|
|
|
|
." AND modified_instance != TRUE";
|
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
|
|
|
// Convert back to local timezone
|
2012-08-06 23:07:18 +02:00
|
|
|
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
2011-02-07 02:12:56 +01:00
|
|
|
return $rows;
|
2011-02-05 00:22:15 +01:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2012-03-13 15:21:01 +01:00
|
|
|
/**
|
2012-07-10 16:36:53 +02:00
|
|
|
* Gets the current show, previous and next with an 2day window from
|
|
|
|
* the given timeNow, so timeNow-2days and timeNow+2days.
|
2012-03-13 15:21:01 +01:00
|
|
|
*/
|
2012-03-13 22:46:13 +01:00
|
|
|
public static function getPrevCurrentNext($p_timeNow)
|
2012-03-13 15:21:01 +01:00
|
|
|
{
|
2012-04-01 21:51:03 +02:00
|
|
|
global $CC_CONFIG;
|
|
|
|
$con = Propel::getConnection();
|
2012-03-13 15:21:01 +01:00
|
|
|
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
|
2012-07-10 16:36:53 +02:00
|
|
|
$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-03-13 15:21:01 +01:00
|
|
|
." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
|
|
|
|
." WHERE si.show_id = s.id"
|
2012-03-13 22:46:13 +01:00
|
|
|
." AND si.starts > TIMESTAMP '$p_timeNow' - INTERVAL '2 days'"
|
|
|
|
." AND si.ends < TIMESTAMP '$p_timeNow' + INTERVAL '2 days'"
|
|
|
|
." AND modified_instance != TRUE"
|
|
|
|
." ORDER BY si.starts";
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-05-15 20:20:53 +02:00
|
|
|
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
2012-03-13 15:21:01 +01:00
|
|
|
$numberOfRows = count($rows);
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-13 15:21:01 +01:00
|
|
|
$results['previousShow'] = array();
|
|
|
|
$results['currentShow'] = array();
|
|
|
|
$results['nextShow'] = array();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-13 22:46:13 +01:00
|
|
|
$timeNowAsMillis = strtotime($p_timeNow);
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 16:36:53 +02:00
|
|
|
for ($i = 0; $i < $numberOfRows; ++$i) {
|
2012-03-13 22:46:13 +01:00
|
|
|
//Find the show that is within the current time.
|
2012-07-11 00:51:32 +02:00
|
|
|
if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis)
|
2012-07-10 16:36:53 +02:00
|
|
|
&& (strtotime($rows[$i]['ends']) > $timeNowAsMillis)) {
|
|
|
|
if ($i-1 >= 0) {
|
2012-03-16 19:02:53 +01:00
|
|
|
$results['previousShow'][0] = array(
|
|
|
|
"id"=>$rows[$i-1]['id'],
|
2012-04-13 00:49:24 +02:00
|
|
|
"instance_id"=>$rows[$i-1]['instance_id'],
|
2012-03-16 19:02:53 +01:00
|
|
|
"name"=>$rows[$i-1]['name'],
|
2012-05-15 20:35:01 +02:00
|
|
|
"url"=>$rows[$i-1]['url'],
|
2012-03-13 15:21:01 +01:00
|
|
|
"start_timestamp"=>$rows[$i-1]['start_timestamp'],
|
|
|
|
"end_timestamp"=>$rows[$i-1]['end_timestamp'],
|
|
|
|
"starts"=>$rows[$i-1]['starts'],
|
2012-05-18 00:21:58 +02:00
|
|
|
"ends"=>$rows[$i-1]['ends'],
|
2012-05-25 23:25:46 +02:00
|
|
|
"record"=>$rows[$i-1]['record'],
|
2012-05-19 00:57:22 +02:00
|
|
|
"type"=>"show");
|
2012-03-13 15:21:01 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-13 15:21:01 +01:00
|
|
|
$results['currentShow'][0] = $rows[$i];
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 16:36:53 +02:00
|
|
|
if (isset($rows[$i+1])) {
|
2012-03-16 19:02:53 +01:00
|
|
|
$results['nextShow'][0] = array(
|
|
|
|
"id"=>$rows[$i+1]['id'],
|
2012-04-13 00:49:24 +02:00
|
|
|
"instance_id"=>$rows[$i+1]['instance_id'],
|
2012-03-16 19:02:53 +01:00
|
|
|
"name"=>$rows[$i+1]['name'],
|
2012-05-15 20:35:01 +02:00
|
|
|
"url"=>$rows[$i+1]['url'],
|
2012-03-13 15:21:01 +01:00
|
|
|
"start_timestamp"=>$rows[$i+1]['start_timestamp'],
|
|
|
|
"end_timestamp"=>$rows[$i+1]['end_timestamp'],
|
|
|
|
"starts"=>$rows[$i+1]['starts'],
|
2012-05-18 00:21:58 +02:00
|
|
|
"ends"=>$rows[$i+1]['ends'],
|
2012-05-25 23:25:46 +02:00
|
|
|
"record"=>$rows[$i+1]['record'],
|
2012-05-19 00:57:22 +02:00
|
|
|
"type"=>"show");
|
2012-03-13 15:21:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-03-13 22:46:13 +01:00
|
|
|
//Previous is any row that ends after time now capture it in case we need it later.
|
2012-03-13 15:21:01 +01:00
|
|
|
if (strtotime($rows[$i]['ends']) < $timeNowAsMillis ) {
|
2012-03-13 22:46:13 +01:00
|
|
|
$previousShowIndex = $i;
|
2012-03-13 15:21:01 +01:00
|
|
|
}
|
2012-03-13 22:46:13 +01:00
|
|
|
//if we hit this we know we've gone to far and can stop looping.
|
2012-03-13 15:21:01 +01:00
|
|
|
if (strtotime($rows[$i]['starts']) > $timeNowAsMillis) {
|
2012-03-16 19:02:53 +01:00
|
|
|
$results['nextShow'][0] = array(
|
|
|
|
"id"=>$rows[$i]['id'],
|
2012-04-13 00:49:24 +02:00
|
|
|
"instance_id"=>$rows[$i]['instance_id'],
|
2012-03-16 19:02:53 +01:00
|
|
|
"name"=>$rows[$i]['name'],
|
2012-05-15 20:35:01 +02:00
|
|
|
"url"=>$rows[$i]['url'],
|
2012-03-13 15:21:01 +01:00
|
|
|
"start_timestamp"=>$rows[$i]['start_timestamp'],
|
|
|
|
"end_timestamp"=>$rows[$i]['end_timestamp'],
|
|
|
|
"starts"=>$rows[$i]['starts'],
|
2012-05-18 00:21:58 +02:00
|
|
|
"ends"=>$rows[$i]['ends'],
|
2012-05-25 23:25:46 +02:00
|
|
|
"record"=>$rows[$i]['record'],
|
2012-05-19 00:57:22 +02:00
|
|
|
"type"=>"show");
|
2012-03-13 15:21:01 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-13 22:46:13 +01:00
|
|
|
//If we didn't find a a current show because the time didn't fit we may still have
|
|
|
|
//found a previous show so use it.
|
|
|
|
if (count($results['previousShow']) == 0 && isset($previousShowIndex)) {
|
2012-03-16 19:02:53 +01:00
|
|
|
$results['previousShow'][0] = array(
|
|
|
|
"id"=>$rows[$previousShowIndex]['id'],
|
2012-04-13 00:49:24 +02:00
|
|
|
"instance_id"=>$rows[$previousShowIndex]['instance_id'],
|
2012-03-16 19:02:53 +01:00
|
|
|
"name"=>$rows[$previousShowIndex]['name'],
|
2012-03-13 22:46:13 +01:00
|
|
|
"start_timestamp"=>$rows[$previousShowIndex]['start_timestamp'],
|
|
|
|
"end_timestamp"=>$rows[$previousShowIndex]['end_timestamp'],
|
|
|
|
"starts"=>$rows[$previousShowIndex]['starts'],
|
2012-05-18 00:21:58 +02:00
|
|
|
"ends"=>$rows[$previousShowIndex]['ends'],
|
2012-05-25 23:25:46 +02:00
|
|
|
"record"=>$rows[$previousShowIndex]['record'],
|
2012-05-19 00:57:22 +02:00
|
|
|
"type"=>"show");
|
2012-03-13 22:46:13 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-03-13 15:21:01 +01:00
|
|
|
return $results;
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
CC-2965: Frontend widget displays shows in UTC time
Not only were frontend widgets showing UTC time,
the SQL query was also comparing UTC timestamp with local timestamps,
causing widgets to display shows in the wrong day, etc.
Another problem was that "On air today" widget was simply calling
GetNextShows which returns shows within next 48 hours.
Fixed by:
1. Under models/Show.php:
In the GetCurrentShow/GetNextShows/GetShowsByDayOfWeek functions,
added code to convert UTC timestamp to local timestamp or vice versa,
depending on which one is more suitable, in SQL queries, thus
removing inconsistency in timezones. Also, before returning query result,
added code to convert result to local timezone.
In GetNextShows, added an optional parameter endTime to limit the interval
of shows to get. This is useful for the "On air today" widget.
2. Under models/DateHelper.php:
Added a few timezone functions to help converting timezones easier in Show.php.
3. Under controller/ApiController.php:
Added todayInfoAction which is to be used by "On Air Today" widget.
2011-11-04 21:57:24 +01:00
|
|
|
/**
|
2011-11-22 00:03:56 +01:00
|
|
|
* Given a start time $timeStart and end time $timeEnd, returns the next $limit
|
2012-07-12 01:31:24 +02:00
|
|
|
* number of shows within the time interval
|
|
|
|
* If $timeEnd not given, shows within next 48 hours from $timeStart are returned
|
|
|
|
* If $limit not given, all shows within the intervals are returned
|
2011-11-22 00:03:56 +01:00
|
|
|
* Times are all in UTC time.
|
2011-11-15 15:20:33 +01:00
|
|
|
*
|
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-07-10 16:36:53 +02:00
|
|
|
public static function getNextShows($timeStart, $limit = "0", $timeEnd = "")
|
2011-03-22 14:55:33 +01:00
|
|
|
{
|
2012-04-01 21:51:03 +02:00
|
|
|
global $CC_CONFIG;
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-11-15 15:20: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
|
|
|
} else {
|
2011-11-15 21:45:08 +01:00
|
|
|
$timeEnd = "'$timeEnd'";
|
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-08-10 18:14:15 +02:00
|
|
|
$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 FROM"
|
2011-04-12 17:54:24 +02:00
|
|
|
." $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
|
|
|
|
." WHERE si.show_id = s.id"
|
2011-11-22 00:03:56 +01:00
|
|
|
." AND si.starts >= TIMESTAMP '$timeStart'"
|
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
|
|
|
." AND si.starts < TIMESTAMP $timeEnd"
|
2011-11-26 03:33:42 +01:00
|
|
|
." AND modified_instance != TRUE"
|
2011-04-04 18:30:29 +02:00
|
|
|
." ORDER BY si.starts";
|
2011-11-23 18:47:44 +01:00
|
|
|
|
2011-11-22 00:03:56 +01:00
|
|
|
// defaults to retrieve all shows within the interval if $limit not set
|
2012-07-10 16:36:53 +02:00
|
|
|
if ($limit != "0") {
|
2011-11-22 00:03:56 +01:00
|
|
|
$sql = $sql . " LIMIT $limit";
|
|
|
|
}
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2012-08-06 23:07:18 +02:00
|
|
|
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
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
|
|
|
return $rows;
|
|
|
|
}
|
2011-11-15 15:20: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
|
|
|
/**
|
2011-11-15 15:20:33 +01:00
|
|
|
* Convert the columns given in the array $columnsToConvert in the
|
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
|
|
|
* database result $rows to local timezone.
|
2011-11-15 15:20:33 +01:00
|
|
|
*
|
2012-07-16 03:17:13 +02:00
|
|
|
* @param type $rows arrays of arrays containing database query result
|
|
|
|
* @param type $columnsToConvert array of column names to convert
|
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-07-10 16:36:53 +02:00
|
|
|
public static function convertToLocalTimeZone(&$rows, $columnsToConvert)
|
|
|
|
{
|
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
|
|
|
$timezone = date_default_timezone_get();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-11-26 03:33:42 +01:00
|
|
|
if (!is_array($rows)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-10 16:36:53 +02:00
|
|
|
foreach ($rows as &$row) {
|
|
|
|
foreach ($columnsToConvert as $column) {
|
2012-04-13 23:45:28 +02:00
|
|
|
$row[$column] = Application_Common_DateHelper::ConvertToLocalDateTimeString($row[$column]);
|
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-04-01 21:51:03 +02:00
|
|
|
global $CC_CONFIG;
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
2011-10-24 19:27:53 +02:00
|
|
|
$sql = "SELECT column_name, character_maximum_length FROM information_schema.columns"
|
|
|
|
." WHERE table_name = 'cc_show' AND character_maximum_length > 0";
|
2012-04-01 21:51:03 +02:00
|
|
|
$result = $con->query($sql)->fetchAll();
|
2011-11-15 15:20:33 +01:00
|
|
|
|
2011-10-25 22:49:44 +02:00
|
|
|
// store result into assoc array
|
|
|
|
$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-11-15 15:20:33 +01:00
|
|
|
|
2011-10-24 19:27:53 +02:00
|
|
|
return $assocArray;
|
|
|
|
}
|
2011-02-05 00:22:15 +01:00
|
|
|
}
|