CcShow.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. /**
  3. * Skeleton subclass for representing a row from the 'cc_show' 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 CcShow extends BaseCcShow {
  14. /*
  15. * Returns all cc_show_day rules that belong to a cc_show and that are
  16. * repeating.
  17. * We do this because editing a single instance from a repeating sequence
  18. * creates a new rule in cc_show_days with the same cc_show id and a repeat
  19. * type of -1 (non-repeating).
  20. * So when the entire cc_show is updated after that, the single edited
  21. * instance can remain separate from the rest of the instances
  22. */
  23. public function getRepeatingCcShowDays(){
  24. return CcShowDaysQuery::create()
  25. ->filterByDbShowId($this->id)
  26. ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
  27. ->find();
  28. }
  29. /**
  30. * Gets an array of CcShowDays objects which contain a foreign key that references this object.
  31. *
  32. * If the $criteria is not null, it is used to always fetch the results from the database.
  33. * Otherwise the results are fetched from the database the first time, then cached.
  34. * Next time the same method is called without $criteria, the cached collection is returned.
  35. * If this CcShow is new, it will return
  36. * an empty collection or the current collection; the criteria is ignored on a new object.
  37. *
  38. * @param Criteria $criteria optional Criteria object to narrow the query
  39. * @param PropelPDO $con optional connection object
  40. * @return PropelCollection|array CcShowDays[] List of CcShowDays objects
  41. * @throws PropelException
  42. */
  43. public function getFirstCcShowDay($criteria = null, PropelPDO $con = null)
  44. {
  45. /*CcShowPeer::clearInstancePool();
  46. CcShowPeer::clearRelatedInstancePool();*/
  47. if(null === $this->collCcShowDayss || null !== $criteria) {
  48. if ($this->isNew() && null === $this->collCcShowDayss) {
  49. // return empty collection
  50. $this->initCcShowDayss();
  51. } else {
  52. $collCcShowDayss = CcShowDaysQuery::create(null, $criteria)
  53. ->filterByCcShow($this)
  54. ->orderByDbFirstShow()
  55. ->limit(1)
  56. ->find($con);
  57. if (null !== $criteria) {
  58. return $collCcShowDayss;
  59. }
  60. $this->collCcShowDayss = $collCcShowDayss;
  61. }
  62. }
  63. return $this->collCcShowDayss[0];
  64. }
  65. /**
  66. *
  67. * A repeating show may have a rule in cc_show_days with a repeat type
  68. * of -1 (not repeating). This happens when a single instances was edited
  69. * from the repeating sequence.
  70. *
  71. * When the repeating show gets edited in this case, we want to exclude all
  72. * the edited instances from the update. We do this by not returning any of
  73. * the cc_show_day rules with a -1 repeat type.
  74. */
  75. public function getFirstRepeatingCcShowDay()
  76. {
  77. return CcShowDaysQuery::create()
  78. ->filterByDbShowId($this->id)
  79. ->filterByDbRepeatType(-1, Criteria::NOT_EQUAL)
  80. ->orderByDbFirstShow()
  81. ->findOne();
  82. }
  83. /**
  84. *
  85. * In order to determine if a show is repeating we need to check each
  86. * cc_show_day entry and check if there are any non -1 repeat types.
  87. * Because editing a single instances creates a new cc_show_day rule
  88. * with a -1 (non repeating) repeat type we need to check all cc_show_day
  89. * entries
  90. */
  91. public function isRepeating()
  92. {
  93. //get all cc_show_day entries that are repeating
  94. $ccShowDays = CcShowDaysQuery::create()
  95. ->filterByDbShowId($this->id)
  96. ->filterByDbRepeatType(0, Criteria::GREATER_EQUAL)
  97. ->find();
  98. if (!$ccShowDays->isEmpty()) {
  99. return true;
  100. }
  101. return false;
  102. }
  103. /**
  104. * Returns all cc_show_instances that have been edited out of
  105. * a repeating sequence
  106. */
  107. public function getEditedRepeatingInstanceIds()
  108. {
  109. //get cc_show_days that have been edited (not repeating)
  110. $ccShowDays = CcShowDaysQuery::create()
  111. ->filterByDbShowId($this->id)
  112. ->filterByDbRepeatType(-1)
  113. ->find();
  114. $startsUTC = array();
  115. $utc = new DateTimeZone("UTC");
  116. foreach ($ccShowDays as $day) {
  117. //convert to UTC
  118. $starts = new DateTime(
  119. $day->getDbFirstShow()." ".$day->getDbStartTime(),
  120. new DateTimeZone($day->getDbTimezone())
  121. );
  122. $starts->setTimezone($utc);
  123. array_push($startsUTC, $starts->format("Y-m-d H:i:s"));
  124. }
  125. $excludeInstances = CcShowInstancesQuery::create()
  126. ->filterByDbShowId($this->id)
  127. ->filterByDbStarts($startsUTC, criteria::IN)
  128. ->find();
  129. $excludeIds = array();
  130. foreach ($excludeInstances as $instance) {
  131. array_push($excludeIds, $instance->getDbId());
  132. }
  133. return $excludeIds;
  134. }
  135. /**
  136. * Gets an array of CcShowInstances objects which contain a foreign key that references this object.
  137. *
  138. * If the $criteria is not null, it is used to always fetch the results from the database.
  139. * Otherwise the results are fetched from the database the first time, then cached.
  140. * Next time the same method is called without $criteria, the cached collection is returned.
  141. * If this CcShow is new, it will return
  142. * an empty collection or the current collection; the criteria is ignored on a new object.
  143. *
  144. * @param Criteria $criteria optional Criteria object to narrow the query
  145. * @param PropelPDO $con optional connection object
  146. * @return PropelCollection|array CcShowInstances[] List of CcShowInstances objects
  147. * @throws PropelException
  148. */
  149. public function getFutureCcShowInstancess($criteria = null, PropelPDO $con = null)
  150. {
  151. if(null === $this->collCcShowInstancess || null !== $criteria) {
  152. if ($this->isNew() && null === $this->collCcShowInstancess) {
  153. // return empty collection
  154. $this->initCcShowInstancess();
  155. } else {
  156. $collCcShowInstancess = CcShowInstancesQuery::create(null, $criteria)
  157. ->filterByCcShow($this)
  158. ->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)
  159. ->filterByDbModifiedInstance(false)
  160. ->find($con);
  161. if (null !== $criteria) {
  162. return $collCcShowInstancess;
  163. }
  164. $this->collCcShowInstancess = $collCcShowInstancess;
  165. }
  166. }
  167. return $this->collCcShowInstancess;
  168. }
  169. public function isRecorded()
  170. {
  171. $ccShowDay = CcShowDaysQuery::create()
  172. ->filterByDbShowId($this->getDbId())
  173. ->filterByDbRecord(1)
  174. ->findOne();
  175. return (!is_null($ccShowDay));
  176. }
  177. public function isRebroadcast()
  178. {
  179. $ccShowRebroadcast = CcShowRebroadcastQuery::create()
  180. ->filterByDbShowId($this->getDbId())
  181. ->findOne();
  182. return (!is_null($ccShowRebroadcast));
  183. }
  184. public function getRebroadcastsRelative()
  185. {
  186. return CcShowRebroadcastQuery::create()
  187. ->filterByDbShowId($this->getDbId())
  188. ->orderByDbDayOffset()
  189. ->find();
  190. }
  191. public function getRebroadcastsAbsolute()
  192. {
  193. return CcShowInstancesQuery::create()
  194. ->filterByDbShowId($this->getDbId())
  195. ->filterByDbRebroadcast(1)
  196. ->filterByDbModifiedInstance(false)
  197. ->orderByDbStarts()
  198. ->find();
  199. }
  200. public function isLinked()
  201. {
  202. return $this->getDbLinked();
  203. }
  204. public function isLinkable()
  205. {
  206. return $this->getDbIsLinkable();
  207. }
  208. /**
  209. * Gets an array of CcShowInstances objects which contain a foreign key that references this object.
  210. *
  211. * If the $criteria is not null, it is used to always fetch the results from the database.
  212. * Otherwise the results are fetched from the database the first time, then cached.
  213. * Next time the same method is called without $criteria, the cached collection is returned.
  214. * If this CcShow is new, it will return
  215. * an empty collection or the current collection; the criteria is ignored on a new object.
  216. *
  217. * @param Criteria $criteria optional Criteria object to narrow the query
  218. * @param PropelPDO $con optional connection object
  219. * @return PropelCollection|array CcShowInstances[] List of CcShowInstances objects
  220. * @throws PropelException
  221. */
  222. public function getCcShowInstancess($criteria = null, PropelPDO $con = null)
  223. {
  224. return CcShowInstancesQuery::create(null, $criteria)
  225. ->filterByCcShow($this)
  226. ->filterByDbModifiedInstance(false)
  227. ->orderByDbId()
  228. ->find($con);
  229. /*if(null === $this->collCcShowInstancess || null !== $criteria) {
  230. if ($this->isNew() && null === $this->collCcShowInstancess) {
  231. // return empty collection
  232. $this->initCcShowInstancess();
  233. } else {
  234. $collCcShowInstancess = CcShowInstancesQuery::create(null, $criteria)
  235. ->filterByCcShow($this)
  236. ->filterByDbModifiedInstance(false)
  237. ->filterByDbStarts(gmdate("Y-m-d H:i:s"), criteria::GREATER_THAN)
  238. ->orderByDbId()
  239. ->find($con);
  240. if (null !== $criteria) {
  241. return $collCcShowInstancess;
  242. }
  243. $this->collCcShowInstancess = $collCcShowInstancess;
  244. }
  245. }
  246. return $this->collCcShowInstancess;*/
  247. }
  248. public function getInstanceIds() {
  249. $instanceIds = array();
  250. foreach ($this->getCcShowInstancess() as $ccShowInstance) {
  251. $instanceIds[] = $ccShowInstance->getDbId();
  252. }
  253. return $instanceIds;
  254. }
  255. /*
  256. * Returns cc_show_instance ids where the start time is greater than
  257. * the current time
  258. *
  259. * If a Criteria object is passed in Propel will always fetch the
  260. * results from the database and not return a cached collection
  261. */
  262. public function getFutureInstanceIds($criteria = null) {
  263. $instanceIds = array();
  264. foreach ($this->getFutureCcShowInstancess($criteria) as $ccShowInstance) {
  265. $instanceIds[] = $ccShowInstance->getDbId();
  266. }
  267. return $instanceIds;
  268. }
  269. //what is this??
  270. public function getOtherInstances($instanceId)
  271. {
  272. return CcShowInstancesQuery::create()
  273. ->filterByCcShow($this)
  274. ->filterByDbId($instanceId, Criteria::NOT_EQUAL)
  275. ->find();
  276. }
  277. public function getShowInfo()
  278. {
  279. $info = array();
  280. if ($this->getDbId() == null) {
  281. return $info;
  282. } else {
  283. $info['name'] = $this->getDbName();
  284. $info['id'] = $this->getDbId();
  285. $info['url'] = $this->getDbUrl();
  286. $info['genre'] = $this->getDbGenre();
  287. $info['description'] = $this->getDbDescription();
  288. $info['color'] = $this->getDbColor();
  289. $info['background_color'] = $this->getDbBackgroundColor();
  290. $info['linked'] = $this->getDbLinked();
  291. return $info;
  292. }
  293. }
  294. } // CcShow