diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index fa9ae8b1e..e843727a3 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -108,8 +108,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm if( $formData["add_show_duration"] == "0m" ) { $this->getElement('add_show_duration')->setErrors(array('Cannot have duration 0m')); $valid = false; - }elseif(strpos($formData["add_show_duration"], 'h') !== false && intval(substr($formData["add_show_duration"], 0, strpos($formData["add_show_duration"], 'h'))) > 23) { - $this->getElement('add_show_duration')->setErrors(array('Cannot have duration > 24h')); + }elseif(strpos($formData["add_show_duration"], 'h') !== false && intval(substr($formData["add_show_duration"], 0, strpos($formData["add_show_duration"], 'h'))) > 24) { + $this->getElement('add_show_duration')->setErrors(array('Cannot have duration greater than 24h')); $valid = false; }elseif( strstr($formData["add_show_duration"], '-') ){ $this->getElement('add_show_duration')->setErrors(array('Cannot have duration < 0m')); diff --git a/airtime_mvc/application/models/Nowplaying.php b/airtime_mvc/application/models/Nowplaying.php index 9a43fa4a3..eea8bbbb9 100644 --- a/airtime_mvc/application/models/Nowplaying.php +++ b/airtime_mvc/application/models/Nowplaying.php @@ -8,55 +8,28 @@ class Application_Model_Nowplaying } public static function CreateDatatableRows($p_dbRows){ - - $dataTablesRows = array(); - - $date = new DateHelper; - $timeNow = $date->getTimestamp(); - - - foreach ($p_dbRows as $dbRow){ - $status = ($dbRow['show_ends'] < $dbRow['item_ends']) ? "x" : ""; - - $type = "a"; - $type .= ($dbRow['item_ends'] > $timeNow && $dbRow['item_starts'] <= $timeNow) ? "c" : ""; - - // remove millisecond from the time format - $itemStart = explode('.', $dbRow['item_starts']); - $itemEnd = explode('.', $dbRow['item_ends']); - - //format duration - $duration = explode('.', $dbRow['clip_length']); - $duration = explode(':', $duration[0]); - - if($duration[2] == 0){ - $duration[2] = ''; - }else{ - $duration[2] = intval($duration[2],10).'s'; - } - - if($duration[1] == 0){ - if($duration[2] == ''){ - $duration[1] = ''; - }else{ - $duration[1] = intval($duration[1],10).'m'; - } - }else{ - $duration[1] = intval($duration[1],10).'m'; - } - - if($duration[0] == 0){ - $duration[0] = ''; - }else{ - $duration[0] = intval($duration[0],10).'h'; - } - - $duration = $duration[0].$duration[1].$duration[2]; - - $dataTablesRows[] = array($type, $dbRow['show_starts'], $itemStart[0], $itemEnd[0], - $duration, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'], - $dbRow['playlist_name'], $dbRow['show_name'], $status); - } + $dataTablesRows = array(); + + $date = new DateHelper; + $timeNow = $date->getTimestamp(); + + foreach ($p_dbRows as $dbRow){ + $status = ($dbRow['show_ends'] < $dbRow['item_ends']) ? "x" : ""; + + $type = "a"; + $type .= ($dbRow['item_ends'] > $timeNow && $dbRow['item_starts'] <= $timeNow) ? "c" : ""; + + // remove millisecond from the time format + $itemStart = explode('.', $dbRow['item_starts']); + $itemEnd = explode('.', $dbRow['item_ends']); + + //format duration + $duration = explode('.', $dbRow['clip_length']); + $formated = Application_Model_Nowplaying::FormatDuration($duration[0]); + $dataTablesRows[] = array($type, $dbRow['show_starts'], $itemStart[0], $itemEnd[0], + $formated, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'], + $dbRow['playlist_name'], $dbRow['show_name'], $status); + } return $dataTablesRows; } @@ -87,42 +60,81 @@ class Application_Model_Nowplaying $endCutoff = $date->getNowDayEndDiff(); } - $data = array(); + $data = array(); - $showIds = ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff); - foreach ($showIds as $showId){ - $instanceId = $showId['id']; + $showIds = ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff); + foreach ($showIds as $showId){ + $instanceId = $showId['id']; + + $si = new ShowInstance($instanceId); + + $showId = $si->getShowId(); + $show = new Show($showId); + + //append show header row + $data[] = Application_Model_Nowplaying::CreateHeaderRow($show->getName(), $si->getShowStart(), $si->getShowEnd()); + + $scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff); + $dataTablesRows = Application_Model_Nowplaying::CreateDatatableRows($scheduledItems); + + //append show audio item rows + $data = array_merge($data, $dataTablesRows); + + //append show gap time row + $gapTime = Application_Model_Nowplaying::FormatDuration($si->getShowEndGapTime(), true); + if ($si->isRecorded()) + $data[] = Application_Model_Nowplaying::CreateRecordingRow($si); + else if ($gapTime > 0) + $data[] = Application_Model_Nowplaying::CreateGapRow($gapTime); + } - $si = new ShowInstance($instanceId); - - $showId = $si->getShowId(); - $show = new Show($showId); - - //append show header row - $data[] = Application_Model_Nowplaying::CreateHeaderRow($show->getName(), $si->getShowStart(), $si->getShowEnd()); - - $scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff); - $dataTablesRows = Application_Model_Nowplaying::CreateDatatableRows($scheduledItems); - - //append show audio item rows - $data = array_merge($data, $dataTablesRows); - - //append show gap time row - $gapTime = $si->getShowEndGapTime(); - if ($si->isRecorded()) - $data[] = Application_Model_Nowplaying::CreateRecordingRow($si); - else if ($gapTime > 0) - $data[] = Application_Model_Nowplaying::CreateGapRow($gapTime); - } - - return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data); - } - - public static function ShouldShowPopUp(){ - $today = mktime(0, 0, 0, date("m") , date("d"), date("Y")); - $remindDate = Application_Model_Preference::GetRemindMeDate(); - if($remindDate == NULL || $today >= $remindDate){ - return true; - } - } + return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data); + } + + public static function ShouldShowPopUp(){ + $today = mktime(0, 0, 0, date("m") , date("d"), date("Y")); + $remindDate = Application_Model_Preference::GetRemindMeDate(); + if($remindDate == NULL || $today >= $remindDate){ + return true; + } + } + /* + * default $time format should be in format of 00:00:00 + * if $inSecond = true, then $time should be in seconds + */ + public static function FormatDuration($time, $inSecond=false){ + if($inSecond == false){ + $duration = explode(':', $time); + }else{ + $duration = array(); + $duration[0] = intval(($time/3600)%24); + $duration[1] = intval(($time/60)%60); + $duration[2] = $time%60; + } + + if($duration[2] == 0){ + $duration[2] = ''; + }else{ + $duration[2] = intval($duration[2],10).'s'; + } + + if($duration[1] == 0){ + if($duration[2] == ''){ + $duration[1] = ''; + }else{ + $duration[1] = intval($duration[1],10).'m '; + } + }else{ + $duration[1] = intval($duration[1],10).'m '; + } + + if($duration[0] == 0){ + $duration[0] = ''; + }else{ + $duration[0] = intval($duration[0],10).'h '; + } + + $out = $duration[0].$duration[1].$duration[2]; + return $out; + } } diff --git a/airtime_mvc/public/css/add-show.css b/airtime_mvc/public/css/add-show.css index 356f7c133..cb88f34df 100644 --- a/airtime_mvc/public/css/add-show.css +++ b/airtime_mvc/public/css/add-show.css @@ -113,16 +113,16 @@ label.wrapp-label input[type="checkbox"] { } #add_show_start_time, #add_show_end_time { - width: 70px; + width: 60px; margin-left:10px; } #add_show_end_date_no_repeat, #add_show_start_date { - width: 100px; + width: 95px; } #add_show_duration { background: #AAAAAA; cursor: default; - width: 100px; + width: 50px; } diff --git a/airtime_mvc/public/js/airtime/nowplaying/nowplayingdatagrid.js b/airtime_mvc/public/js/airtime/nowplaying/nowplayingdatagrid.js index b20804745..57f62ce2d 100644 --- a/airtime_mvc/public/js/airtime/nowplaying/nowplayingdatagrid.js +++ b/airtime_mvc/public/js/airtime/nowplaying/nowplayingdatagrid.js @@ -167,26 +167,17 @@ function createDataGrid(){ nGroup.appendChild(nCell); nTrs[i].parentNode.replaceChild(nGroup, nTrs[i]); } else if ( sType.indexOf("g") != -1 ){ - //gap row found - + //gap row found var gapTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[4]; - - var hours = parseInt( gapTime / 3600 ) % 24; - var minutes = parseInt( gapTime / 60 ) % 60; - var seconds = gapTime % 60; - - var gapTimeFormat = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds); - var nGroup = document.createElement('tr'); var nCell = document.createElement('td'); nCell.colSpan = iColspan; nCell.className = "gap"; - nCell.innerHTML = "Gap until show end: " + gapTimeFormat; + nCell.innerHTML = "Gap until show end: " + gapTime; nGroup.appendChild(nCell); nTrs[i].parentNode.replaceChild(nGroup, nTrs[i]); } else if ( sType.indexOf("r") != -1 ){ - //gap row found - + //gap row found var showName = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[4]; var nGroup = document.createElement('tr');