CcShowInstances.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * Skeleton subclass for representing a row from the 'cc_show_instances' table.
  4. *
  5. *
  6. *
  7. * You should add additional methods to this class to meet the
  8. * application requirements. This class will only be generated as
  9. * long as it does not already exist in the output directory.
  10. *
  11. * @package propel.generator.airtime
  12. */
  13. class CcShowInstances extends BaseCcShowInstances {
  14. /**
  15. * Get the [optionally formatted] temporal [starts] column value.
  16. *
  17. *
  18. * @param string $format The date/time format string (either date()-style or strftime()-style).
  19. * If format is NULL, then the raw DateTime object will be returned.
  20. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  21. * @throws PropelException - if unable to parse/validate the date/time value.
  22. */
  23. public function getDbStarts($format = 'Y-m-d H:i:s')
  24. {
  25. if ($this->starts === null) {
  26. return null;
  27. }
  28. try {
  29. $dt = new DateTime($this->starts, new DateTimeZone("UTC"));
  30. } catch (Exception $x) {
  31. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->starts, true), $x);
  32. }
  33. if ($format === null) {
  34. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  35. return $dt;
  36. } elseif (strpos($format, '%') !== false) {
  37. return strftime($format, $dt->format('U'));
  38. } else {
  39. return $dt->format($format);
  40. }
  41. }
  42. /**
  43. * Get the [optionally formatted] temporal [ends] column value.
  44. *
  45. *
  46. * @param string $format The date/time format string (either date()-style or strftime()-style).
  47. * If format is NULL, then the raw DateTime object will be returned.
  48. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  49. * @throws PropelException - if unable to parse/validate the date/time value.
  50. */
  51. public function getDbEnds($format = 'Y-m-d H:i:s')
  52. {
  53. if ($this->ends === null) {
  54. return null;
  55. }
  56. try {
  57. $dt = new DateTime($this->ends, new DateTimeZone("UTC"));
  58. } catch (Exception $x) {
  59. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ends, true), $x);
  60. }
  61. if ($format === null) {
  62. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  63. return $dt;
  64. } elseif (strpos($format, '%') !== false) {
  65. return strftime($format, $dt->format('U'));
  66. } else {
  67. return $dt->format($format);
  68. }
  69. }
  70. /**
  71. * Get the [optionally formatted] temporal [last_scheduled] column value.
  72. *
  73. *
  74. * @param string $format The date/time format string (either date()-style or strftime()-style).
  75. * If format is NULL, then the raw DateTime object will be returned.
  76. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  77. * @throws PropelException - if unable to parse/validate the date/time value.
  78. */
  79. public function getDbLastScheduled($format = 'Y-m-d H:i:s')
  80. {
  81. if ($this->last_scheduled === null) {
  82. return null;
  83. }
  84. try {
  85. $dt = new DateTime($this->last_scheduled, new DateTimeZone("UTC"));
  86. } catch (Exception $x) {
  87. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->last_scheduled, true), $x);
  88. }
  89. if ($format === null) {
  90. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  91. return $dt;
  92. } elseif (strpos($format, '%') !== false) {
  93. return strftime($format, $dt->format('U'));
  94. } else {
  95. return $dt->format($format);
  96. }
  97. }
  98. //post save hook to update the cc_schedule status column for the tracks in the show.
  99. public function updateScheduleStatus(PropelPDO $con) {
  100. $this->updateDbTimeFilled($con);
  101. //scheduled track is in the show
  102. CcScheduleQuery::create()
  103. ->filterByDbInstanceId($this->id)
  104. ->filterByDbPlayoutStatus(0, Criteria::GREATER_EQUAL)
  105. ->filterByDbEnds($this->ends, Criteria::LESS_EQUAL)
  106. ->update(array('DbPlayoutStatus' => 1), $con);
  107. //scheduled track is a boundary track
  108. CcScheduleQuery::create()
  109. ->filterByDbInstanceId($this->id)
  110. ->filterByDbPlayoutStatus(0, Criteria::GREATER_EQUAL)
  111. ->filterByDbStarts($this->ends, Criteria::LESS_THAN)
  112. ->filterByDbEnds($this->ends, Criteria::GREATER_THAN)
  113. ->update(array('DbPlayoutStatus' => 2), $con);
  114. //scheduled track is overbooked.
  115. CcScheduleQuery::create()
  116. ->filterByDbInstanceId($this->id)
  117. ->filterByDbPlayoutStatus(0, Criteria::GREATER_EQUAL)
  118. ->filterByDbStarts($this->ends, Criteria::GREATER_THAN)
  119. ->update(array('DbPlayoutStatus' => 0), $con);
  120. $this->setDbLastScheduled(gmdate("Y-m-d H:i:s"));
  121. $this->save($con);
  122. }
  123. /**
  124. *
  125. * This function resets the cc_schedule table's position numbers so that
  126. * tracks for each cc_show_instances start at position 1
  127. *
  128. * The position numbers can become out of sync when the user deletes items
  129. * from linekd shows filled with dyanmic smart blocks, where each instance
  130. * has a different amount of scheduled items
  131. */
  132. public function correctSchedulePositions()
  133. {
  134. $schedule = CcScheduleQuery::create()
  135. ->filterByDbInstanceId($this->id)
  136. ->orderByDbStarts()
  137. ->find();
  138. $pos = 0;
  139. foreach ($schedule as $item) {
  140. $item->setDbPosition($pos)->save();
  141. $pos++;
  142. }
  143. }
  144. /**
  145. * Computes the value of the aggregate column time_filled
  146. *
  147. * @param PropelPDO $con A connection object
  148. *
  149. * @return mixed The scalar result from the aggregate query
  150. */
  151. public function computeDbTimeFilled(PropelPDO $con)
  152. {
  153. $stmt = $con->prepare('SELECT SUM(clip_length) FROM "cc_schedule" WHERE cc_schedule.INSTANCE_ID = :p1');
  154. $stmt->bindValue(':p1', $this->getDbId());
  155. $stmt->execute();
  156. return $stmt->fetchColumn();
  157. }
  158. /**
  159. * Updates the aggregate column time_filled
  160. *
  161. * @param PropelPDO $con A connection object
  162. */
  163. public function updateDbTimeFilled(PropelPDO $con)
  164. {
  165. $timefilled = $this->computeDbTimeFilled($con);
  166. if(is_null($timefilled)){
  167. $timefilled = "00:00:00";
  168. }
  169. $this->setDbTimeFilled($timefilled);
  170. $this->save($con);
  171. }
  172. public function preInsert(PropelPDO $con = null) {
  173. $now = new DateTime("now", new DateTimeZone("UTC"));
  174. $this->setDbCreated($now);
  175. return true;
  176. }
  177. public function isRecorded()
  178. {
  179. return $this->getDbRecord() == 1 ? true : false;
  180. }
  181. public function isRebroadcast()
  182. {
  183. return $this->getDbRebroadcast() == 1 ? true : false;
  184. }
  185. public function getLocalStartDateTime()
  186. {
  187. $startDT = $this->getDbStarts(null);
  188. return $startDT->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone()));
  189. }
  190. } // CcShowInstances