Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration formulaire d'ajout / modification des événements #1005

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
421 changes: 421 additions & 0 deletions app/Resources/views/admin/event/form.html.twig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/Resources/views/admin/event/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h2>Liste des événements</h2>

<div class="ui menu">
<a href="/pages/administration/index.php?page=forum_gestion&amp;action=ajouter" class="item">
<a href="{{ path('admin_event_new') }}" class="item">
<div data-tooltip="Ajouter un forum" data-position="bottom left">
<i class="icon plus square"></i>
Ajouter
Expand Down Expand Up @@ -43,7 +43,7 @@
<td>{{ event.date_fin_appel_conferencier|date("d/m/Y H:i:s") }}</td>
<td>{{ event.date_fin_vente|date("d/m/Y H:i:s") }}</td>
<td style="text-align: right" nowrap="nowrap">
<a href="/pages/administration/index.php?page=forum_gestion&amp;action=modifier&amp;id={{ event.id }}"
<a href="{{ path('admin_event_edit', {'id': event.id}) }}"
data-tooltip="Modifier le forum {{ event.titre }}"
data-position="left center"
class="compact ui icon button"
Expand Down
13 changes: 13 additions & 0 deletions app/config/routing/admin_event.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ admin_event_delete:
id: \d+
token: '[a-zA-Z0-9_-]+'

admin_event_new:
path: /new
defaults:
_controller: AppBundle\Controller\Admin\Event\AddEditEventAction
id: null

admin_event_edit:
path: /edit/{id}
defaults:
_controller: AppBundle\Controller\Admin\Event\AddEditEventAction
requirements:
id: \d+

admin_event_room:
path: /room
defaults: {_controller: AppBundle\Controller\Admin\Event\RoomAction}
Expand Down
5 changes: 5 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ services:
factory: ["@ting", get]
arguments: [AppBundle\Event\Model\Repository\EventRepository]

AppBundle\Event\Model\Repository\EventCouponRepository:
class: AppBundle\Event\Model\Repository\EventCouponRepository
factory: ["@ting", get]
arguments: [AppBundle\Event\Model\Repository\EventCouponRepository]

AppBundle\Event\Model\Repository\EventStatsRepository:
autowire: true

Expand Down
208 changes: 0 additions & 208 deletions htdocs/pages/administration/forum_gestion.php

This file was deleted.

18 changes: 0 additions & 18 deletions htdocs/templates/administration/forum_gestion.html

This file was deleted.

103 changes: 103 additions & 0 deletions sources/AppBundle/Controller/Admin/Event/AddEditEventAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace AppBundle\Controller\Admin\Event;

use AppBundle\Event\Form\EventType;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventCouponRepository;
use AppBundle\Event\Model\Repository\EventRepository;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;

class AddEditEventAction
{
/**
* @var FormFactoryInterface
*/
private $formFactory;
/**
* @var Environment
*/
private $twig;
/**
* @var EventRepository
*/
private $eventRepository;
/**
* @var FlashBagInterface
*/
private $flashBag;
/**
* @var UrlGeneratorInterface
*/
private $urlGenerator;
/**
* @var EventCouponRepository
*/
private $couponRepository;

public function __construct(
FormFactoryInterface $formFactory,
Environment $twig,
EventRepository $eventRepository,
EventCouponRepository $couponRepository,
FlashBagInterface $flashBag,
UrlGeneratorInterface $urlGenerator
) {
$this->formFactory = $formFactory;
$this->twig = $twig;
$this->eventRepository = $eventRepository;
$this->flashBag = $flashBag;
$this->urlGenerator = $urlGenerator;
$this->couponRepository = $couponRepository;
}

public function __invoke(Request $request, $id)
{
$event = new Event();
$couponTxt = null;
$action = 'ajouté';
if ($id !== null) {
$event = $this->eventRepository->get($id);
if ($event === null) {
$this->flashBag->add('error', 'Evénement introuvable');
return new RedirectResponse($this->urlGenerator->generate('admin_event_list'));
}
$coupons = $this->couponRepository->couponsListForEvent($event);
$couponTxt = [];
foreach ($coupons as $coupon) {
if ($coupon->getText() === null || empty($coupon->getText()) === true) {
continue;
}
$couponTxt[] = $coupon->getText();
}
$couponTxt = implode(',', $couponTxt);
$action = 'modifié';
}

$form = $this->formFactory->create(EventType::class, $event);
$form->get('coupons')->setData($couponTxt);
// $form->get('cFP')->setData($event->getCFP());

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
dump($form->get('cFP')->getData(), $event);
// $event->setCFP($form->get('cFP')->getData());

$this->eventRepository->save($event);

$couponsPost = explode(',', $form->get('coupons')->getData());
$couponsPost = array_map('trim', $couponsPost);
$this->couponRepository->changeCouponForEvent($couponsPost, $event);

$this->flashBag->add('notice', 'Evénement ' . $action);
return new RedirectResponse($this->urlGenerator->generate('admin_event_list'));
}
return new Response($this->twig->render('admin/event/form.html.twig', ['form' => $form->createView()]));
}
}
Loading