mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-03 22:47:45 +00:00
FEATURE [activity][filter] filter form created to list activities within the parcours and person context
This commit is contained in:
parent
55a845fcd6
commit
3923a13b30
@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Controller;
|
|||||||
|
|
||||||
use Chill\ActivityBundle\Entity\Activity;
|
use Chill\ActivityBundle\Entity\Activity;
|
||||||
use Chill\ActivityBundle\Entity\ActivityReason;
|
use Chill\ActivityBundle\Entity\ActivityReason;
|
||||||
|
use Chill\ActivityBundle\Form\ActivityFilterType;
|
||||||
use Chill\ActivityBundle\Form\ActivityType;
|
use Chill\ActivityBundle\Form\ActivityType;
|
||||||
use Chill\ActivityBundle\Repository\ActivityACLAwareRepositoryInterface;
|
use Chill\ActivityBundle\Repository\ActivityACLAwareRepositoryInterface;
|
||||||
use Chill\ActivityBundle\Repository\ActivityRepository;
|
use Chill\ActivityBundle\Repository\ActivityRepository;
|
||||||
@ -294,6 +295,10 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||||
|
|
||||||
|
$form = $this->createForm(ActivityFilterType::class);
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($person instanceof Person) {
|
if ($person instanceof Person) {
|
||||||
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $person);
|
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $person);
|
||||||
$activities = $this->activityACLAwareRepository
|
$activities = $this->activityACLAwareRepository
|
||||||
@ -307,6 +312,7 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
$view = 'ChillActivityBundle:Activity:listPerson.html.twig';
|
$view = 'ChillActivityBundle:Activity:listPerson.html.twig';
|
||||||
} elseif ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
} elseif ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $accompanyingPeriod);
|
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $accompanyingPeriod);
|
||||||
|
|
||||||
$activities = $this->activityACLAwareRepository
|
$activities = $this->activityACLAwareRepository
|
||||||
@ -315,9 +321,12 @@ final class ActivityController extends AbstractController
|
|||||||
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
$view,
|
$view,
|
||||||
[
|
[
|
||||||
|
'form' => $form->createView(),
|
||||||
'activities' => $activities,
|
'activities' => $activities,
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'accompanyingCourse' => $accompanyingPeriod,
|
'accompanyingCourse' => $accompanyingPeriod,
|
||||||
|
107
src/Bundle/ChillActivityBundle/Form/ActivityFilterType.php
Normal file
107
src/Bundle/ChillActivityBundle/Form/ActivityFilterType.php
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\ActivityBundle\Form;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\UserJob;
|
||||||
|
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\Form\FormError;
|
||||||
|
use Symfony\Component\Form\FormEvent;
|
||||||
|
use Symfony\Component\Form\FormEvents;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
use Chill\ActivityBundle\Entity\ActivityType;
|
||||||
|
|
||||||
|
class ActivityFilterType extends AbstractType
|
||||||
|
{
|
||||||
|
private TranslatableStringHelperInterface $translatableString;
|
||||||
|
|
||||||
|
protected TranslatorInterface $translator;
|
||||||
|
|
||||||
|
public function __construct(TranslatableStringHelperInterface $translatableString, TranslatorInterface $translator)
|
||||||
|
{
|
||||||
|
$this->translatableString = $translatableString;
|
||||||
|
|
||||||
|
$this->translator = $translator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
|
||||||
|
$builder
|
||||||
|
->add('types', EntityType::class, [
|
||||||
|
'class' => ActivityType::class,
|
||||||
|
'label' => 'Activity type',
|
||||||
|
'multiple' => true,
|
||||||
|
'query_builder' => static function (EntityRepository $er) {
|
||||||
|
$qb = $er->createQueryBuilder('t');
|
||||||
|
$qb->andWhere($qb->expr()->eq('t.active', "'TRUE'"));
|
||||||
|
|
||||||
|
return $qb;
|
||||||
|
},
|
||||||
|
'choice_label' => function (ActivityType $t) {
|
||||||
|
return $this->translatableString->localize($t->getName());
|
||||||
|
},
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->add('jobs', EntityType::class, [
|
||||||
|
'class' => UserJob::class,
|
||||||
|
'label' => 'user job',
|
||||||
|
'multiple' => true,
|
||||||
|
'query_builder' => static function (EntityRepository $er) {
|
||||||
|
$qb = $er->createQueryBuilder('j');
|
||||||
|
$qb->andWhere($qb->expr()->eq('j.active', "'TRUE'"));
|
||||||
|
|
||||||
|
return $qb;
|
||||||
|
},
|
||||||
|
'choice_label' => function (UserJob $j) {
|
||||||
|
return $this->translatableString->localize($j->getLabel());
|
||||||
|
},
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->add('dateFrom', ChillDateType::class, [
|
||||||
|
'label' => 'Activities after this date',
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->add('dateTo', ChillDateType::class, [
|
||||||
|
'label' => 'Activities before this date',
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->add('onlyMe', CheckboxType::class, [
|
||||||
|
'label' => 'My activities only',
|
||||||
|
'required' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
|
||||||
|
|
||||||
|
$form = $event->getForm();
|
||||||
|
$dateFrom = $form->get('dateFrom')->getData();
|
||||||
|
$dateTo = $form->get('dateTo')->getData();
|
||||||
|
|
||||||
|
// check that date_from is before date_to
|
||||||
|
if (
|
||||||
|
(null !== $dateFrom && null !== $dateTo)
|
||||||
|
&& $dateFrom >= $dateTo
|
||||||
|
) {
|
||||||
|
$form->get('dateTo')->addError(new FormError(
|
||||||
|
$this->translator->trans('This date should be after '
|
||||||
|
. 'the date given in "Implied in an activity after '
|
||||||
|
. 'this date" field')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -27,7 +27,48 @@
|
|||||||
{% set accompanying_course_id = accompanyingCourse.id %}
|
{% set accompanying_course_id = accompanyingCourse.id %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<h1>{{ 'Activity list' |trans }}</h1>
|
<h1>{{ 'Activity list'|trans }}</h1>
|
||||||
|
|
||||||
|
{# <div class="col-10">#}
|
||||||
|
|
||||||
|
{{ form_start(form) }}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
{{ form_label(form.types ) }}
|
||||||
|
{{ form_widget(form.types, {'attr': {'class': 'select2'}}) }}
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
{{ form_label(form.jobs) }}
|
||||||
|
{{ form_widget(form.jobs, {'attr': {'class': 'select2'}}) }}
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
{{ form_label(form.dateFrom) }}
|
||||||
|
{{ form_widget(form.dateFrom) }}
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
{{ form_label(form.dateTo) }}
|
||||||
|
{{ form_widget(form.dateTo) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
{{ form_label(form.onlyMe) }}
|
||||||
|
{{ form_widget(form.onlyMe) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<button type="submit" class="btn btn-save change-icon">
|
||||||
|
<i class="fa fa-filter"></i> Filtrer
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{{ form_end(form) }}
|
||||||
|
{# </div>#}
|
||||||
|
|
||||||
{% include 'ChillActivityBundle:Activity:list.html.twig' with {'context': 'accompanyingCourse'} %}
|
{% include 'ChillActivityBundle:Activity:list.html.twig' with {'context': 'accompanyingCourse'} %}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
---
|
---
|
||||||
services:
|
services:
|
||||||
|
Chill\ActivityBundle\Form\ActivityFilterType:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategoryType:
|
Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategoryType:
|
||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
|
@ -284,6 +284,8 @@ Filter acp which has no activity: Filtrer les parcours qui n’ont pas d’activ
|
|||||||
Filtered acp which has no activities: Filtrer les parcours sans activité associée
|
Filtered acp which has no activities: Filtrer les parcours sans activité associée
|
||||||
Group acp by activity number: Grouper les parcours par nombre d’activité
|
Group acp by activity number: Grouper les parcours par nombre d’activité
|
||||||
|
|
||||||
|
My activities only: Mes échanges uniquement
|
||||||
|
|
||||||
#aggregators
|
#aggregators
|
||||||
Activity type: Type d'activité
|
Activity type: Type d'activité
|
||||||
Activity user: Utilisateur lié à l'activité
|
Activity user: Utilisateur lié à l'activité
|
||||||
|
Loading…
x
Reference in New Issue
Block a user