early implementation of CC-1962

This commit is contained in:
martin 2011-03-06 00:08:02 -05:00
parent f4a86d96c6
commit e16dd6c486
8 changed files with 78 additions and 20 deletions

View file

@ -278,12 +278,11 @@ class Schedule {
return ($count == '0');
}
public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) {
public static function getTimeUnScheduledInRange($instance_id, $s_datetime, $e_datetime) {
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]."
WHERE (starts >= '{$s_datetime}')
AND (ends <= '{$e_datetime}')";
$sql = "SELECT SUM(clip_length) FROM $CC_CONFIG[scheduleTable]"
." WHERE instance_id = $instance_id";
$time = $CC_DBC->GetOne($sql);
@ -313,6 +312,20 @@ class Schedule {
return $res;
}
public static function GetTotalShowTime($instance_id) {
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT SUM(clip_length) FROM $CC_CONFIG[scheduleTable]"
." WHERE instance_id = $instance_id";
$res = $CC_DBC->GetOne($sql);
if(is_null($res))
return 0;
return $res;
}
public static function getPercentScheduledInRange($s_datetime, $e_datetime) {
@ -337,6 +350,25 @@ class Schedule {
return $percent;
}
public static function GetPercentScheduled($instance_id, $s_datetime, $e_datetime){
$time = Schedule::GetTotalShowTime($instance_id);
$s_epoch = strtotime($s_datetime);
$e_epoch = strtotime($e_datetime);
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
$sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')";
$r = $con->query($sql);
$i_epoch = $r->fetchColumn(0);
$percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100);
if ($percent > 100)
$percent = 100;
return $percent;
}
/**
* Return TRUE if file is going to be played in the future.
@ -490,7 +522,8 @@ class Schedule {
." WHERE st.playlist_id = pt.id"
." AND st.file_id = ft.id"
." AND st.instance_id = si.id"
." AND si.show_id = show.id";
." AND si.show_id = show.id"
." AND st.starts < si.ends";
if ($timePeriod < 0){
$sql .= " AND st.ends < TIMESTAMP '$timeStamp'"

View file

@ -456,6 +456,10 @@ class ShowInstance {
return $showInstance->getDbShowId();
}
public function getShowInstanceId() {
return $this->_instanceId;
}
public function getName() {
$show = CcShowQuery::create()->findPK($this->getShowId());
return $show->getDbName();
@ -635,11 +639,8 @@ class ShowInstance {
}
public function getTimeScheduled() {
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp);
$instance_id = $this->getShowInstanceId();
$time = Schedule::GetTotalShowTime($instance_id);
return $time;
}
@ -648,8 +649,9 @@ class ShowInstance {
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$instance_id = $this->getShowInstanceId();
$time = Schedule::getTimeUnScheduledInRange($start_timestamp, $end_timestamp);
$time = Schedule::getTimeUnScheduledInRange($instance_id, $start_timestamp, $end_timestamp);
return $time;
}
@ -662,6 +664,14 @@ class ShowInstance {
return Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp);
}
public function getPercentScheduled(){
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$instance_id = $this->getShowInstanceId();
return Schedule::GetPercentScheduled($instance_id, $start_timestamp, $end_timestamp);
}
public function getShowLength(){
global $CC_DBC;
@ -794,6 +804,7 @@ class Show_DAL{
." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')"
." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')"
." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))"
." AND (st.starts < si.ends)"
." ORDER BY st.starts";
return $CC_DBC->GetAll($sql);

View file

@ -1671,7 +1671,7 @@ class StoredFile {
$fromTable = "cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id";
$datatables["optWhere"][] = "plt.length <= INTERVAL '{$p_length}'";
$datatables["optWhere"][] = "INTERVAL '{$p_length}' > INTERVAL '00:00:00'";
$datatables["optWhere"][] = "plt.length > INTERVAL '00:00:00'";
return StoredFile::searchFiles($fromTable, $datatables);