first delivery

This commit is contained in:
Alexandre Gain committed 2026-11-07 19:31:49 +01:00
1 parent 793fbc0c91
commit f6684f3b2e
65 files changed
+5828

No files matched your search

@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* Class constraint for any DateRangeInterface (Plan, Task): when both dates are set, endDate must be
* on or after startDate.
*/
class EndDateAfterStartDate extends Constraint
{
public string $message = 'mautic.plan.end_date.before_start_date';
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}
}
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use MauticPlugin\PlanBundle\Entity\DateRangeInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
class EndDateAfterStartDateValidator extends ConstraintValidator
{
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof EndDateAfterStartDate) {
throw new UnexpectedTypeException($constraint, EndDateAfterStartDate::class);
}
if (null === $value) {
return;
}
if (!$value instanceof DateRangeInterface) {
throw new UnexpectedValueException($value, DateRangeInterface::class);
}
$start = $value->getStartDate();
$end = $value->getEndDate();
if (null === $start || null === $end || $end >= $start) {
return;
}
$this->context->buildViolation($constraint->message)
->atPath('endDate')
->addViolation();
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* Class constraint on Task: the parent task must be in the same plan, and must not be the task itself
* or one of its sub-tasks (which would create a loop).
*/
class ValidTaskParent extends Constraint
{
public string $otherPlanMessage = 'mautic.plan.task.parent.other_plan';
public string $loopMessage = 'mautic.plan.task.parent.loop';
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}
}
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use MauticPlugin\PlanBundle\Entity\Task;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
class ValidTaskParentValidator extends ConstraintValidator
{
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof ValidTaskParent) {
throw new UnexpectedTypeException($constraint, ValidTaskParent::class);
}
if (null === $value) {
return;
}
if (!$value instanceof Task) {
throw new UnexpectedValueException($value, Task::class);
}
$parent = $value->getParent();
if (null === $parent) {
return;
}
// The parent's ancestors include the task itself: the task is its own parent or a sub-task's child.
if ($parent->hasAncestorOrSelf($value)) {
$this->context->buildViolation($constraint->loopMessage)
->atPath('parent')
->addViolation();
return;
}
$plan = $value->getPlan();
$parentPlan = $parent->getPlan();
if (null !== $plan && null !== $parentPlan && $plan->getId() !== $parentPlan->getId()) {
$this->context->buildViolation($constraint->otherPlanMessage)
->atPath('parent')
->addViolation();
}
}
}