CC-3174 : showbuilder
making a time filled formatter to take the code out of show builder.
This commit is contained in:
parent
1c43edb40b
commit
b813ba1035
2 changed files with 50 additions and 30 deletions
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'formatters/LengthFormatter.php';
|
require_once 'formatters/LengthFormatter.php';
|
||||||
|
require_once 'formatters/TimeFilledFormatter.php';
|
||||||
|
|
||||||
class Application_Model_ShowBuilder {
|
class Application_Model_ShowBuilder {
|
||||||
|
|
||||||
|
@ -48,35 +49,6 @@ class Application_Model_ShowBuilder {
|
||||||
$this->epoch_now = time();
|
$this->epoch_now = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formatTimeFilled($p_sec) {
|
|
||||||
|
|
||||||
$formatted = "";
|
|
||||||
$sign = ($p_sec < 0) ? "-" : "+";
|
|
||||||
|
|
||||||
$time = Application_Model_Playlist::secondsToPlaylistTime(abs($p_sec));
|
|
||||||
Logging::log("time is: ".$time);
|
|
||||||
$info = explode(":", $time);
|
|
||||||
|
|
||||||
$formatted .= $sign;
|
|
||||||
|
|
||||||
if (intval($info[0]) > 0) {
|
|
||||||
$info[0] = ltrim($info[0], "0");
|
|
||||||
$formatted .= " {$info[0]}h";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (intval($info[1]) > 0) {
|
|
||||||
$info[1] = ltrim($info[1], "0");
|
|
||||||
$formatted .= " {$info[1]}m";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (intval($info[2]) > 0) {
|
|
||||||
$sec = round($info[2], 0);
|
|
||||||
$formatted .= " {$sec}s";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $formatted;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check to see if this row should be editable.
|
//check to see if this row should be editable.
|
||||||
private function isAllowed($p_item, &$row) {
|
private function isAllowed($p_item, &$row) {
|
||||||
|
|
||||||
|
@ -206,7 +178,9 @@ class Application_Model_ShowBuilder {
|
||||||
|
|
||||||
$runtime = bcsub($contentDT->format("U.u"), $showEndDT->format("U.u"), 6);
|
$runtime = bcsub($contentDT->format("U.u"), $showEndDT->format("U.u"), 6);
|
||||||
$row["runtime"] = $runtime;
|
$row["runtime"] = $runtime;
|
||||||
$row["fRuntime"] = $this->formatTimeFilled($runtime);
|
|
||||||
|
$timeFilled = new TimeFilledFormatter($runtime);
|
||||||
|
$row["fRuntime"] = $timeFilled->format();
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class TimeFilledFormatter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @string seconds
|
||||||
|
*/
|
||||||
|
private $_seconds;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param string $seconds
|
||||||
|
*/
|
||||||
|
public function __construct($seconds)
|
||||||
|
{
|
||||||
|
$this->_seconds = $seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function format()
|
||||||
|
{
|
||||||
|
$formatted = "";
|
||||||
|
$sign = ($this->_seconds < 0) ? "-" : "+";
|
||||||
|
|
||||||
|
$time = Application_Model_Playlist::secondsToPlaylistTime(abs($this->_seconds));
|
||||||
|
Logging::log("time is: ".$time);
|
||||||
|
$info = explode(":", $time);
|
||||||
|
|
||||||
|
$formatted .= $sign;
|
||||||
|
|
||||||
|
if (intval($info[0]) > 0) {
|
||||||
|
$info[0] = ltrim($info[0], "0");
|
||||||
|
$formatted .= " {$info[0]}h";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intval($info[1]) > 0) {
|
||||||
|
$info[1] = ltrim($info[1], "0");
|
||||||
|
$formatted .= " {$info[1]}m";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intval($info[2]) > 0) {
|
||||||
|
$sec = round($info[2], 0);
|
||||||
|
$formatted .= " {$sec}s";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $formatted;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue