UserAdherentController.php 3.7 KB
Newer Older
1 2 3 4 5 6 7
<?php

namespace App\Controller;

use App\Entity\Adherent;
use App\Entity\Cotisation;
use App\Entity\Geoloc;
8
use App\Entity\TransactionAdherentAdherent;
9
use App\Entity\TransactionAdherentPrestataire;
10 11 12
use App\Entity\Usergroup;
use App\Form\Type\AdherentInfosFormType;
use App\Form\Type\AdhererFormType;
13
use App\Form\Type\TransactionAdherentAdherentFormType;
14
use App\Form\Type\TransactionAdherentPrestataireFormType;
15 16 17 18 19 20 21
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
22
use Symfony\Component\Translation\TranslatorInterface;
23

24
class UserAdherentController extends FluxController
25 26
{
    protected $em;
27
    protected $translator;
28

29
    public function __construct(EntityManagerInterface $em, TranslatorInterface $translator)
30 31
    {
        $this->em = $em;
32
        $this->translator = $translator;
33 34 35 36 37 38 39 40 41 42 43 44
    }

    /**
     * @Route("/adherent/infos", name="adherent_infos")
     * @IsGranted("ROLE_ADHERENT")
     */
    public function adherentInfosAction(Request $request)
    {
        $form = $this->createForm(AdherentInfosFormType::class, $this->getUser()->getAdherent());
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
Julien Jorry committed
45 46 47 48
            $this->em->persist($form->getData());
            $this->em->flush();
            $this->addFlash(
                'success',
49
                $this->translator->trans('Infos du prestataire modifiée !')
Julien Jorry committed
50 51 52 53 54 55 56
            );
            $referer = $request->headers->get('referer');
            if ($referer && !$request->isXmlHttpRequest()) {
                return $this->redirect($referer);
            } elseif (!$request->isXmlHttpRequest()) {
                return new Response('', Response::HTTP_BAD_REQUEST);
            }
57 58
        }

Julien Jorry committed
59
        return $this->redirectToRoute('index');
60 61 62 63 64 65 66 67 68 69
    }

    /**
     * @Route("/adherent/transaction/prestataire/", name="transactionAdherentPrestataire")
     * @IsGranted("ROLE_ADHERENT")
     */
    public function transactionAdherentPrestataireAction(Request $request)
    {
        $entity = new TransactionAdherentPrestataire();
        $entity->setOperateur($this->getUser());
70
        $entity->setExpediteur($this->getUser()->getAdherent());
71
        $form = $this->createForm(TransactionAdherentPrestataireFormType::class, $entity);
72 73 74 75 76 77 78
        return $this->manageFluxForm(
            $request,
            $form,
            $this->getUser()->getAdherent()->getCompte(),
            $this->translator->trans('Transaction à un prestataire bien effectuée !'),
            $this->translator->trans('Transaction à un prestataire')
        );
79
    }
80 81 82 83 84 85 86 87 88 89 90 91 92 93

    /**
     * @Route("/adherent/transaction/adherent/", name="transactionAdherentAdherent")
     * @IsGranted("ROLE_ADHERENT")
     */
    public function transactionAdherentAdherentAction(Request $request)
    {
        if (empty($this->getUser()) || empty($this->getUser()->getAdherent())) {
            return $this->redirectToRoute('index');
        }
        $entity = new TransactionAdherentAdherent();
        $entity->setOperateur($this->getUser());
        $entity->setExpediteur($this->getUser()->getAdherent());
        $form = $this->createForm(TransactionAdherentAdherentFormType::class, $entity);
94 95 96 97 98 99 100
        return $this->manageFluxForm(
            $request,
            $form,
            $this->getUser()->getAdherent()->getCompte(),
            $this->translator->trans('Transaction à un adhérent bien effectuée !'),
            $this->translator->trans('Transaction à un adhérent')
        );
101
    }
102
}