Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed Feb 27, 2015
1 parent 0e0293e commit f3d0d42
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 46 deletions.
19 changes: 10 additions & 9 deletions module/Application/src/Application/View/Helper/JobDuration.php
Expand Up @@ -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 = "-";
}
}
}
6 changes: 2 additions & 4 deletions module/Dashboard/view/dashboard/dashboard/index.phtml
Expand Up @@ -86,7 +86,6 @@ $flash->setMessageOpenFormat('
<th><?php echo $this->translate("Type"); ?></th>
<th><?php echo $this->translate("Level"); ?></th>
<th><?php echo $this->translate("Start"); ?></th>
<!-- <th>Duration</th> -->
<th><?php echo $this->translate("Status"); ?></th>
<th><?php echo $this->translate("Action"); ?></th>
</tr>
Expand All @@ -101,7 +100,6 @@ $flash->setMessageOpenFormat('
<td><?php echo $this->printJobType($item->type); ?></td>
<td><?php echo $this->printJobLevel($item->level); ?></td>
<td><?php echo $this->printDate($item->starttime); ?></td>
<!-- <td><?php echo $this->printJobDuration($item->starttime, $item->endtime); ?></td> -->
<td><?php echo $this->printJobStatus($item->jobstatus); ?></td>
<td>

Expand Down Expand Up @@ -265,7 +263,7 @@ $flash->setMessageOpenFormat('
<td><?php echo $this->printJobLevel($jobUnsuccess->level); ?></td>
<td><?php echo $this->printDate($jobUnsuccess->starttime); ?></td>
<td><?php echo $this->printDate($jobUnsuccess->endtime); ?></td>
<td><?php echo $this->printJobDuration($jobUnsuccess->starttime, $jobUnsuccess->endtime); ?></td>
<td><?php echo $this->printJobDuration($jobUnsuccess->duration); ?></td>
<td><?php echo $this->printJobStatus($jobUnsuccess->jobstatus); ?></td>
<td>
<?php if($jobUnsuccess->type == "B") : ?>
Expand Down Expand Up @@ -354,7 +352,7 @@ $flash->setMessageOpenFormat('
<td><?php echo $this->printJobLevel($jobSuccess->level); ?></td>
<td><?php echo $this->printDate($jobSuccess->starttime); ?></td>
<td><?php echo $this->printDate($jobSuccess->endtime); ?></td>
<td><?php echo $this->printJobDuration($jobSuccess->starttime, $jobSuccess->endtime); ?></td>
<td><?php echo $this->printJobDuration($jobSuccess->duration); ?></td>
<td><?php echo $this->printJobStatus($jobSuccess->jobstatus); ?></td>
<td>
<?php if($jobSuccess->type == "B") : ?>
Expand Down
2 changes: 2 additions & 0 deletions module/Job/src/Job/Model/Job.php
Expand Up @@ -56,6 +56,7 @@ class Job
public $reviewed;
public $comment;
public $clientname;
public $duration;

public function exchangeArray($data)
{
Expand All @@ -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;
}

}
Expand Down
78 changes: 66 additions & 12 deletions module/Job/src/Job/Model/JobTable.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"),
Expand All @@ -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) {
Expand Down
12 changes: 5 additions & 7 deletions module/Job/view/job/job/index.phtml
Expand Up @@ -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';
}

?>

Expand Down Expand Up @@ -87,7 +90,7 @@ Jobs per page:
<th><a href="<?php echo $this->url('job', array('order_by' => 'Level', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Level"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('order_by' => 'StartTime', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Start"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('order_by' => 'EndTime', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("End"); ?></a></th>
<th><?php echo $this->translate("Duration"); ?></th>
<th><a href="<?php echo $this->url('job', array('order_by' => 'duration', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Duration"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('order_by' => 'JobStatus', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Status"); ?></a></th>
<th><?php echo $this->translate("Action"); ?></th>

Expand All @@ -104,12 +107,7 @@ Jobs per page:
<td><?php echo $this->printJobLevel($job->level); ?></td>
<td><?php echo $this->printDate($job->starttime); ?></td>
<td><?php echo $this->printDate($job->endtime); ?></td>
<?php if(!empty($job->endtime)) : ?>
<td><?php echo $this->printJobDuration($job->starttime, $job->endtime); ?></td>
<?php endif; ?>
<?php if(empty($job->endtime)) : ?>
<td><?php echo $this->escapeHtml("-"); ?></td>
<?php endif; ?>
<td><?php echo $this->printJobDuration($job->duration); ?></td>
<td><?php echo $this->printJobStatus($job->jobstatus); ?></td>
<td>
<?php if($job->type == "B") : ?>
Expand Down
4 changes: 1 addition & 3 deletions module/Job/view/job/job/running.phtml
Expand Up @@ -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';

?>

Expand Down Expand Up @@ -105,7 +103,7 @@ Jobs per page:
<th><a href="<?php echo $this->url('job', array('action' => 'running', 'order_by' => 'Type', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Type"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('action' => 'running', 'order_by' => 'Level', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Level"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('action' => 'running', 'order_by' => 'StartTime', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Start"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('action' => 'running', 'order_by' => 'JobStatus', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Status"); ?></a></th>
<th><?php echo $this->translate("Status"); ?></th>
<th><?php echo $this->translate("Action"); ?></th>

</tr>
Expand Down
6 changes: 4 additions & 2 deletions module/Job/view/job/job/successful.phtml
Expand Up @@ -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';

?>

Expand Down Expand Up @@ -106,7 +108,7 @@ Jobs per page:
<th><a href="<?php echo $this->url('job', array('action' => 'successful', 'order_by' => 'Level', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Level"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('action' => 'successful', 'order_by' => 'StartTime', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Start"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('action' => 'successful', 'order_by' => 'EndTime', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("End"); ?></a></th>
<th><?php echo $this->translate("Duration"); ?></th>
<th><a href="<?php echo $this->url('job', array('action' => 'successful', 'order_by' => 'duration', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Duration"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('action' => 'successful', 'order_by' => 'JobBytes', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Bytes"); ?></a></th>
<th><?php echo $this->translate("Status"); ?></th>
<th><?php echo $this->translate("Action"); ?></th>
Expand All @@ -124,7 +126,7 @@ Jobs per page:
<td><?php echo $this->printJobLevel($job->level); ?></td>
<td><?php echo $this->printDate($job->starttime); ?></td>
<td><?php echo $this->printDate($job->endtime); ?></td>
<td><?php echo $this->printJobDuration($job->starttime, $job->endtime); ?></td>
<td><?php echo $this->printJobDuration($job->duration); ?></td>
<td><?php echo $this->printBytes($job->jobbytes); ?></td>
<td><?php echo $this->printJobStatus($job->jobstatus); ?></td>
<td>
Expand Down
7 changes: 4 additions & 3 deletions module/Job/view/job/job/unsuccessful.phtml
Expand Up @@ -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';
?>

<h3 class="text-muted"><?php echo $title; ?></h3>
Expand Down Expand Up @@ -104,7 +105,7 @@ Jobs per page:
<th><a href="<?php echo $this->url('job', array('action' => 'unsuccessful', 'order_by' => 'Level', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Level"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('action' => 'unsuccessful', 'order_by' => 'StartTime', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Start"); ?></a></th>
<th><a href="<?php echo $this->url('job', array('action' => 'unsuccessful', 'order_by' => 'EndTime', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("End"); ?></a></th>
<th><?php echo $this->translate("Duration"); ?></th>
<th><a href="<?php echo $this->url('job', array('action' => 'unsuccessful', 'order_by' => 'duration', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Duration"); ?></a></th>
<th><?php echo $this->translate("Status"); ?></th>
<th><?php echo $this->translate("Action"); ?></th>

Expand All @@ -121,7 +122,7 @@ Jobs per page:
<td><?php echo $this->printJobLevel($job->level); ?></td>
<td><?php echo $this->printDate($job->starttime); ?></td>
<td><?php echo $this->printDate($job->endtime); ?></td>
<td><?php echo $this->printJobDuration($job->starttime, $job->endtime); ?></td>
<td><?php echo $this->printJobDuration($job->duration); ?></td>
<td><?php echo $this->printJobStatus($job->jobstatus); ?></td>
<td>

Expand Down
6 changes: 0 additions & 6 deletions module/Job/view/job/job/waiting.phtml
Expand Up @@ -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';

?>

Expand Down

0 comments on commit f3d0d42

Please sign in to comment.