added UI configuration for default start-time (#1506)
This commit is contained in:
@@ -14,12 +14,14 @@ use App\Event\SystemConfigurationEvent;
|
||||
use App\Form\Model\Configuration;
|
||||
use App\Form\Model\SystemConfiguration as SystemConfigurationModel;
|
||||
use App\Form\SystemConfigurationForm;
|
||||
use App\Form\Type\DateTimeTextType;
|
||||
use App\Form\Type\LanguageType;
|
||||
use App\Form\Type\RoundingModeType;
|
||||
use App\Form\Type\SkinType;
|
||||
use App\Form\Type\TrackingModeType;
|
||||
use App\Form\Type\WeekDaysType;
|
||||
use App\Repository\ConfigurationRepository;
|
||||
use App\Validator\Constraints\DateTimeFormat;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
@@ -216,6 +218,11 @@ final class SystemConfigurationController extends AbstractController
|
||||
->setName('timesheet.mode')
|
||||
->setType(TrackingModeType::class)
|
||||
->setTranslationDomain('system-configuration'),
|
||||
(new Configuration())
|
||||
->setName('timesheet.default_begin')
|
||||
->setType(DateTimeTextType::class)
|
||||
->setConstraints([new DateTimeFormat(), new NotNull()])
|
||||
->setTranslationDomain('system-configuration'),
|
||||
(new Configuration())
|
||||
->setName('timesheet.rules.allow_future_times')
|
||||
->setType(CheckboxType::class)
|
||||
|
||||
24
src/Form/Type/DateTimeTextType.php
Normal file
24
src/Form/Type/DateTimeTextType.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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\TextType;
|
||||
|
||||
class DateTimeTextType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return TextType::class;
|
||||
}
|
||||
}
|
||||
28
src/Validator/Constraints/DateTimeFormat.php
Normal file
28
src/Validator/Constraints/DateTimeFormat.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
class DateTimeFormat extends Constraint
|
||||
{
|
||||
public const INVALID_FORMAT = 'kimai-datetime-00';
|
||||
|
||||
protected static $errorNames = [
|
||||
self::INVALID_FORMAT => 'The given value is not a valid datetime format.',
|
||||
];
|
||||
|
||||
public $message = 'This datetime format is invalid.';
|
||||
|
||||
public function getTargets()
|
||||
{
|
||||
return self::PROPERTY_CONSTRAINT;
|
||||
}
|
||||
}
|
||||
43
src/Validator/Constraints/DateTimeFormatValidator.php
Normal file
43
src/Validator/Constraints/DateTimeFormatValidator.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
class DateTimeFormatValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* @param string|mixed $value
|
||||
* @param Constraint $constraint
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!($constraint instanceof DateTimeFormat)) {
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\DateTimeFormat');
|
||||
}
|
||||
|
||||
$valid = true;
|
||||
|
||||
try {
|
||||
$test = new \DateTime($value);
|
||||
} catch (\Exception $ex) {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if (false === $valid) {
|
||||
$this->context->buildViolation('The given value is not a valid datetime format.')
|
||||
->setTranslationDomain('validators')
|
||||
->setCode(DateTimeFormat::INVALID_FORMAT)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user