mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
redo bulk assign
This commit is contained in:
parent
81bff2bb76
commit
2646fa5b65
@ -20,7 +20,7 @@ use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
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\HiddenType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||||
use Symfony\Component\Form\FormFactoryInterface;
|
use Symfony\Component\Form\FormFactoryInterface;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
@ -99,22 +99,25 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
|||||||
$paginator->getCurrentPageFirstItemNumber()
|
$paginator->getCurrentPageFirstItemNumber()
|
||||||
);
|
);
|
||||||
|
|
||||||
$assignForm = $this->buildReassignForm($periods);
|
$periodIds = [];
|
||||||
|
|
||||||
|
foreach ($periods as $period) {
|
||||||
|
$periodIds[] = $period->getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
$assignForm = $this->buildReassignForm($periodIds);
|
||||||
|
|
||||||
$assignForm->handleRequest($request);
|
$assignForm->handleRequest($request);
|
||||||
|
|
||||||
if ($assignForm->isSubmitted()) {
|
if ($assignForm->isSubmitted()) {
|
||||||
|
|
||||||
$periods = $assignForm->get('periods')->getData();
|
$assignPeriodIds = json_decode($assignForm->get('periods')->getData(), true);
|
||||||
$userAssign = $assignForm->get('assignUser')->getData();
|
$userAssign = $assignForm->get('assignUser')->getData();
|
||||||
|
|
||||||
dump($periods);
|
foreach($assignPeriodIds as $assignPeriodId) {
|
||||||
dump($userAssign);
|
$assignPeriod = $this->courseRepository->find($assignPeriodId);
|
||||||
|
$assignPeriod->setUser($userAssign);
|
||||||
foreach($periods as $periodId) {
|
$this->em->persist($assignPeriod);
|
||||||
$reassignPeriod = $this->courseRepository->find($periodId);
|
|
||||||
$reassignPeriod->setUser($userAssign);
|
|
||||||
$this->em->persist($reassignPeriod);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
@ -171,17 +174,20 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
|||||||
return $builder->getForm();
|
return $builder->getForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildReassignForm(array $periods): FormInterface
|
private function buildReassignForm(array $periodIds): FormInterface
|
||||||
{
|
{
|
||||||
$defaultData = [];
|
$defaultData = [
|
||||||
|
'user' => null,
|
||||||
|
'periods' => []
|
||||||
|
];
|
||||||
|
|
||||||
|
$periodsJson = json_encode($periodIds);
|
||||||
|
|
||||||
$builder = $this->formFactory->createBuilder(FormType::class, $defaultData, ['csrf_protection' => false, ]);
|
$builder = $this->formFactory->createBuilder(FormType::class, $defaultData, ['csrf_protection' => false, ]);
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('periods', ChoiceType::class, [
|
->add('periods', HiddenType::class, [
|
||||||
'choices' => $periods,
|
'data' => $periodsJson,
|
||||||
'multiple' => true,
|
|
||||||
'expanded' => true
|
|
||||||
])
|
])
|
||||||
->add('assignUser', EntityType::class, [
|
->add('assignUser', EntityType::class, [
|
||||||
'class' => User::class,
|
'class' => User::class,
|
||||||
|
@ -74,24 +74,6 @@
|
|||||||
{{ form_widget(assignForm.assignUser, {'attr': {'class': 'select2'}}) }}
|
{{ form_widget(assignForm.assignUser, {'attr': {'class': 'select2'}}) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="form_periods">
|
|
||||||
<div class="flex-table">
|
|
||||||
{{ dump(assignForm.periods.vars.choices) }}
|
|
||||||
{% for choice in assignForm.periods.vars.choices %}
|
|
||||||
<div class="form_check" style="display:flex; margin-bottom:1rem;">
|
|
||||||
<input id="form_periods_{{ choice.value }}" class="form-check-input" type="checkbox" style="margin-right: 1rem;"
|
|
||||||
name="form[periods][{{ choice.value }}]" value="{{ choice.data.id }}">
|
|
||||||
<label class="form-check-label" for="form_periods_{{ choice.value }}" style="display: block; width: 100%;">
|
|
||||||
{% 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">
|
||||||
@ -100,12 +82,12 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{{ form_end(assignForm) }}
|
{{ form_end(assignForm) }}
|
||||||
{# <div class="flex-table">
|
<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