allow to configure timezone for the lockdown period (#2593)

This commit is contained in:
Kevin Papst
2021-06-02 00:05:44 +02:00
committed by GitHub
parent c1eb5ba90a
commit 286b63e2c8
16 changed files with 163 additions and 41 deletions

View File

@@ -208,6 +208,11 @@ class SystemConfiguration implements SystemBundleConfiguration
return (string) $this->find('timesheet.rules.lockdown_grace_period');
}
public function getTimesheetLockdownTimeZone(): ?string
{
return $this->find('timesheet.rules.lockdown_period_timezone');
}
public function isTimesheetLockdownActive(): bool
{
return !empty($this->find('timesheet.rules.lockdown_period_start')) && !empty($this->find('timesheet.rules.lockdown_period_end'));

View File

@@ -22,6 +22,7 @@ use App\Form\Type\LanguageType;
use App\Form\Type\MinuteIncrementType;
use App\Form\Type\RoundingModeType;
use App\Form\Type\SkinType;
use App\Form\Type\TimezoneType;
use App\Form\Type\TrackingModeType;
use App\Form\Type\WeekDaysType;
use App\Form\Type\YesNoType;
@@ -37,7 +38,6 @@ use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@@ -232,18 +232,32 @@ final class SystemConfigurationController extends AbstractController
$dateFormat = 'D, d M Y H:i:s';
if ($this->configurations->isTimesheetLockdownActive()) {
$userTimezone = $this->getDateTimeFactory()->getTimezone();
$timezone = $this->configurations->getTimesheetLockdownTimeZone();
if ($timezone !== null) {
$timezone = new \DateTimeZone($timezone);
}
if ($timezone === null) {
$timezone = $userTimezone;
}
try {
if (!empty($this->configurations->getTimesheetLockdownPeriodStart())) {
$lockdownStartHelp = $this->getDateTimeFactory()->createDateTime($this->configurations->getTimesheetLockdownPeriodStart());
$lockdownStartHelp = new \DateTime($this->configurations->getTimesheetLockdownPeriodStart(), $timezone);
$lockdownStartHelp->setTimezone($userTimezone);
$lockdownStartHelp = $lockdownStartHelp->format($dateFormat);
}
if (!empty($this->configurations->getTimesheetLockdownPeriodEnd())) {
$lockdownEndHelp = $this->getDateTimeFactory()->createDateTime($this->configurations->getTimesheetLockdownPeriodEnd());
$lockdownEndHelp = new \DateTime($this->configurations->getTimesheetLockdownPeriodEnd(), $timezone);
if (!empty($this->configurations->getTimesheetLockdownGracePeriod())) {
$lockdownGraceHelp = clone $lockdownEndHelp;
$lockdownGraceHelp->modify($this->configurations->getTimesheetLockdownGracePeriod());
$lockdownGraceHelp->setTimezone($userTimezone);
$lockdownGraceHelp = $lockdownGraceHelp->format($dateFormat);
}
$lockdownEndHelp->setTimezone($userTimezone);
$lockdownEndHelp = $lockdownEndHelp->format($dateFormat);
}
} catch (\Exception $ex) {
@@ -276,27 +290,6 @@ final class SystemConfigurationController extends AbstractController
->setName('timesheet.rules.allow_overbooking_budget')
->setType(CheckboxType::class)
->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()])
->setTranslationDomain('system-configuration'),
(new Configuration())
->setName('timesheet.active_entries.hard_limit')
->setType(IntegerType::class)
@@ -327,6 +320,36 @@ final class SystemConfigurationController extends AbstractController
new GreaterThanOrEqual(['value' => 0])
]),
]),
(new SystemConfigurationModel())
->setSection(SystemConfigurationModel::SECTION_LOCKDOWN)
->setConfiguration([
(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_period_timezone')
->setType(TimezoneType::class)
->setRequired(false)
->setTranslationDomain('system-configuration'),
(new Configuration())
->setName('timesheet.rules.lockdown_grace_period')
->setOptions(['help' => $lockdownGraceHelp])
->setType(TextType::class)
->setRequired(false)
->setConstraints([new DateTimeFormat()])
->setTranslationDomain('system-configuration'),
]),
(new SystemConfigurationModel())
->setSection(SystemConfigurationModel::SECTION_ROUNDING)
->setConfiguration([

View File

@@ -235,6 +235,9 @@ class Configuration implements ConfigurationInterface
->scalarNode('lockdown_period_end')
->defaultNull()
->end()
->scalarNode('lockdown_period_timezone')
->defaultNull()
->end()
->scalarNode('lockdown_grace_period')
->defaultNull()
->end()

View File

@@ -21,12 +21,12 @@ use App\Form\Type\LanguageType;
use App\Form\Type\ReportType;
use App\Form\Type\SkinType;
use App\Form\Type\ThemeLayoutType;
use App\Form\Type\TimezoneType;
use App\Reporting\ReportingService;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Validator\Constraints\Range;

View File

@@ -11,13 +11,13 @@ namespace App\Form;
use App\Entity\Customer;
use App\Form\Type\MailType;
use App\Form\Type\TimezoneType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

View File

@@ -12,6 +12,7 @@ namespace App\Form\Model;
class SystemConfiguration
{
public const SECTION_ROUNDING = 'rounding';
public const SECTION_LOCKDOWN = 'lockdown_period';
public const SECTION_TIMESHEET = 'timesheet';
public const SECTION_FORM_INVOICE = 'invoice';
public const SECTION_FORM_CUSTOMER = 'form_customer';

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType as BaseTimezoneType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TimezoneType extends AbstractType
{
public function getBlockPrefix()
{
return 'timezone_type';
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'intl' => false,
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return BaseTimezoneType::class;
}
}

View File

@@ -12,11 +12,11 @@ namespace App\Form;
use App\Entity\User;
use App\Form\Type\AvatarType;
use App\Form\Type\LanguageType;
use App\Form\Type\TimezoneType;
use App\Form\Type\YesNoType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

View File

@@ -55,10 +55,17 @@ final class LockdownService
$lockedStart = $this->configuration->getTimesheetLockdownPeriodStart();
$lockedEnd = $this->configuration->getTimesheetLockdownPeriodEnd();
$gracePeriod = $this->configuration->getTimesheetLockdownGracePeriod();
$timezone = $this->configuration->getTimesheetLockdownTimeZone();
if ($timezone === null) {
$timezone = $timesheetStart->getTimezone();
} else {
$timezone = new \DateTimeZone($timezone);
}
try {
$lockdownStart = new \DateTime($lockedStart, $timesheetStart->getTimezone());
$lockdownEnd = new \DateTime($lockedEnd, $timesheetStart->getTimezone());
$lockdownStart = new \DateTime($lockedStart, $timezone);
$lockdownEnd = new \DateTime($lockedEnd, $timezone);
$lockdownGrace = clone $lockdownEnd;
if (!empty($gracePeriod)) {
$lockdownGrace->modify($gracePeriod);