diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 13109cc98..095577194 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -27,6 +27,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOverlap; use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicateCheck; +use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\AccompanyingPeriodValidity; use Chill\ThirdPartyBundle\Entity\ThirdParty; use DateTime; use DateTimeImmutable; @@ -58,6 +59,8 @@ use const SORT_REGULAR; * "this.isConfidential and this.getUser === NULL", * message="If the accompanying course is confirmed and confidential, a referrer must remain assigned." * ) + * + * @AccompanyingPeriodValidity(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED}) */ class AccompanyingPeriod implements GroupSequenceProviderInterface, diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidity.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidity.php new file mode 100644 index 000000000..a423a20c8 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidity.php @@ -0,0 +1,27 @@ +activityRepository = $activityRepository; + } + + public function validate($period, Constraint $constraint) + { + + if (!$constraint instanceof AccompanyingPeriodValidity) { + throw new UnexpectedTypeException($constraint, AccompanyingPeriodValidity::class); + } + + if (!$period instanceof AccompanyingPeriod) { + throw new UnexpectedValueException($period, AccompanyingPeriod::class); + } + + dump($period); + + $socialIssues = []; + + $activities = $this->activityRepository->findByAccompanyingPeriod($period, 'SEE'); + dump($activities); + foreach ($activities as $activity) { + $socialIssues[] = $activity->getSocialIssues(); + } + + foreach ($period->getWorks() as $work) { + $socialIssues[] = $work->getSocialIssues(); + } + dump($socialIssues); + + foreach ($period->getSocialIssues() as $si) { + dump($si); + if (!in_array($si, $socialIssues)) { + $this->context + ->buildViolation( + $constraint->messageSocialIssueCannotBeDeleted + ) + ->addViolation(); + } + } + + } +} diff --git a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml index c733a935c..c1dda8bf9 100644 --- a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml @@ -46,3 +46,4 @@ household_membership: '{{ name }} is already associated to this accompanying course.': '{{ name }} est déjà associé à ce parcours.' A course must contains at least one social issue: 'Un parcours doit être associé à au moins une problématique sociale' A course must be associated to at least one scope: 'Un parcours doit être associé à au moins un service' +This social issue cannot be deleted because it is associated with an activity or an action: La problématique sociale ne peut pas être supprimée car elle est associée à une activité ou une action \ No newline at end of file