From 7a5e5d9789e6162ae67ab5f2a129fd237380eb07 Mon Sep 17 00:00:00 2001 From: Frank Bergkemper Date: Tue, 9 Sep 2014 02:55:20 +0200 Subject: [PATCH] update --- .../Application/View/Helper/JobDuration.php | 19 ++--- .../view/dashboard/dashboard/index.phtml | 6 +- module/Job/src/Job/Model/Job.php | 2 + module/Job/src/Job/Model/JobTable.php | 78 ++++++++++++++++--- module/Job/view/job/job/index.phtml | 12 ++- module/Job/view/job/job/running.phtml | 4 +- module/Job/view/job/job/successful.phtml | 6 +- module/Job/view/job/job/unsuccessful.phtml | 7 +- module/Job/view/job/job/waiting.phtml | 6 -- 9 files changed, 94 insertions(+), 46 deletions(-) diff --git a/module/Application/src/Application/View/Helper/JobDuration.php b/module/Application/src/Application/View/Helper/JobDuration.php index 767baf27..0701bb09 100644 --- a/module/Application/src/Application/View/Helper/JobDuration.php +++ b/module/Application/src/Application/View/Helper/JobDuration.php @@ -27,14 +27,15 @@ use Zend\View\Helper\AbstractHelper; -class JobDuration extends AbstractHelper +class JobDuration extends AbstractHelper { - public function __invoke($date1, $date2) - { - $datetime1 = strtotime($date1); - $datetime2 = strtotime($date2); - $diff = $datetime2 - $datetime1; - $duration = date('H:i:s',$diff); - return $duration; - } + public function __invoke($duration) + { + if($duration > 0) { + return sprintf('%02d:%02d:%02d', ($duration/3600),($duration/60%60), $duration%60); + } + else { + return $duration = "-"; + } + } } diff --git a/module/Dashboard/view/dashboard/dashboard/index.phtml b/module/Dashboard/view/dashboard/dashboard/index.phtml index b1256b84..f358eb67 100644 --- a/module/Dashboard/view/dashboard/dashboard/index.phtml +++ b/module/Dashboard/view/dashboard/dashboard/index.phtml @@ -86,7 +86,6 @@ $flash->setMessageOpenFormat(' translate("Type"); ?> translate("Level"); ?> translate("Start"); ?> - translate("Status"); ?> translate("Action"); ?> @@ -101,7 +100,6 @@ $flash->setMessageOpenFormat(' printJobType($item->type); ?> printJobLevel($item->level); ?> printDate($item->starttime); ?> - printJobStatus($item->jobstatus); ?> @@ -265,7 +263,7 @@ $flash->setMessageOpenFormat(' printJobLevel($jobUnsuccess->level); ?> printDate($jobUnsuccess->starttime); ?> printDate($jobUnsuccess->endtime); ?> - printJobDuration($jobUnsuccess->starttime, $jobUnsuccess->endtime); ?> + printJobDuration($jobUnsuccess->duration); ?> printJobStatus($jobUnsuccess->jobstatus); ?> type == "B") : ?> @@ -354,7 +352,7 @@ $flash->setMessageOpenFormat(' printJobLevel($jobSuccess->level); ?> printDate($jobSuccess->starttime); ?> printDate($jobSuccess->endtime); ?> - printJobDuration($jobSuccess->starttime, $jobSuccess->endtime); ?> + printJobDuration($jobSuccess->duration); ?> printJobStatus($jobSuccess->jobstatus); ?> type == "B") : ?> diff --git a/module/Job/src/Job/Model/Job.php b/module/Job/src/Job/Model/Job.php index 79534075..113f7c26 100644 --- a/module/Job/src/Job/Model/Job.php +++ b/module/Job/src/Job/Model/Job.php @@ -56,6 +56,7 @@ class Job public $reviewed; public $comment; public $clientname; + public $duration; public function exchangeArray($data) { @@ -82,6 +83,7 @@ public function exchangeArray($data) $this->poolid = (!empty($data['poolid'])) ? $data['poolid'] : null; $this->filesetid = (!empty($data['filesetid'])) ? $data['filesetid'] : null; $this->clientname = (!empty($data['clientname'])) ? $data['clientname'] : null; + $this->duration = (!empty($data['duration'])) ? $data['duration'] : null; } } diff --git a/module/Job/src/Job/Model/JobTable.php b/module/Job/src/Job/Model/JobTable.php index a653cb33..8817a5ef 100644 --- a/module/Job/src/Job/Model/JobTable.php +++ b/module/Job/src/Job/Model/JobTable.php @@ -28,6 +28,7 @@ use Zend\Db\ResultSet\ResultSet; use Zend\Db\TableGateway\TableGateway; use Zend\Db\Sql\Select; +use Zend\Db\Sql\Expression; use Zend\Paginator\Adapter\DbSelect; use Zend\Paginator\Paginator; use Zend\ServiceManager\ServiceLocatorAwareInterface; @@ -59,9 +60,27 @@ public function getDbDriverConfig() { public function fetchAll($paginated=false, $order_by=null, $order=null) { + if($this->getDbDriverConfig() == "Pdo_Mysql" || $this->getDbDriverConfig() == "Mysqli") { + $duration = new Expression("TIMESTAMPDIFF(SECOND, StartTime, EndTime)"); + } + elseif($this->getDbDriverConfig() == "Pdo_Pgsql" || $this->getDbDriverConfig() == "Pgsql") { + $duration = new Expression("DATE_PART('second', 'EndTime'::timestamp - 'StartTime'::timestamp)"); + } + $bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig()); $select = new Select(); $select->from($bsqlch->strdbcompat("Job")); + $select->columns(array( + $bsqlch->strdbcompat("JobId"), + $bsqlch->strdbcompat("Name"), + $bsqlch->strdbcompat("Type"), + $bsqlch->strdbcompat("Level"), + $bsqlch->strdbcompat("StartTime"), + $bsqlch->strdbcompat("EndTime"), + $bsqlch->strdbcompat("JobStatus"), + 'duration' => $duration, + ) + ); $select->join( $bsqlch->strdbcompat("Client"), $bsqlch->strdbcompat("Job.ClientId = Client.ClientId"), @@ -206,23 +225,41 @@ public function getWaitingJobs($paginated=false, $order_by=null, $order=null) public function getLast24HoursSuccessfulJobs($paginated=false, $order_by=null, $order=null) { - $current_time = date("Y-m-d H:i:s",time()); - $back24h_time = date("Y-m-d H:i:s",time() - (60*60*24)); - + if($this->getDbDriverConfig() == "Pdo_Mysql" || $this->getDbDriverConfig() == "Mysqli") { + $duration = new Expression("TIMESTAMPDIFF(SECOND, StartTime, EndTime)"); + $interval = "now() - interval 1 day"; + } + elseif($this->getDbDriverConfig() == "Pdo_Pgsql" || $this->getDbDriverConfig() == "Pgsql") { + $duration = new Expression("DATE_PART('second', 'EndTime'::timestamp - 'StartTime'::timestamp)"); + $interval = "now() - interval '1 day'"; + } + $bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig()); $select = new Select(); $select->from($bsqlch->strdbcompat("Job")); + $select->columns(array( + $bsqlch->strdbcompat("JobId"), + $bsqlch->strdbcompat("Name"), + $bsqlch->strdbcompat("Type"), + $bsqlch->strdbcompat("Level"), + $bsqlch->strdbcompat("StartTime"), + $bsqlch->strdbcompat("EndTime"), + $bsqlch->strdbcompat("JobStatus"), + 'duration' => $duration, + ) + ); $select->join( $bsqlch->strdbcompat("Client"), $bsqlch->strdbcompat("Job.ClientId = Client.ClientId"), array($bsqlch->strdbcompat("ClientName") => $bsqlch->strdbcompat("Name")) ); + $select->where( "(" . $bsqlch->strdbcompat("JobStatus") . " = 'T' OR " . - $bsqlch->strdbcompat("JobStatus") . " = 'W' ) AND " . - $bsqlch->strdbcompat("StartTime") . " >= '" . $back24h_time . "' AND " . - $bsqlch->strdbcompat("EndTime") . " >= '" . $back24h_time . "'" + $bsqlch->strdbcompat("JobStatus") . " = 'W' ) AND (" . + $bsqlch->strdbcompat("StartTime") . " >= " . $interval . " OR " . + $bsqlch->strdbcompat("EndTime") . " >= " . $interval . ")" ); if($order_by != null && $order != null) { @@ -251,12 +288,29 @@ public function getLast24HoursSuccessfulJobs($paginated=false, $order_by=null, $ public function getLast24HoursUnsuccessfulJobs($paginated=false, $order_by=null, $order=null) { - $current_time = date("Y-m-d H:i:s",time()); - $back24h_time = date("Y-m-d H:i:s",time() - (60*60*24)); - + if($this->getDbDriverConfig() == "Pdo_Mysql" || $this->getDbDriverConfig() == "Mysqli") { + $duration = new Expression("TIMESTAMPDIFF(SECOND, StartTime, EndTime)"); + $interval = "now() - interval 1 day"; + } + elseif($this->getDbDriverConfig() == "Pdo_Pgsql" || $this->getDbDriverConfig() == "Pgsql") { + $duration = new Expression("DATE_PART('second', 'EndTime'::timestamp - 'StartTime'::timestamp)"); + $interval = "now() - interval '1 day'"; + } + $bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig()); $select = new Select(); $select->from($bsqlch->strdbcompat("Job")); + $select->columns(array( + $bsqlch->strdbcompat("JobId"), + $bsqlch->strdbcompat("Name"), + $bsqlch->strdbcompat("Type"), + $bsqlch->strdbcompat("Level"), + $bsqlch->strdbcompat("StartTime"), + $bsqlch->strdbcompat("EndTime"), + $bsqlch->strdbcompat("JobStatus"), + 'duration' => $duration, + ) + ); $select->join( $bsqlch->strdbcompat("Client"), $bsqlch->strdbcompat("Job.ClientId = Client.ClientId"), @@ -267,9 +321,9 @@ public function getLast24HoursUnsuccessfulJobs($paginated=false, $order_by=null, $bsqlch->strdbcompat("JobStatus") . " = 'A' OR " . $bsqlch->strdbcompat("JobStatus") . " = 'E' OR " . $bsqlch->strdbcompat("JobStatus") . " = 'e' OR " . - $bsqlch->strdbcompat("JobStatus") . " = 'f' ) AND " . - $bsqlch->strdbcompat("StartTime") . " >= '" . $back24h_time . "' AND " . - $bsqlch->strdbcompat("EndTime") . " >= '" . $back24h_time . "'" + $bsqlch->strdbcompat("JobStatus") . " = 'f' ) AND (" . + $bsqlch->strdbcompat("StartTime") . " >= " . $interval . " OR " . + $bsqlch->strdbcompat("EndTime") . " >= " . $interval . ")" ); if($order_by != null && $order != null) { diff --git a/module/Job/view/job/job/index.phtml b/module/Job/view/job/job/index.phtml index 48a24ad6..0815e1cd 100644 --- a/module/Job/view/job/job/index.phtml +++ b/module/Job/view/job/job/index.phtml @@ -43,6 +43,9 @@ elseif($order_by == 'EndTime') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; elseif($order_by == 'JobStatus') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; +elseif($order_by == 'duration') { + $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; +} ?> @@ -87,7 +90,7 @@ Jobs per page: translate("Level"); ?> translate("Start"); ?> translate("End"); ?> - translate("Duration"); ?> + translate("Duration"); ?> translate("Status"); ?> translate("Action"); ?> @@ -104,12 +107,7 @@ Jobs per page: printJobLevel($job->level); ?> printDate($job->starttime); ?> printDate($job->endtime); ?> - endtime)) : ?> - printJobDuration($job->starttime, $job->endtime); ?> - - endtime)) : ?> - escapeHtml("-"); ?> - + printJobDuration($job->duration); ?> printJobStatus($job->jobstatus); ?> type == "B") : ?> diff --git a/module/Job/view/job/job/running.phtml b/module/Job/view/job/job/running.phtml index 279152c8..f3e1e622 100644 --- a/module/Job/view/job/job/running.phtml +++ b/module/Job/view/job/job/running.phtml @@ -41,8 +41,6 @@ elseif($order_by == 'StartTime') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; elseif($order_by == 'EndTime') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; -elseif($order_by == 'JobStatus') - $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; ?> @@ -105,7 +103,7 @@ Jobs per page: translate("Type"); ?> translate("Level"); ?> translate("Start"); ?> - translate("Status"); ?> + translate("Status"); ?> translate("Action"); ?> diff --git a/module/Job/view/job/job/successful.phtml b/module/Job/view/job/job/successful.phtml index 29ba18a6..9d06965e 100644 --- a/module/Job/view/job/job/successful.phtml +++ b/module/Job/view/job/job/successful.phtml @@ -43,6 +43,8 @@ elseif($order_by == 'EndTime') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; elseif($order_by == 'JobBytes') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; +elseif($order_by == 'duration') + $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; ?> @@ -106,7 +108,7 @@ Jobs per page: translate("Level"); ?> translate("Start"); ?> translate("End"); ?> - translate("Duration"); ?> + translate("Duration"); ?> translate("Bytes"); ?> translate("Status"); ?> translate("Action"); ?> @@ -124,7 +126,7 @@ Jobs per page: printJobLevel($job->level); ?> printDate($job->starttime); ?> printDate($job->endtime); ?> - printJobDuration($job->starttime, $job->endtime); ?> + printJobDuration($job->duration); ?> printBytes($job->jobbytes); ?> printJobStatus($job->jobstatus); ?> diff --git a/module/Job/view/job/job/unsuccessful.phtml b/module/Job/view/job/job/unsuccessful.phtml index 37097c72..0ff591b9 100644 --- a/module/Job/view/job/job/unsuccessful.phtml +++ b/module/Job/view/job/job/unsuccessful.phtml @@ -41,7 +41,8 @@ elseif($order_by == 'StartTime') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; elseif($order_by == 'EndTime') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; - +elseif($order_by == 'duration') + $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; ?>

@@ -104,7 +105,7 @@ Jobs per page: translate("Level"); ?> translate("Start"); ?> translate("End"); ?> - translate("Duration"); ?> + translate("Duration"); ?> translate("Status"); ?> translate("Action"); ?> @@ -121,7 +122,7 @@ Jobs per page: printJobLevel($job->level); ?> printDate($job->starttime); ?> printDate($job->endtime); ?> - printJobDuration($job->starttime, $job->endtime); ?> + printJobDuration($job->duration); ?> printJobStatus($job->jobstatus); ?> diff --git a/module/Job/view/job/job/waiting.phtml b/module/Job/view/job/job/waiting.phtml index 8eb95426..05784f4e 100644 --- a/module/Job/view/job/job/waiting.phtml +++ b/module/Job/view/job/job/waiting.phtml @@ -37,12 +37,6 @@ elseif($order_by == 'Type') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; elseif($order_by == 'Level') $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; -elseif($order_by == 'StartTime') - $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; -elseif($order_by == 'EndTime') - $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; -elseif($order_by == 'JobBytes') - $url_order = $order == 'ASC' ? 'DESC' : 'ASC'; ?>