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:
Kevin Papst
2023-12-26 14:49:11 +01:00
committed by GitHub
parent f86eca05ae
commit ad645f5b58
72 changed files with 378 additions and 735 deletions

View File

@@ -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']);