weekly quick-entry form (#2793)

This commit is contained in:
Kevin Papst
2021-10-18 11:12:46 +02:00
committed by GitHub
parent 64893e0a95
commit 9ab098af86
105 changed files with 3356 additions and 778 deletions

View File

@@ -0,0 +1,61 @@
<?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 App\Entity\Timesheet as TimesheetEntity;
use App\Validator\Constraints\QuickEntryTimesheet as QuickEntryTimesheetConstraint;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class QuickEntryTimesheetValidator extends ConstraintValidator
{
/**
* @var Constraint[]
*/
private $constraints;
/**
* @param Constraint[] $constraints
*/
public function __construct(iterable $constraints)
{
$this->constraints = $constraints;
}
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof QuickEntryTimesheetConstraint) {
throw new UnexpectedTypeException($constraint, QuickEntryTimesheetConstraint::class);
}
if (!\is_object($value) || !($value instanceof TimesheetEntity)) {
throw new UnexpectedTypeException($value, TimesheetEntity::class);
}
/** @var TimesheetEntity $timesheet */
$timesheet = $value;
if ($timesheet->getId() === null && $timesheet->getDuration(false) === null) {
return;
}
foreach ($this->constraints as $constraint) {
$this->context
->getValidator()
->inContext($this->context)
->atPath('duration')
->validate($timesheet, $constraint, [Constraint::DEFAULT_GROUP]);
}
}
}