* replaced durationForEntry with duration filter * fixed duration problem - fixes #137
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
avanzu_admin_theme:
|
||||
use_twig: true
|
||||
use_assetic: true
|
||||
use_assetic: false
|
||||
bower_bin: "/usr/local/bin/bower"
|
||||
options:
|
||||
default_avatar: build/images/default_avatar.png
|
||||
|
||||
@@ -3,7 +3,7 @@ kimai:
|
||||
timesheet:
|
||||
|
||||
# Whether we display start and end time columns (false) or durations only (true).
|
||||
# Setting this to true will also change the "edit timesheet" forms, more infos available in the confiugrations docu.
|
||||
# Setting this to true will also change the "edit timesheet" forms, more infos available in the configurations docu.
|
||||
duration_only: false
|
||||
|
||||
# Rounding rules are used to round the begin & end dates and the duration for timesheet records.
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
{% if not duration_only %}
|
||||
<td class="hidden-xs">‐</td>
|
||||
{% endif %}
|
||||
<td><i>{{ entry.duration|duration }}</i></td>
|
||||
<td><i>{{ entry|duration }}</i></td>
|
||||
<td>‐</td>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</div>
|
||||
<h4>
|
||||
{{ entry.activity.name }}
|
||||
<small><i class="fa fa-clock-o"></i> {{ entry|durationForEntry }}</small>
|
||||
<small><i class="fa fa-clock-o"></i> {{ entry|duration }}</small>
|
||||
</h4>
|
||||
<p>{{ entry.activity.project.name }} ({{ entry.activity.project.customer.name }})</p>
|
||||
</a>
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
{% if not duration_only %}
|
||||
<td>‐</td>
|
||||
{% endif %}
|
||||
<td class="hidden-xs"><i>{{ entry.duration|duration }}</i></td>
|
||||
<td class="hidden-xs"><i>{{ entry|duration }}</i></td>
|
||||
<td class="hidden-xs">‐</td>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class ExtensionsTest extends TestCase
|
||||
|
||||
public function testGetFilters()
|
||||
{
|
||||
$filters = ['duration', 'durationForEntry', 'money', 'currency', 'country'];
|
||||
$filters = ['duration', 'money', 'currency', 'country'];
|
||||
$sut = new Extensions('de');
|
||||
$twigFilters = $sut->getFilters();
|
||||
$this->assertCount(count($filters), $twigFilters);
|
||||
@@ -110,8 +110,8 @@ class ExtensionsTest extends TestCase
|
||||
$this->assertEquals('02:37 h', $sut->duration($record->getDuration()));
|
||||
$this->assertEquals('02:37:17 h', $sut->duration($record->getDuration(), true));
|
||||
|
||||
$this->assertEquals('02:37 h', $sut->durationForEntry($record));
|
||||
$this->assertEquals('02:37:17 h', $sut->durationForEntry($record, true));
|
||||
$this->assertEquals('02:37 h', $sut->duration($record));
|
||||
$this->assertEquals('02:37:17 h', $sut->duration($record, true));
|
||||
}
|
||||
|
||||
protected function getTimesheet($seconds)
|
||||
|
||||
Reference in New Issue
Block a user