mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
try to fix [wip]
This commit is contained in:
parent
96e5e4a7b2
commit
afb7d4a160
@ -31,6 +31,7 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use @link{ActivityACLAwareRepositoryInterface::findByAccompanyingPeriod}
|
||||
* @return Activity[]
|
||||
*/
|
||||
public function findByAccompanyingPeriod(AccompanyingPeriod $period, array $scopes, ?bool $allowNullScope = false, ?int $limit = 100, ?int $offset = 0, array $orderBy = ['date' => 'desc']): array
|
||||
|
@ -18,7 +18,7 @@ use Symfony\Component\Validator\Constraint;
|
||||
*/
|
||||
class AccompanyingPeriodValidity extends Constraint
|
||||
{
|
||||
public $messageSocialIssueCannotBeDeleted = 'This social issue cannot be deleted because it is associated with an activity or an action';
|
||||
public $messageSocialIssueCannotBeDeleted = 'The social %name% issue cannot be deleted because it is associated with an activity or an action';
|
||||
|
||||
public function getTargets()
|
||||
{
|
||||
|
@ -12,7 +12,10 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
||||
|
||||
use Chill\ActivityBundle\Repository\ActivityACLAwareRepository;
|
||||
use Chill\ActivityBundle\Repository\ActivityRepository;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
@ -21,11 +24,14 @@ use function in_array;
|
||||
|
||||
class AccompanyingPeriodValidityValidator extends ConstraintValidator
|
||||
{
|
||||
private ActivityACLAwareRepository $activityRepository;
|
||||
private ActivityRepository $activityRepository;
|
||||
|
||||
public function __construct(ActivityACLAwareRepository $activityRepository)
|
||||
private SocialIssueRender $socialIssueRender;
|
||||
|
||||
public function __construct(ActivityRepository $activityRepository, SocialIssueRender $socialIssueRender)
|
||||
{
|
||||
$this->activityRepository = $activityRepository;
|
||||
$this->socialIssueRender = $socialIssueRender;
|
||||
}
|
||||
|
||||
public function validate($period, Constraint $constraint)
|
||||
@ -40,22 +46,34 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator
|
||||
|
||||
$socialIssues = [];
|
||||
|
||||
$activities = $this->activityRepository->findByAccompanyingPeriod($period, 'SEE');
|
||||
$activities = $this->activityRepository->findBy(['accompanyingPeriod' => $period]);
|
||||
|
||||
foreach ($activities as $activity) {
|
||||
$socialIssues = $activity->getSocialIssues()->getValues();
|
||||
$socialIssues = $activity->getSocialIssues()->toArray();
|
||||
}
|
||||
|
||||
foreach ($period->getWorks() as $work) {
|
||||
$socialIssues[] = $work->getSocialAction()->getIssue();
|
||||
}
|
||||
|
||||
$socialIssuesByKey = [];
|
||||
foreach ($socialIssues as $si) {
|
||||
if (!in_array($si, $period->getSocialIssues()->getValues(), true)) {
|
||||
$socialIssuesByKey[$si->getId()] = $si;
|
||||
}
|
||||
|
||||
$periodIssuesKeys = $period->getSocialIssues()->map(function (SocialIssue $si) { return $si->getId();})
|
||||
->toArray();
|
||||
|
||||
dump($socialIssuesByKey);
|
||||
dump($periodIssuesKeys);
|
||||
|
||||
foreach ($socialIssuesByKey as $key => $si) {
|
||||
if (!in_array($key, $periodIssuesKeys)) {
|
||||
$this->context
|
||||
->buildViolation(
|
||||
$constraint->messageSocialIssueCannotBeDeleted
|
||||
)
|
||||
->setParameter('%name%', $this->socialIssueRender->renderString($si, []))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +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
|
||||
The social %name% issue cannot be deleted because it is associated with an activity or an action: 'La problématique sociale "%name%" ne peut pas être supprimée car elle est associée à une activité ou une action'
|
||||
|
Loading…
x
Reference in New Issue
Block a user