-commented some functions

-removed usage of "current_timestamp" in postgresql queries in favour
of php time.
This commit is contained in:
martin 2011-04-14 14:17:56 -04:00
parent ac3853c0fb
commit bf146e7f85
6 changed files with 117 additions and 41 deletions

View File

@ -21,6 +21,7 @@ require_once 'Schedule.php';
require_once 'Shows.php'; require_once 'Shows.php';
require_once 'Users.php'; require_once 'Users.php';
require_once 'RabbitMq.php'; require_once 'RabbitMq.php';
require_once 'DateHelper.php';
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php'; require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;

View File

@ -112,8 +112,8 @@ class ApiController extends Zend_Controller_Action
$result = Schedule::GetPlayOrderRange(0, 1); $result = Schedule::GetPlayOrderRange(0, 1);
$date = new Application_Model_DateHelper; $date = new DateHelper;
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
$result = array("env"=>APPLICATION_ENV, $result = array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"), "schedulerTime"=>gmdate("Y-m-d H:i:s"),
"currentShow"=>Show_DAL::GetCurrentShow($timeNow), "currentShow"=>Show_DAL::GetCurrentShow($timeNow),

View File

@ -1,6 +1,6 @@
<?php <?php
class Application_Model_DateHelper class DateHelper
{ {
private $_timestamp; private $_timestamp;
@ -13,7 +13,7 @@ class Application_Model_DateHelper
* Get time of object construction in the format * Get time of object construction in the format
* YYYY-MM-DD HH:mm:ss * YYYY-MM-DD HH:mm:ss
*/ */
function getDate() function getTimestamp()
{ {
return date("Y-m-d H:i:s", $this->_timestamp); return date("Y-m-d H:i:s", $this->_timestamp);
} }

View File

@ -57,8 +57,8 @@ class Application_Model_Nowplaying
} }
public static function FilterRowsByDate($rows, $date, $startCutoff, $endCutoff){ public static function FilterRowsByDate($rows, $date, $startCutoff, $endCutoff){
$dateNow = new Application_Model_DateHelper; $dateNow = new DateHelper;
$timeNow = $dateNow->getDate(); $timeNow = $dateNow->getTimestamp();
$data = array(); $data = array();
//iterate over each show, and calculate information for it. //iterate over each show, and calculate information for it.
@ -117,16 +117,16 @@ class Application_Model_Nowplaying
public static function GetDataGridData($viewType, $dateString){ public static function GetDataGridData($viewType, $dateString){
if ($viewType == "now"){ if ($viewType == "now"){
$date = new Application_Model_DateHelper; $date = new DateHelper;
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
$startCutoff = 60; $startCutoff = 60;
$endCutoff = 86400; //60*60*24 - seconds in a day $endCutoff = 86400; //60*60*24 - seconds in a day
} else { } else {
$date = new Application_Model_DateHelper; $date = new DateHelper;
$time = $date->getTime(); $time = $date->getTime();
$date->setDate($dateString." ".$time); $date->setDate($dateString." ".$time);
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
$startCutoff = $date->getNowDayStartDiff(); $startCutoff = $date->getNowDayStartDiff();
$endCutoff = $date->getNowDayEndDiff(); $endCutoff = $date->getNowDayEndDiff();
@ -139,8 +139,8 @@ class Application_Model_Nowplaying
//$rows = FindGapsBetweenShows() //$rows = FindGapsBetweenShows()
$data = Application_Model_Nowplaying::FilterRowsByDate($rows, $date, $startCutoff, $endCutoff); $data = Application_Model_Nowplaying::FilterRowsByDate($rows, $date, $startCutoff, $endCutoff);
$date = new Application_Model_DateHelper; $date = new DateHelper;
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data); return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data);
} }
} }

View File

@ -361,8 +361,8 @@ class Schedule {
global $CC_CONFIG; global $CC_CONFIG;
$date = new Application_Model_DateHelper; $date = new DateHelper;
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
return array("env"=>APPLICATION_ENV, return array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"), "schedulerTime"=>gmdate("Y-m-d H:i:s"),
"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"), "previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),

View File

@ -136,9 +136,13 @@ class Show {
$uncheckedDaysImploded = implode(",", $p_uncheckedDays); $uncheckedDaysImploded = implode(",", $p_uncheckedDays);
$showId = $this->getId(); $showId = $this->getId();
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "DELETE FROM cc_show_instances" $sql = "DELETE FROM cc_show_instances"
." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)" ." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)"
." AND starts > current_timestamp " ." AND starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql); $CC_DBC->query($sql);
@ -177,6 +181,14 @@ class Show {
return !is_null($showInstancesRow); return !is_null($showInstancesRow);
} }
/**
* 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
* array of associate arrays containing "start_date" and "start_time"
*/
public function getRebroadcastsAbsolute() public function getRebroadcastsAbsolute()
{ {
global $CC_DBC; global $CC_DBC;
@ -199,6 +211,14 @@ class Show {
return $CC_DBC->GetAll($sql); return $CC_DBC->GetAll($sql);
} }
/**
* 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
* array of associate arrays containing "day_offset" and "start_time"
*/
public function getRebroadcastsRelative() public function getRebroadcastsRelative()
{ {
global $CC_DBC; global $CC_DBC;
@ -272,42 +292,76 @@ class Show {
return $endDate; return $endDate;
} }
} }
/**
* Deletes all future instances of the current show object
* from the show_instances table.
*
*/
public function deleteAllInstances(){ public function deleteAllInstances(){
global $CC_DBC; global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId(); $showId = $this->getId();
$sql = "DELETE FROM cc_show_instances " $sql = "DELETE FROM cc_show_instances"
."WHERE starts > current_timestamp " ." WHERE starts > TIMESTAMP '$timestamp'"
."AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql); $CC_DBC->query($sql);
} }
/**
* Deletes all show instances of current show after a
* certain date.
*
* @param string $p_date
* The date which to delete after
*/
public function removeAllInstancesAfterDate($p_date){ public function removeAllInstancesAfterDate($p_date){
global $CC_DBC; global $CC_DBC;
$showId = $this->getId(); $date = new DateHelper;
$sql = "DELETE FROM cc_show_instances " $timestamp = $date->getTimestamp();
."WHERE date(starts) > DATE '$p_date' "
."AND starts > current_timestamp "
."AND show_id = $showId";
$CC_DBC->query($sql);
}
public function removeAllInstancesBeforeDate($p_date){
global $CC_DBC;
$showId = $this->getId(); $showId = $this->getId();
$sql = "DELETE FROM cc_show_instances " $sql = "DELETE FROM cc_show_instances "
."WHERE date(starts) < DATE '$p_date' " ." WHERE date(starts) > DATE '$p_date'"
."AND starts > current_timestamp " ." AND starts > TIMESTAMP '$timestamp'"
."AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql);
}
/**
* Deletes all show instances of current show before a
* certain date.
*
* @param string $p_date
* The date which to delete before
*/
public function removeAllInstancesBeforeDate($p_date){
global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
." WHERE date(starts) < DATE '$p_date'"
." AND starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId";
$CC_DBC->query($sql); $CC_DBC->query($sql);
} }
/**
* Get the start date of the current show.
*
* @return string
* The start date in the format YYYY-MM-DD
*/
public function getStartDate(){ public function getStartDate(){
global $CC_DBC; global $CC_DBC;
@ -323,7 +377,13 @@ class Show {
return $firstDate; return $firstDate;
} }
} }
/**
* Get the start time of the current show.
*
* @return string
* The start time in the format HH:MM:SS
*/
public function getStartTime(){ public function getStartTime(){
global $CC_DBC; global $CC_DBC;
@ -339,14 +399,23 @@ class Show {
return $startTime; return $startTime;
} }
} }
/**
* Get the ID's of future instance of the current show.
*
* @return array
* A simple array containing all future instance ID's
*/
public function getAllFutureInstanceIds(){ public function getAllFutureInstanceIds(){
global $CC_DBC; global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId(); $showId = $this->getId();
$sql = "SELECT id from cc_show_instances " $sql = "SELECT id from cc_show_instances"
." WHERE show_id = $showId" ." WHERE show_id = $showId"
." AND starts > current_timestamp"; ." AND starts > TIMESTAMP '$timestamp'";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
@ -361,6 +430,9 @@ class Show {
//need to update cc_show_instances, cc_show_days //need to update cc_show_instances, cc_show_days
global $CC_DBC; global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "UPDATE cc_show_days " $sql = "UPDATE cc_show_days "
."SET duration = '$p_data[add_show_duration]' " ."SET duration = '$p_data[add_show_duration]' "
@ -370,7 +442,7 @@ class Show {
$sql = "UPDATE cc_show_instances " $sql = "UPDATE cc_show_instances "
."SET ends = starts + INTERVAL '$p_data[add_show_duration]' " ."SET ends = starts + INTERVAL '$p_data[add_show_duration]' "
."WHERE show_id = $p_data[add_show_id] " ."WHERE show_id = $p_data[add_show_id] "
."AND starts > current_timestamp"; ."AND starts > TIMESTAMP '$timestamp'";
$CC_DBC->query($sql); $CC_DBC->query($sql);
} }
@ -379,6 +451,9 @@ class Show {
//need to update cc_schedule, cc_show_instances, cc_show_days //need to update cc_schedule, cc_show_instances, cc_show_days
global $CC_DBC; global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "UPDATE cc_show_days " $sql = "UPDATE cc_show_days "
."SET start_time = TIME '$p_data[add_show_start_time]', " ."SET start_time = TIME '$p_data[add_show_start_time]', "
@ -399,7 +474,7 @@ class Show {
."SET starts = starts + INTERVAL '$diff sec', " ."SET starts = starts + INTERVAL '$diff sec', "
."ends = ends + INTERVAL '$diff sec' " ."ends = ends + INTERVAL '$diff sec' "
."WHERE show_id = $p_data[add_show_id] " ."WHERE show_id = $p_data[add_show_id] "
."AND starts > current_timestamp"; ."AND starts > TIMESTAMP '$timestamp'";
$CC_DBC->query($sql); $CC_DBC->query($sql);
$showInstanceIds = $this->getAllFutureInstanceIds(); $showInstanceIds = $this->getAllFutureInstanceIds();