From 3cd7e01a2cd16225640eff8f5f0f7a1bbd476cd1 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 20 Jan 2021 17:50:50 +0100 Subject: [PATCH] show calculated lockdown date in config screen (#2274) --- .../SystemConfigurationController.php | 28 +++++++++++++++++++ src/Timesheet/LockdownService.php | 9 +++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Controller/SystemConfigurationController.php b/src/Controller/SystemConfigurationController.php index 75150d2f..88f75e5e 100644 --- a/src/Controller/SystemConfigurationController.php +++ b/src/Controller/SystemConfigurationController.php @@ -223,6 +223,31 @@ final class SystemConfigurationController extends AbstractController */ protected function getConfigurationTypes() { + $lockdownStartHelp = null; + $lockdownEndHelp = null; + $lockdownGraceHelp = null; + $dateFormat = 'D, d M Y H:i:s'; + + if ($this->configurations->isTimesheetLockdownActive()) { + try { + if (!empty($this->configurations->getTimesheetLockdownPeriodStart())) { + $lockdownStartHelp = $this->getDateTimeFactory()->createDateTime($this->configurations->getTimesheetLockdownPeriodStart()); + $lockdownStartHelp = $lockdownStartHelp->format($dateFormat); + } + if (!empty($this->configurations->getTimesheetLockdownPeriodEnd())) { + $lockdownEndHelp = $this->getDateTimeFactory()->createDateTime($this->configurations->getTimesheetLockdownPeriodEnd()); + if (!empty($this->configurations->getTimesheetLockdownGracePeriod())) { + $lockdownGraceHelp = clone $lockdownEndHelp; + $lockdownGraceHelp->modify($this->configurations->getTimesheetLockdownGracePeriod()); + $lockdownGraceHelp = $lockdownGraceHelp->format($dateFormat); + } + $lockdownEndHelp = $lockdownEndHelp->format($dateFormat); + } + } catch (\Exception $ex) { + $lockdownStartHelp = 'invalid'; + } + } + return [ (new SystemConfigurationModel()) ->setSection(SystemConfigurationModel::SECTION_TIMESHEET) @@ -246,18 +271,21 @@ final class SystemConfigurationController extends AbstractController ->setTranslationDomain('system-configuration'), (new Configuration()) ->setName('timesheet.rules.lockdown_period_start') + ->setOptions(['help' => $lockdownStartHelp]) ->setType(TextType::class) ->setRequired(false) ->setConstraints([new DateTimeFormat()]) ->setTranslationDomain('system-configuration'), (new Configuration()) ->setName('timesheet.rules.lockdown_period_end') + ->setOptions(['help' => $lockdownEndHelp]) ->setType(TextType::class) ->setRequired(false) ->setConstraints([new DateTimeFormat()]) ->setTranslationDomain('system-configuration'), (new Configuration()) ->setName('timesheet.rules.lockdown_grace_period') + ->setOptions(['help' => $lockdownGraceHelp]) ->setType(TextType::class) ->setRequired(false) ->setConstraints([new DateTimeFormat()]) diff --git a/src/Timesheet/LockdownService.php b/src/Timesheet/LockdownService.php index d18e5081..9c5a1c1d 100644 --- a/src/Timesheet/LockdownService.php +++ b/src/Timesheet/LockdownService.php @@ -54,16 +54,15 @@ final class LockdownService $lockedStart = $this->configuration->getTimesheetLockdownPeriodStart(); $lockedEnd = $this->configuration->getTimesheetLockdownPeriodEnd(); - $gracePeriod = $this->configuration->getTimesheetLockdownGracePeriod(); - if (!empty($gracePeriod)) { - $gracePeriod = $gracePeriod . ' '; - } try { $lockdownStart = new \DateTime($lockedStart, $timesheetStart->getTimezone()); $lockdownEnd = new \DateTime($lockedEnd, $timesheetStart->getTimezone()); - $lockdownGrace = new \DateTime($gracePeriod . $lockdownEnd->format('Y-m-d'), $timesheetStart->getTimezone()); + $lockdownGrace = clone $lockdownEnd; + if (!empty($gracePeriod)) { + $lockdownGrace->modify($gracePeriod); + } } catch (\Exception $ex) { // should not happen, but ... if parsing of datetimes fails: skip validation return true;