CcPlaylist.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Skeleton subclass for representing a row from the 'cc_playlist' 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.campcaster
  12. */
  13. class CcPlaylist extends BaseCcPlaylist {
  14. /**
  15. * Get the [optionally formatted] temporal [utime] 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 getDbUtime($format = 'Y-m-d H:i:s')
  24. {
  25. if ($this->utime === null) {
  26. return null;
  27. }
  28. try {
  29. $dt = new DateTime($this->utime, 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->utime, 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 [mtime] 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 getDbMtime($format = 'Y-m-d H:i:s')
  52. {
  53. if ($this->mtime === null) {
  54. return null;
  55. }
  56. try {
  57. $dt = new DateTime($this->mtime, 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->mtime, 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. * Computes the value of the aggregate column length
  72. * Overridden to provide a default of 00:00:00 if the playlist is empty.
  73. *
  74. * @param PropelPDO $con A connection object
  75. *
  76. * @return mixed The scalar result from the aggregate query
  77. */
  78. public function computeDbLength(PropelPDO $con)
  79. {
  80. $sql = <<<SQL
  81. SELECT SUM(cliplength) FROM cc_playlistcontents as pc
  82. LEFT JOIN cc_files as f ON pc.file_id = f.id
  83. WHERE PLAYLIST_ID = :p1
  84. AND (f.file_exists is NUll or f.file_exists = true)
  85. SQL;
  86. $stmt = $con->prepare($sql);
  87. $stmt->bindValue(':p1', $this->getDbId());
  88. $stmt->execute();
  89. $length = $stmt->fetchColumn();
  90. if (is_null($length)) {
  91. $length = "00:00:00";
  92. }
  93. return $length;
  94. }
  95. } // CcPlaylist