new system-config to prevent overlapping records (#1720)
This commit is contained in:
@@ -30,6 +30,7 @@ class Timesheet extends Constraint
|
||||
public const START_DISALLOWED = 'kimai-timesheet-90';
|
||||
public const PROJECT_NOT_STARTED = 'kimai-timesheet-91';
|
||||
public const PROJECT_ALREADY_ENDED = 'kimai-timesheet-92';
|
||||
public const RECORD_OVERLAPPING = 'kimai-timesheet-93';
|
||||
|
||||
protected static $errorNames = [
|
||||
self::MISSING_BEGIN_ERROR => 'You must submit a begin date.',
|
||||
@@ -44,6 +45,7 @@ class Timesheet extends Constraint
|
||||
self::START_DISALLOWED => 'You are not allowed to start this timesheet record.',
|
||||
self::PROJECT_NOT_STARTED => 'The project has not started at that time.',
|
||||
self::PROJECT_ALREADY_ENDED => 'The project is finished at that time.',
|
||||
self::RECORD_OVERLAPPING => 'You already have an entry for this time.',
|
||||
];
|
||||
|
||||
public $message = 'This timesheet has invalid settings.';
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App\Validator\Constraints;
|
||||
|
||||
use App\Configuration\TimesheetConfiguration;
|
||||
use App\Entity\Timesheet as TimesheetEntity;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Timesheet\TrackingModeService;
|
||||
use App\Validator\Constraints\Timesheet as TimesheetConstraint;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
@@ -33,16 +34,17 @@ class TimesheetValidator extends ConstraintValidator
|
||||
* @var TrackingModeService
|
||||
*/
|
||||
protected $trackingModeService;
|
||||
|
||||
/**
|
||||
* @param AuthorizationCheckerInterface $auth
|
||||
* @param TimesheetConfiguration $configuration
|
||||
* @var TimesheetRepository
|
||||
*/
|
||||
public function __construct(AuthorizationCheckerInterface $auth, TimesheetConfiguration $configuration, TrackingModeService $service)
|
||||
private $repository;
|
||||
|
||||
public function __construct(AuthorizationCheckerInterface $auth, TimesheetConfiguration $configuration, TrackingModeService $service, TimesheetRepository $repository)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->configuration = $configuration;
|
||||
$this->trackingModeService = $service;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +64,38 @@ class TimesheetValidator extends ConstraintValidator
|
||||
$this->validateBeginAndEnd($value, $this->context);
|
||||
$this->validateActivityAndProject($value, $this->context);
|
||||
$this->validatePermissions($value, $this->context);
|
||||
$this->validateActiveLimit($value, $this->context);
|
||||
$this->validateOverlapping($value, $this->context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TimesheetEntity $timesheet
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
protected function validateOverlapping(TimesheetEntity $timesheet, ExecutionContextInterface $context)
|
||||
{
|
||||
if ($this->configuration->isAllowOverlappingRecords()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->repository->hasRecordForTime($timesheet)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context->buildViolation('You already have an entry for this time.')
|
||||
->atPath('begin')
|
||||
->setTranslationDomain('validators')
|
||||
->setCode(TimesheetConstraint::RECORD_OVERLAPPING)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TimesheetEntity $timesheet
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
protected function validateActiveLimit(TimesheetEntity $timesheet, ExecutionContextInterface $context)
|
||||
{
|
||||
// TODO check active entries against hard_limit
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,8 +125,6 @@ class TimesheetValidator extends ConstraintValidator
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO check active entries against hard_limit
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user