try to fix [wip]

This commit is contained in:
2021-12-06 15:37:20 +01:00
parent 96e5e4a7b2
commit afb7d4a160
4 changed files with 26 additions and 7 deletions

View File

@@ -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()
{

View File

@@ -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();
}
}