123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- class CcShowInstances extends BaseCcShowInstances {
-
- public function getDbStarts($format = 'Y-m-d H:i:s')
- {
- if ($this->starts === null) {
- return null;
- }
- try {
- $dt = new DateTime($this->starts, new DateTimeZone("UTC"));
- } catch (Exception $x) {
- throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->starts, true), $x);
- }
- if ($format === null) {
-
- return $dt;
- } elseif (strpos($format, '%') !== false) {
- return strftime($format, $dt->format('U'));
- } else {
- return $dt->format($format);
- }
- }
-
- public function getDbEnds($format = 'Y-m-d H:i:s')
- {
- if ($this->ends === null) {
- return null;
- }
- try {
- $dt = new DateTime($this->ends, new DateTimeZone("UTC"));
- } catch (Exception $x) {
- throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ends, true), $x);
- }
- if ($format === null) {
-
- return $dt;
- } elseif (strpos($format, '%') !== false) {
- return strftime($format, $dt->format('U'));
- } else {
- return $dt->format($format);
- }
- }
-
- public function getDbLastScheduled($format = 'Y-m-d H:i:s')
- {
- if ($this->last_scheduled === null) {
- return null;
- }
- try {
- $dt = new DateTime($this->last_scheduled, new DateTimeZone("UTC"));
- } catch (Exception $x) {
- throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->last_scheduled, true), $x);
- }
- if ($format === null) {
-
- return $dt;
- } elseif (strpos($format, '%') !== false) {
- return strftime($format, $dt->format('U'));
- } else {
- return $dt->format($format);
- }
- }
-
- public function updateScheduleStatus(PropelPDO $con) {
-
- $this->updateDbTimeFilled($con);
-
- CcScheduleQuery::create()
- ->filterByDbInstanceId($this->id)
- ->filterByDbPlayoutStatus(0, Criteria::GREATER_EQUAL)
- ->filterByDbEnds($this->ends, Criteria::LESS_EQUAL)
- ->update(array('DbPlayoutStatus' => 1), $con);
-
- CcScheduleQuery::create()
- ->filterByDbInstanceId($this->id)
- ->filterByDbPlayoutStatus(0, Criteria::GREATER_EQUAL)
- ->filterByDbStarts($this->ends, Criteria::LESS_THAN)
- ->filterByDbEnds($this->ends, Criteria::GREATER_THAN)
- ->update(array('DbPlayoutStatus' => 2), $con);
-
- CcScheduleQuery::create()
- ->filterByDbInstanceId($this->id)
- ->filterByDbPlayoutStatus(0, Criteria::GREATER_EQUAL)
- ->filterByDbStarts($this->ends, Criteria::GREATER_THAN)
- ->update(array('DbPlayoutStatus' => 0), $con);
-
- $this->setDbLastScheduled(gmdate("Y-m-d H:i:s"));
- $this->save($con);
- }
-
- public function correctSchedulePositions()
- {
- $schedule = CcScheduleQuery::create()
- ->filterByDbInstanceId($this->id)
- ->orderByDbStarts()
- ->find();
- $pos = 0;
- foreach ($schedule as $item) {
- $item->setDbPosition($pos)->save();
- $pos++;
- }
- }
-
-
- public function computeDbTimeFilled(PropelPDO $con)
- {
- $stmt = $con->prepare('SELECT SUM(clip_length) FROM "cc_schedule" WHERE cc_schedule.INSTANCE_ID = :p1');
- $stmt->bindValue(':p1', $this->getDbId());
- $stmt->execute();
- return $stmt->fetchColumn();
- }
-
-
- public function updateDbTimeFilled(PropelPDO $con)
- {
- $timefilled = $this->computeDbTimeFilled($con);
- if(is_null($timefilled)){
- $timefilled = "00:00:00";
- }
- $this->setDbTimeFilled($timefilled);
- $this->save($con);
- }
-
- public function preInsert(PropelPDO $con = null) {
- $now = new DateTime("now", new DateTimeZone("UTC"));
- $this->setDbCreated($now);
- return true;
- }
- public function isRecorded()
- {
- return $this->getDbRecord() == 1 ? true : false;
- }
- public function isRebroadcast()
- {
- return $this->getDbRebroadcast() == 1 ? true : false;
- }
- public function getLocalStartDateTime()
- {
- $startDT = $this->getDbStarts(null);
- return $startDT->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone()));
- }
- }
|