SocialAction & Issues in Activity form

This commit is contained in:
Marc Ducobu
2021-06-03 20:13:49 +02:00
parent 32b3d74a1b
commit 0f635ca51a
5 changed files with 94 additions and 23 deletions

View File

@@ -50,7 +50,7 @@ class ActivityController extends AbstractController
protected AuthorizationHelper $authorizationHelper;
protected LoggerInterface $logger;
protected SerializerInterface $serializer;
public function __construct(
@@ -191,6 +191,7 @@ class ActivityController extends AbstractController
'center' => $entity->getCenter(),
'role' => new Role('CHILL_ACTIVITY_CREATE'),
'activityType' => $entity->getType(),
'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@@ -210,7 +211,7 @@ class ActivityController extends AbstractController
}
$activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
return $this->render($view, [
'person' => $person,
'accompanyingCourse' => $accompanyingPeriod,
@@ -294,6 +295,7 @@ class ActivityController extends AbstractController
'center' => $entity->getCenter(),
'role' => new Role('CHILL_ACTIVITY_UPDATE'),
'activityType' => $entity->getType(),
'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@@ -324,7 +326,7 @@ class ActivityController extends AbstractController
}
$activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
return $this->render($view, array(
'entity' => $entity,
'edit_form' => $form->createView(),

View File

@@ -9,6 +9,8 @@ use Chill\DocStoreBundle\Form\StoredObjectType;
use Chill\MainBundle\Form\Type\ChillCollectionType;
use Chill\MainBundle\Form\Type\CommentType;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@@ -94,6 +96,42 @@ class ActivityType extends AbstractType
]);
}
/** @var ? \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod */
$accompanyingPeriod = NULL;
if ($options['accompanyingPeriod']) {
$accompanyingPeriod = $options['accompanyingPeriod'];
}
if ($activityType->isVisible('socialIssues') && $accompanyingPeriod) {
$builder->add('socialIssues', EntityType::class, [
'label' => $activityType->getLabel('socialIssues'),
'required' => $activityType->isRequired('socialIssues'),
'class' => SocialIssue::class,
'choice_label' => function (SocialIssue $socialIssue) {
return $this->translatableStringHelper->localize($socialIssue->getTitle());
},
'multiple' => true,
'choices' => $accompanyingPeriod->getSocialIssues(),
]);
}
if($accompanyingPeriod) {
dump($accompanyingPeriod->getSocialActions()->toArray());
}
if ($activityType->isVisible('socialActions') && $accompanyingPeriod) {
$builder->add('socialActions', EntityType::class, [
'label' => $activityType->getLabel('socialActions'),
'required' => $activityType->isRequired('socialActions'),
'class' => SocialAction::class,
'choice_label' => function (SocialAction $socialAction) {
return $this->translatableStringHelper->localize($socialAction->getTitle());
},
'multiple' => true,
'choices' => $accompanyingPeriod->getSocialActions(),
]);
}
if ($activityType->isVisible('date')) {
$builder->add('date', ChillDateType::class, [
'label' => $activityType->getLabel('date'),
@@ -313,10 +351,11 @@ class ActivityType extends AbstractType
]);
$resolver
->setRequired(['center', 'role', 'activityType'])
->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod'])
->setAllowedTypes('center', ['null', 'Chill\MainBundle\Entity\Center'])
->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role')
->setAllowedTypes('activityType', \Chill\ActivityBundle\Entity\ActivityType::class)
->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null'])
;
}

View File

@@ -19,7 +19,13 @@
{{ form_row(edit_form.scope) }}
{% endif %}
.. type
{%- if form.socialActions is defined -%}
{{ form_row(form.socialActions) }}
{% endif %}
{%- if form.socialIssues is defined -%}
{{ form_row(form.socialIssues) }}
{% endif %}
{%- if edit_form.reasons is defined -%}
{{ form_row(edit_form.reasons) }}

View File

@@ -20,9 +20,16 @@
{{ form_row(form.scope) }}
{% endif %}
.. type
{%- if form.socialActions is defined -%}
{{ form_row(form.socialActions) }}
{% endif %}
{%- if form.reasons is defined -%}
{%- if form.socialIssues is defined -%}
{{ form_row(form.socialIssues) }}
{% endif %}
{%- if form.reasons is defined -%}
{{ form_row(form.reasons) }}
{% endif %}