[activity] handle case when there is no action associated to selected

issues
This commit is contained in:
2021-11-29 22:43:14 +01:00
parent 55b9242690
commit 7b0c7988df
4 changed files with 41 additions and 14 deletions

View File

@@ -10,10 +10,12 @@
namespace Chill\ActivityBundle\Validator\Constraints;
use Chill\ActivityBundle\Entity\Activity;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
use function array_merge;
class ActivityValidityValidator extends ConstraintValidator
{
@@ -118,9 +120,19 @@ class ActivityValidityValidator extends ConstraintValidator
}
if ($activity->getActivityType()->getSocialActionsVisible() === 2 && $activity->getSocialActions()->count() === 0) {
$this->context
->buildViolation($constraint->socialActionsMessage)
->addViolation();
// check if a social action may be added
$actions = [];
foreach ($activity->getSocialIssues() as $socialIssue) {
/** @var SocialIssue $socialIssue */
$actions = array_merge($actions, $socialIssue->getRecursiveSocialActions()->toArray());
}
if (0 < count($actions)) {
$this->context
->buildViolation($constraint->socialActionsMessage)
->addViolation();
}
}
}
}