Using date and interval filters
This commit is contained in:
parent
e38f7d106e
commit
af9bb9691a
|
@ -6,6 +6,7 @@ namespace JeroenED\Framework;
|
||||||
|
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use Twig\Loader\FilesystemLoader;
|
use Twig\Loader\FilesystemLoader;
|
||||||
|
use Twig\TwigFilter;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
class Twig
|
class Twig
|
||||||
|
@ -19,6 +20,7 @@ class Twig
|
||||||
$this->environment = new Environment($loader);
|
$this->environment = new Environment($loader);
|
||||||
$this->kernel = $kernel;
|
$this->kernel = $kernel;
|
||||||
$this->addFunctions();
|
$this->addFunctions();
|
||||||
|
$this->addFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render(string $template, array $vars = []): string
|
public function render(string $template, array $vars = []): string
|
||||||
|
@ -32,6 +34,28 @@ class Twig
|
||||||
return $this->kernel->getRouter()->getUrlForRoute($route);
|
return $this->kernel->getRouter()->getUrlForRoute($route);
|
||||||
});
|
});
|
||||||
$this->environment->addFunction($path);
|
$this->environment->addFunction($path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addFilters() {
|
||||||
|
$secondsToInterval = new TwigFilter('interval', function(int $time) {
|
||||||
|
$days = floor($time / (60 * 60 * 24));
|
||||||
|
$time -= $days * (60 * 60 * 24);
|
||||||
|
|
||||||
|
$hours = floor($time / (60 * 60));
|
||||||
|
$time -= $hours * (60 * 60);
|
||||||
|
|
||||||
|
$minutes = floor($time / 60);
|
||||||
|
$time -= $minutes * 60;
|
||||||
|
|
||||||
|
$seconds = floor($time);
|
||||||
|
$time -= $seconds;
|
||||||
|
|
||||||
|
return "{$days}d {$hours}h {$minutes}m {$seconds}s";
|
||||||
|
});
|
||||||
|
$this->environment->addFilter($secondsToInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -20,8 +20,8 @@
|
||||||
<tr{% if(job.norun == true) %} class="norun"{% endif %}>
|
<tr{% if(job.norun == true) %} class="norun"{% endif %}>
|
||||||
<td>{{ job.name }}</td>
|
<td>{{ job.name }}</td>
|
||||||
<td>{{ job.data.host }}</td>
|
<td>{{ job.data.host }}</td>
|
||||||
<td>{{ job.delay }}</td>
|
<td>{{ job.delay | interval }}</td>
|
||||||
<td>{{ job.nextrun }}</td>
|
<td>{{ job.nextrun | date("d/m/Y H:i:s") }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="#" data-id="{{ job.id }}" class="runcron btn btn-default"><span class="glyphicon glyphicon-play"><span></a>
|
<a href="#" data-id="{{ job.id }}" class="runcron btn btn-default"><span class="glyphicon glyphicon-play"><span></a>
|
||||||
<a href="runs.php?jobID={{ job.id }}" class="btn btn-default"><span class="glyphicon glyphicon-align-justify"></span></a>
|
<a href="runs.php?jobID={{ job.id }}" class="btn btn-default"><span class="glyphicon glyphicon-align-justify"></span></a>
|
||||||
|
|
Loading…
Reference in New Issue