mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +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\Templating\Entity\UserRender;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
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\HiddenType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -45,7 +47,21 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
|
||||
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->engine = $engine;
|
||||
@ -54,6 +70,8 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
$this->security = $security;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->userRender = $userRender;
|
||||
$this->courseRepository = $courseRepository;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,9 +83,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
|
||||
$periodIds = [];
|
||||
|
||||
$form = $this->buildFilterForm($periodIds);
|
||||
$form = $this->buildFilterForm();
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
@ -83,14 +99,66 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
$paginator->getCurrentPageFirstItemNumber()
|
||||
);
|
||||
|
||||
foreach ($periods as $period) {
|
||||
$periodIds[] = $period->getId();
|
||||
// foreach ($periods as $period) {
|
||||
// $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);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
$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()
|
||||
])
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$assignForm= $this->buildFilterForm($periodIds);
|
||||
|
||||
dump($assignForm->get('periods'));
|
||||
|
||||
return new Response(
|
||||
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
|
||||
'paginator' => $paginator,
|
||||
@ -101,7 +169,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
private function buildFilterForm(array $periodIds): FormInterface
|
||||
private function buildFilterForm(): FormInterface
|
||||
{
|
||||
$data = [
|
||||
'user' => null,
|
||||
@ -119,9 +187,40 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
'multiple' => false,
|
||||
'label' => 'User',
|
||||
'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, [
|
||||
'data' => serialize($periodIds),
|
||||
->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,
|
||||
]);
|
||||
|
||||
return $builder->getForm();
|
||||
|
@ -59,15 +59,37 @@
|
||||
|
||||
{{ form_end(form) }}
|
||||
|
||||
<div>
|
||||
<p>{{ 'Attribute all parcours in this list to the following users,'|trans }}</p>
|
||||
{% 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 %}
|
||||
<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="col-md-6">
|
||||
{{ form_label(assignForm.user ) }}
|
||||
{{ form_widget(assignForm.user, {'attr': {'class': 'select2'}}) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ form_start(assignForm) }}
|
||||
<div class="row filter-box">
|
||||
<div class="col-md-6">
|
||||
{{ form_label(assignForm.user ) }}
|
||||
{{ form_widget(assignForm.user, {'attr': {'class': 'select2'}}) }}
|
||||
<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">
|
||||
<li>
|
||||
@ -77,22 +99,12 @@
|
||||
</li>
|
||||
</ul>
|
||||
{{ form_end(assignForm) }}
|
||||
</div>
|
||||
|
||||
{% 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">
|
||||
{# <div class="flex-table">
|
||||
{% for period in periods %}
|
||||
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
|
||||
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div> #}
|
||||
{% endif %}
|
||||
|
||||
{{ chill_pagination(paginator) }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user