Dashboard.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. class Application_Model_Dashboard
  3. {
  4. public static function GetPreviousItem($p_timeNow)
  5. {
  6. //get previous show and previous item in the schedule table.
  7. //Compare the two and if the last show was recorded and started
  8. //after the last item in the schedule table, then return the show's
  9. //name. Else return the last item from the schedule.
  10. $showInstance = Application_Model_ShowInstance::GetLastShowInstance($p_timeNow);
  11. $row = Application_Model_Schedule::GetLastScheduleItem($p_timeNow);
  12. if (is_null($showInstance)) {
  13. if (count($row) == 0) {
  14. return null;
  15. } else {
  16. return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
  17. "starts"=>$row[0]["starts"],
  18. "ends"=>$row[0]["ends"]);
  19. }
  20. } else {
  21. if (count($row) == 0) {
  22. if ($showInstance->isRecorded()) {
  23. //last item is a show instance
  24. return array("name"=>$showInstance->getName(),
  25. "starts"=>$showInstance->getShowInstanceStart(),
  26. "ends"=>$showInstance->getShowInstanceEnd());
  27. } else {
  28. return null;
  29. }
  30. } else {
  31. //return the one that started later.
  32. if ($row[0]["starts"] >= $showInstance->getShowInstanceStart()) {
  33. return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
  34. "starts"=>$row[0]["starts"],
  35. "ends"=>$row[0]["ends"]);
  36. } else {
  37. return array("name"=>$showInstance->getName(),
  38. "starts"=>$showInstance->getShowInstanceStart(),
  39. "ends"=>$showInstance->getShowInstanceEnd());
  40. }
  41. }
  42. }
  43. }
  44. public static function GetCurrentItem($p_timeNow)
  45. {
  46. //get previous show and previous item in the schedule table.
  47. //Compare the two and if the last show was recorded and started
  48. //after the last item in the schedule table, then return the show's
  49. //name. Else return the last item from the schedule.
  50. $row = array();
  51. $showInstance = Application_Model_ShowInstance::GetCurrentShowInstance($p_timeNow);
  52. if (!is_null($showInstance)) {
  53. $instanceId = $showInstance->getShowInstanceId();
  54. $row = Application_Model_Schedule::GetCurrentScheduleItem($p_timeNow, $instanceId);
  55. }
  56. if (is_null($showInstance)) {
  57. if (count($row) == 0) {
  58. return null;
  59. } else {
  60. /* Should never reach here, but lets return the track information
  61. * just in case we allow tracks to be scheduled without a show
  62. * in the future.
  63. */
  64. return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
  65. "starts"=>$row[0]["starts"],
  66. "ends"=>$row[0]["ends"]);
  67. }
  68. } else {
  69. if (count($row) == 0) {
  70. //last item is a show instance
  71. if ($showInstance->isRecorded()) {
  72. return array("name"=>$showInstance->getName(),
  73. "starts"=>$showInstance->getShowInstanceStart(),
  74. "ends"=>$showInstance->getShowInstanceEnd(),
  75. "media_item_played"=>false,
  76. "record"=>true);
  77. } else {
  78. return null;
  79. }
  80. } else {
  81. return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
  82. "starts"=>$row[0]["starts"],
  83. "ends"=>$row[0]["ends"],
  84. "media_item_played"=>$row[0]["media_item_played"],
  85. "record"=>0);
  86. }
  87. }
  88. }
  89. public static function GetNextItem($p_timeNow)
  90. {
  91. //get previous show and previous item in the schedule table.
  92. //Compare the two and if the last show was recorded and started
  93. //after the last item in the schedule table, then return the show's
  94. //name. Else return the last item from the schedule.
  95. $showInstance = Application_Model_ShowInstance::GetNextShowInstance($p_timeNow);
  96. $row = Application_Model_Schedule::GetNextScheduleItem($p_timeNow);
  97. if (is_null($showInstance)) {
  98. if (count($row) == 0) {
  99. return null;
  100. } else {
  101. return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
  102. "starts"=>$row[0]["starts"],
  103. "ends"=>$row[0]["ends"]);
  104. }
  105. } else {
  106. if (count($row) == 0) {
  107. if ($showInstance->isRecorded()) {
  108. //last item is a show instance
  109. return array("name"=>$showInstance->getName(),
  110. "starts"=>$showInstance->getShowInstanceStart(),
  111. "ends"=>$showInstance->getShowInstanceEnd());
  112. } else {
  113. return null;
  114. }
  115. } else {
  116. //return the one that starts sooner.
  117. if ($row[0]["starts"] <= $showInstance->getShowInstanceStart()) {
  118. return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
  119. "starts"=>$row[0]["starts"],
  120. "ends"=>$row[0]["ends"]);
  121. } else {
  122. return array("name"=>$showInstance->getName(),
  123. "starts"=>$showInstance->getShowInstanceStart(),
  124. "ends"=>$showInstance->getShowInstanceEnd());
  125. }
  126. }
  127. }
  128. }
  129. }