From c665a3fa0391575956144ced41a5c13a6afe91f6 Mon Sep 17 00:00:00 2001
From: Naomi Aro <naomiaro@gmail.com>
Date: Thu, 23 Feb 2012 22:23:21 +0100
Subject: [PATCH] CC-3333 : showbuilder track colouring

tracks coloured if boundry/over.

needs better colour selection.
---
 .../application/models/ShowBuilder.php        | 25 +++++++++++++++++++
 airtime_mvc/public/css/showbuilder.css        |  8 ++++++
 .../public/js/airtime/showbuilder/builder.js  |  8 ++++++
 3 files changed, 41 insertions(+)

diff --git a/airtime_mvc/application/models/ShowBuilder.php b/airtime_mvc/application/models/ShowBuilder.php
index 327c18d1b..1a715ea7e 100644
--- a/airtime_mvc/application/models/ShowBuilder.php
+++ b/airtime_mvc/application/models/ShowBuilder.php
@@ -114,6 +114,29 @@ class Application_Model_ShowBuilder {
         }
     }
 
+    private function getItemStatus($p_item, &$row) {
+
+        $showEndDT = new DateTime($p_item["si_ends"]);
+        $schedStartDT = new DateTime($p_item["sched_starts"]);
+        $schedEndDT = new DateTime($p_item["sched_ends"]);
+
+        $showEndEpoch = intval($showEndDT->format("U"));
+        $schedStartEpoch = intval($schedStartDT->format("U"));
+        $schedEndEpoch = intval($schedEndDT->format("U"));
+
+        if ($schedEndEpoch < $showEndEpoch) {
+            $status = 0; //item will playout in full
+        }
+        else if ($schedStartEpoch < $showEndEpoch && $schedEndEpoch > $showEndEpoch) {
+            $status = 1; //item is on boundry
+        }
+        else {
+            $status = 2; //item is overscheduled won't play.
+        }
+
+        $row["status"] = $status;
+    }
+
     private function getRowTimestamp($p_item, &$row) {
 
         if (is_null($p_item["si_last_scheduled"])) {
@@ -163,6 +186,8 @@ class Application_Model_ShowBuilder {
             $schedEndDT = new DateTime($p_item["sched_ends"], new DateTimeZone("UTC"));
             $schedEndDT->setTimezone(new DateTimeZone($this->timezone));
 
+            $this->getItemStatus($p_item, $row);
+
             $runtime = $schedStartDT->diff($schedEndDT);
 
             $row["id"] = intval($p_item["sched_id"]);
diff --git a/airtime_mvc/public/css/showbuilder.css b/airtime_mvc/public/css/showbuilder.css
index fd2cc1e14..95ec1aad8 100644
--- a/airtime_mvc/public/css/showbuilder.css
+++ b/airtime_mvc/public/css/showbuilder.css
@@ -22,4 +22,12 @@ table.datatable tr.cursor-selected-row td, table.datatable tr.cursor-selected-ro
 }
 tr.cursor-selected-row .marker {
     background-position: 0 -15px;
+}
+
+.sb-boundry {
+    background-color:#e66a31;
+}
+
+.sb-over {
+    background-color:#ff3030;
 }
\ No newline at end of file
diff --git a/airtime_mvc/public/js/airtime/showbuilder/builder.js b/airtime_mvc/public/js/airtime/showbuilder/builder.js
index 7bbbb17d4..8ade81a30 100644
--- a/airtime_mvc/public/js/airtime/showbuilder/builder.js
+++ b/airtime_mvc/public/js/airtime/showbuilder/builder.js
@@ -284,6 +284,14 @@ $(document).ready(function() {
 				$(nRow).addClass("sb-not-allowed");
 			}
 			
+			//status used to colour tracks.
+			if (aData.status === 1) {
+				$(nRow).addClass("sb-boundry");
+			}
+			else if (aData.status === 2) {
+				$(nRow).addClass("sb-over");
+			}
+			
 			fnPrepareSeparatorRow = function(sRowContent, sClass, iNodeIndex) {
 				
 				node = nRow.children[iNodeIndex];