Release 2.7.0 (#4506)
* added api URL for simpler integration * allow to request password change upon next login * make ModifiedAt timesheet independent * improved plugin api * replace kernel calls with AutoconfigureTag and TaggedIterator attributes * new translation keys (e.g. for days) * support setting min and max date on date and daterange pickers
This commit is contained in:
@@ -10,11 +10,13 @@
|
||||
namespace App\Timesheet;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
/**
|
||||
* A calculator is called before a Timesheet entity will be updated.
|
||||
* These classes will normally be used when calculating duration or rates.
|
||||
*/
|
||||
#[AutoconfigureTag]
|
||||
interface CalculatorInterface
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
namespace App\Timesheet\Rounding;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
/**
|
||||
* Apply rounding rules to the given timesheet.
|
||||
*/
|
||||
#[AutoconfigureTag]
|
||||
interface RoundingInterface
|
||||
{
|
||||
public function roundBegin(Timesheet $record, int $minutes): void;
|
||||
|
||||
@@ -12,45 +12,59 @@ namespace App\Timesheet;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Timesheet\Rounding\RoundingInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
|
||||
|
||||
final class RoundingService
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
* @var array<string, array{'days': array<string>, 'begin': int, 'end': int, 'duration': int, 'mode': string}>
|
||||
*/
|
||||
private $rulesCache;
|
||||
private ?array $rulesCache = null;
|
||||
|
||||
/**
|
||||
* @param SystemConfiguration $configuration
|
||||
* @param RoundingInterface[] $roundingModes
|
||||
* @param array $rules
|
||||
* @param array<string, array{'days': array<string>, 'begin': int, 'end': int, 'duration': int, 'mode': string}> $rules
|
||||
*/
|
||||
public function __construct(private SystemConfiguration $configuration, private iterable $roundingModes, private array $rules)
|
||||
public function __construct(
|
||||
private readonly SystemConfiguration $configuration,
|
||||
#[TaggedIterator(RoundingInterface::class)]
|
||||
private readonly iterable $roundingModes,
|
||||
private readonly array $rules
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{'days': array<string>, 'begin': int, 'end': int, 'duration': int, 'mode': string}>
|
||||
*/
|
||||
private function getRoundingRules(): array
|
||||
{
|
||||
if (empty($this->rulesCache)) {
|
||||
$this->rulesCache = $this->rules;
|
||||
if (empty($this->rulesCache) || \array_key_exists('default', $this->rulesCache)) {
|
||||
$this->rulesCache['default']['days'] = $this->configuration->getTimesheetDefaultRoundingDays();
|
||||
$this->rulesCache['default']['begin'] = $this->configuration->getTimesheetDefaultRoundingBegin();
|
||||
$this->rulesCache['default']['end'] = $this->configuration->getTimesheetDefaultRoundingEnd();
|
||||
$this->rulesCache['default']['duration'] = $this->configuration->getTimesheetDefaultRoundingDuration();
|
||||
$this->rulesCache['default']['mode'] = $this->configuration->getTimesheetDefaultRoundingMode();
|
||||
}
|
||||
if ($this->rulesCache === null) {
|
||||
$rules = $this->rules;
|
||||
$rules['default']['days'] = $this->configuration->getTimesheetDefaultRoundingDays();
|
||||
$rules['default']['begin'] = $this->configuration->getTimesheetDefaultRoundingBegin();
|
||||
$rules['default']['end'] = $this->configuration->getTimesheetDefaultRoundingEnd();
|
||||
$rules['default']['duration'] = $this->configuration->getTimesheetDefaultRoundingDuration();
|
||||
$rules['default']['mode'] = $this->configuration->getTimesheetDefaultRoundingMode();
|
||||
|
||||
// see AppExtension, conversion from string to array due to system configuration ont allowing to store arrays
|
||||
foreach ($this->rulesCache as $key => $settings) {
|
||||
// see AppExtension, conversion from string to array due to system configuration not allowing to store arrays
|
||||
foreach ($rules as $key => $settings) {
|
||||
if (\is_array($settings['days'])) {
|
||||
continue;
|
||||
}
|
||||
if ($settings['days'] === '') {
|
||||
$rules[$key]['days'] = [];
|
||||
continue;
|
||||
}
|
||||
$days = explode(',', $settings['days']);
|
||||
$days = array_map('trim', $days);
|
||||
$days = array_map('strtolower', $days);
|
||||
$this->rulesCache[$key]['days'] = $days;
|
||||
$rules[$key]['days'] = $days;
|
||||
}
|
||||
$this->rulesCache = $rules; // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
return $this->rulesCache;
|
||||
return $this->rulesCache; // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
public function roundBegin(Timesheet $record): void
|
||||
@@ -61,7 +75,7 @@ final class RoundingService
|
||||
}
|
||||
$weekday = $record->getBegin()->format('l');
|
||||
|
||||
if (\in_array(strtolower($weekday), $rounding['days'])) {
|
||||
if (\in_array(strtolower($weekday), $rounding['days'], true)) {
|
||||
$rounder = $this->getRoundingMode($rounding['mode']);
|
||||
$rounder->roundBegin($record, $rounding['begin']);
|
||||
}
|
||||
@@ -76,7 +90,7 @@ final class RoundingService
|
||||
}
|
||||
$weekday = $record->getEnd()->format('l');
|
||||
|
||||
if (\in_array(strtolower($weekday), $rounding['days'])) {
|
||||
if (\in_array(strtolower($weekday), $rounding['days'], true)) {
|
||||
$rounder = $this->getRoundingMode($rounding['mode']);
|
||||
$rounder->roundEnd($record, $rounding['end']);
|
||||
}
|
||||
@@ -91,7 +105,7 @@ final class RoundingService
|
||||
}
|
||||
$weekday = $record->getEnd()->format('l');
|
||||
|
||||
if (\in_array(strtolower($weekday), $rounding['days'])) {
|
||||
if (\in_array(strtolower($weekday), $rounding['days'], true)) {
|
||||
$rounder = $this->getRoundingMode($rounding['mode']);
|
||||
$rounder->roundDuration($record, $rounding['duration']);
|
||||
}
|
||||
@@ -110,7 +124,7 @@ final class RoundingService
|
||||
}
|
||||
$weekday = $record->getEnd()->format('l');
|
||||
|
||||
if (\in_array(strtolower($weekday), $rounding['days'])) {
|
||||
if (\in_array(strtolower($weekday), $rounding['days'], true)) {
|
||||
$rounder = $this->getRoundingMode($rounding['mode']);
|
||||
$rounder->roundBegin($record, $rounding['begin']);
|
||||
$rounder->roundEnd($record, $rounding['end']);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Timesheet\TrackingMode;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
@@ -18,6 +19,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
*
|
||||
* @internal do not implement this interface in your bundle, but rather drop a PR to add it to Kimai core
|
||||
*/
|
||||
#[AutoconfigureTag]
|
||||
interface TrackingModeInterface
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App\Timesheet;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Timesheet\TrackingMode\TrackingModeInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
|
||||
final class TrackingModeService
|
||||
@@ -19,7 +20,11 @@ final class TrackingModeService
|
||||
* @param SystemConfiguration $configuration
|
||||
* @param TrackingModeInterface[] $modes
|
||||
*/
|
||||
public function __construct(private SystemConfiguration $configuration, private iterable $modes)
|
||||
public function __construct(
|
||||
private readonly SystemConfiguration $configuration,
|
||||
#[TaggedIterator(TrackingModeInterface::class)]
|
||||
private readonly iterable $modes
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user