* replaced durationForEntry with duration filter * fixed duration problem - fixes #137
This commit is contained in:
@@ -116,7 +116,7 @@ class AppFixtures extends Fixture
|
||||
// no alias to test twig username macro
|
||||
[
|
||||
null, 'Super Administrator', self::USERNAME_SUPER_ADMIN, 'susan_super@example.com', 'ROLE_SUPER_ADMIN',
|
||||
'/bundles/avanzuadmintheme/img/avatar.png', true
|
||||
'/build/images/default_avatar.png', true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace App\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
@@ -60,7 +59,7 @@ class DoctrineCompilerPass implements CompilerPassInterface
|
||||
if ($engine === null) {
|
||||
throw new \Exception(
|
||||
'Could not detect database engine. Please set the environment config DATABASE_ENGINE ' .
|
||||
'to one ' . implode(', ', $this->allowedEngines) . ', e.g. in your .env file: DATABASE_ENGINE=sqlite'
|
||||
'to one of: "' . implode(', ', $this->allowedEngines) . '" in your .env file: DATABASE_ENGINE=sqlite'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -156,20 +156,12 @@ class Timesheet
|
||||
|
||||
/**
|
||||
* Get duration
|
||||
* Do not rely on the results of this method for active records.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getDuration()
|
||||
{
|
||||
if ($this->begin === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($this->end === null) {
|
||||
$current = new \DateTime();
|
||||
return $current->getTimestamp() - $this->begin->getTimestamp();
|
||||
}
|
||||
|
||||
return $this->duration;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ class Extensions extends \Twig_Extension
|
||||
{
|
||||
return [
|
||||
new TwigFilter('duration', [$this, 'duration']),
|
||||
new TwigFilter('durationForEntry', [$this, 'durationForEntry']),
|
||||
new TwigFilter('money', [$this, 'money']),
|
||||
new TwigFilter('currency', [$this, 'currency']),
|
||||
new TwigFilter('country', [$this, 'country']),
|
||||
@@ -63,27 +62,22 @@ class Extensions extends \Twig_Extension
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted duration for a Timesheet entry.
|
||||
*
|
||||
* @param Timesheet $entry
|
||||
* @param bool $includeSeconds
|
||||
* @return string
|
||||
*/
|
||||
public function durationForEntry(Timesheet $entry, $includeSeconds = false)
|
||||
{
|
||||
return $this->duration($entry->getDuration(), $includeSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms seconds into a duration string.
|
||||
*
|
||||
* @param $seconds
|
||||
* @param int|Timesheet $duration
|
||||
* @param bool $includeSeconds
|
||||
* @return string
|
||||
*/
|
||||
public function duration($seconds, $includeSeconds = false)
|
||||
public function duration($duration, $includeSeconds = false)
|
||||
{
|
||||
$seconds = $duration;
|
||||
if ($duration instanceof Timesheet) {
|
||||
$seconds = $duration->getDuration();
|
||||
if ($duration->getEnd() === null) {
|
||||
$seconds = time() - $duration->getBegin()->getTimestamp();
|
||||
}
|
||||
}
|
||||
return $this->durationFormatter->format($seconds, $includeSeconds) . ' h';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user