mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
attempts to submit reassign form
This commit is contained in:
parent
9f064784f2
commit
805b9dc0df
@ -16,10 +16,12 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
|
|||||||
use Chill\MainBundle\Repository\UserRepository;
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
use Chill\MainBundle\Templating\Entity\UserRender;
|
use Chill\MainBundle\Templating\Entity\UserRender;
|
||||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
|
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
|
||||||
|
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
|
||||||
use Symfony\Component\Form\FormFactoryInterface;
|
use Symfony\Component\Form\FormFactoryInterface;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -45,7 +47,21 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
|||||||
|
|
||||||
private UserRepository $userRepository;
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
public function __construct(AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security, UserRender $userRender)
|
private AccompanyingPeriodRepository $courseRepository;
|
||||||
|
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository,
|
||||||
|
UserRepository $userRepository,
|
||||||
|
AccompanyingPeriodRepository $courseRepository,
|
||||||
|
EngineInterface $engine,
|
||||||
|
FormFactoryInterface $formFactory,
|
||||||
|
PaginatorFactory $paginatorFactory,
|
||||||
|
Security $security,
|
||||||
|
UserRender $userRender,
|
||||||
|
EntityManagerInterface $em
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
|
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
|
||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
@ -54,6 +70,8 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
|||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
$this->userRepository = $userRepository;
|
$this->userRepository = $userRepository;
|
||||||
$this->userRender = $userRender;
|
$this->userRender = $userRender;
|
||||||
|
$this->courseRepository = $courseRepository;
|
||||||
|
$this->em = $em;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,9 +83,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
|||||||
throw new AccessDeniedException();
|
throw new AccessDeniedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$periodIds = [];
|
$form = $this->buildFilterForm();
|
||||||
|
|
||||||
$form = $this->buildFilterForm($periodIds);
|
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
@ -83,13 +99,65 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
|||||||
$paginator->getCurrentPageFirstItemNumber()
|
$paginator->getCurrentPageFirstItemNumber()
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($periods as $period) {
|
// foreach ($periods as $period) {
|
||||||
$periodIds[] = $period->getId();
|
// $periodIds[] = $period->getId();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $assignForm= $this->buildReassignForm($periods);
|
||||||
|
$assignData = [];
|
||||||
|
$assignForm = $this->createFormBuilder($assignData)
|
||||||
|
->add('periods', ChoiceType::class, [
|
||||||
|
// 'data' => serialize($periods),
|
||||||
|
'choices' => $periods,
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true
|
||||||
|
])
|
||||||
|
->add('user', EntityType::class, [
|
||||||
|
'class' => User::class,
|
||||||
|
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
|
||||||
|
'choice_label' => function (User $u) {
|
||||||
|
return $this->userRender->renderString($u, []);
|
||||||
|
},
|
||||||
|
'placeholder' => 'Choose a user to reassign to',
|
||||||
|
'multiple' => false,
|
||||||
|
'label' => 'User',
|
||||||
|
'required' => true,
|
||||||
|
])
|
||||||
|
->getForm();
|
||||||
|
|
||||||
|
$assignForm->handleRequest($request);
|
||||||
|
|
||||||
|
if ($assignForm->isSubmitted()) {
|
||||||
|
|
||||||
|
$periods = $assignForm->get('periods')->getData();
|
||||||
|
$userAssign = $assignForm->get('user')->getData();
|
||||||
|
|
||||||
|
foreach($periods as $periodId) {
|
||||||
|
$reassignPeriod = $this->courseRepository->find($periodId);
|
||||||
|
$reassignPeriod->setUser($userAssign);
|
||||||
|
$this->em->persist($reassignPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
$assignForm= $this->buildFilterForm($periodIds);
|
$this->em->flush();
|
||||||
|
|
||||||
dump($assignForm->get('periods'));
|
$remainingPeriods = $this->accompanyingPeriodACLAwareRepository
|
||||||
|
->findByUserOpenedAccompanyingPeriod(
|
||||||
|
$form['user']->getData(),
|
||||||
|
['openingDate' => 'ASC'],
|
||||||
|
$paginator->getItemsPerPage(),
|
||||||
|
$paginator->getCurrentPageFirstItemNumber()
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Response(
|
||||||
|
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
|
||||||
|
'paginator' => $paginator,
|
||||||
|
'periods' => $remainingPeriods,
|
||||||
|
'form' => $form->createView(),
|
||||||
|
'assignForm' => $assignForm->createView()
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
|
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
|
||||||
@ -101,7 +169,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildFilterForm(array $periodIds): FormInterface
|
private function buildFilterForm(): FormInterface
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'user' => null,
|
'user' => null,
|
||||||
@ -119,9 +187,40 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
|||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'label' => 'User',
|
'label' => 'User',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
|
]);
|
||||||
|
// ->add('periods', HiddenType::class, [
|
||||||
|
// 'data' => serialize($periodIds),
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
return $builder->getForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildReassignForm(array $periods): FormInterface
|
||||||
|
{
|
||||||
|
$defaultData = [
|
||||||
|
'user' => [],
|
||||||
|
'periods' => $periods
|
||||||
|
];
|
||||||
|
|
||||||
|
$builder = $this->formFactory->createBuilder(FormType::class, $defaultData, ['csrf_protection' => false, ]);
|
||||||
|
|
||||||
|
$builder
|
||||||
|
->add('periods', ChoiceType::class, [
|
||||||
|
// 'data' => serialize($periods),
|
||||||
|
'choices' => $periods,
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true
|
||||||
])
|
])
|
||||||
->add('periods', HiddenType::class, [
|
->add('user', EntityType::class, [
|
||||||
'data' => serialize($periodIds),
|
'class' => User::class,
|
||||||
|
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
|
||||||
|
'choice_label' => function (User $u) {
|
||||||
|
return $this->userRender->renderString($u, []);
|
||||||
|
},
|
||||||
|
'placeholder' => 'Choose a user to reassign to',
|
||||||
|
'multiple' => false,
|
||||||
|
'label' => 'User',
|
||||||
|
'required' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $builder->getForm();
|
return $builder->getForm();
|
||||||
|
@ -59,9 +59,14 @@
|
|||||||
|
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
|
|
||||||
<div>
|
{% if form.user.vars.value is empty %}
|
||||||
<p>{{ 'Attribute all parcours in this list to the following users,'|trans }}</p>
|
<p class="chill-no-data-statement">{{ 'period_by_user_list.Pick a user'|trans }}</p>
|
||||||
{{ form_start(assignForm) }}
|
{% elseif periods|length == 0 and form.user.vars.value is not empty %}
|
||||||
|
<p class="chill-no-data-statement">{{ 'period_by_user_list.Any course or no authorization to see them'|trans }}</p>
|
||||||
|
{% else %}
|
||||||
|
<h3>{{ 'Attribute parcours in this list to the following user,'|trans }}</h3>
|
||||||
|
<p><span class="badge rounded-pill bg-primary">{{ paginator.totalItems }}</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p>
|
||||||
|
|
||||||
<div class="row filter-box">
|
<div class="row filter-box">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{{ form_label(assignForm.user ) }}
|
{{ form_label(assignForm.user ) }}
|
||||||
@ -69,6 +74,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{ form_start(assignForm) }}
|
||||||
|
<div id="form_periods">
|
||||||
|
<div class="flex-table">
|
||||||
|
{% for choice in assignForm.periods.vars.choices %}
|
||||||
|
<div class="form_check">
|
||||||
|
<input id="form_periods_{{ choice.value }}" class="form-check-input" type="checkbox"
|
||||||
|
name="form[periods][{{ choice.value }}]" value="{{ choice.data.id }}">
|
||||||
|
<label class="form-check-label" for="form_periods_{{ choice.value }}">
|
||||||
|
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': choice.data,
|
||||||
|
'recordAction': m.period_actions(choice.data), 'itemMeta': m.period_meta(choice.data) } %}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% do assignForm.periods.setRendered() %}
|
||||||
|
|
||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li>
|
<li>
|
||||||
<button type="submit" class="btn btn-save change-icon">
|
<button type="submit" class="btn btn-save change-icon">
|
||||||
@ -77,22 +99,12 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{{ form_end(assignForm) }}
|
{{ form_end(assignForm) }}
|
||||||
</div>
|
{# <div class="flex-table">
|
||||||
|
|
||||||
{% if form.user.vars.value is empty %}
|
|
||||||
<p class="chill-no-data-statement">{{ 'period_by_user_list.Pick a user'|trans }}</p>
|
|
||||||
{% elseif periods|length == 0 and form.user.vars.value is not empty %}
|
|
||||||
<p class="chill-no-data-statement">{{ 'period_by_user_list.Any course or no authorization to see them'|trans }}</p>
|
|
||||||
|
|
||||||
{% else %}
|
|
||||||
<p><span class="badge rounded-pill bg-primary">{{ paginator.totalItems }}</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p>
|
|
||||||
|
|
||||||
<div class="flex-table">
|
|
||||||
{% for period in periods %}
|
{% for period in periods %}
|
||||||
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
|
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
|
||||||
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %}
|
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div> #}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{{ chill_pagination(paginator) }}
|
{{ chill_pagination(paginator) }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user