UserAdherentController.php 4.51 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
use App\Entity\AchatMonnaieAdherent;
11 12 13
use App\Entity\Usergroup;
use App\Form\Type\AdherentInfosFormType;
use App\Form\Type\AdhererFormType;
14
use App\Form\Type\TransactionAdherentAdherentFormType;
15
use App\Form\Type\TransactionAdherentPrestataireFormType;
16
use App\Form\Type\AchatMonnaieAdherentFormType;
17 18 19 20 21 22 23
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;
24
use Symfony\Component\Translation\TranslatorInterface;
25

26
class UserAdherentController extends FluxController
27 28
{
    /**
29 30 31
      * @Route("/adherent/infos", name="adherent_infos")
      * @IsGranted("ROLE_ADHERENT")
      */
32 33 34 35 36 37
    public function adherentInfosAction(Request $request)
    {
        $form = $this->createForm(AdherentInfosFormType::class, $this->getUser()->getAdherent());
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
Julien Jorry committed
38 39 40 41
            $this->em->persist($form->getData());
            $this->em->flush();
            $this->addFlash(
                'success',
42
                $this->translator->trans('Infos du prestataire modifiée !')
Julien Jorry committed
43 44 45 46 47 48 49
            );
            $referer = $request->headers->get('referer');
            if ($referer && !$request->isXmlHttpRequest()) {
                return $this->redirect($referer);
            } elseif (!$request->isXmlHttpRequest()) {
                return new Response('', Response::HTTP_BAD_REQUEST);
            }
50 51
        }

Julien Jorry committed
52
        return $this->redirectToRoute('index');
53 54 55 56 57 58 59 60 61 62
    }

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

    /**
     * @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);
87 88 89 90 91 92 93
        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')
        );
94
    }
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

    /**
     * @Route("/adherent/achat-monnaie/", name="achatMonnaieAdherent")
     * @IsGranted("ROLE_ADHERENT")
     */
    public function achatMonnaieAdherentAction(Request $request)
    {
        if (empty($this->getUser()) || empty($this->getUser()->getAdherent())) {
            return $this->redirectToRoute('index');
        }

        $entity = new AchatMonnaieAdherent();
        $entity->setReference("Achat Monnaie en CB");
        $form = $this->createForm(AchatMonnaieAdherentFormType::class, $entity);

        //TODO custom form handling -> redirect to payzen or other mean of payment
        return $this->redirectToRoute('index');
        
        return $this->manageFluxForm(
            $request,
            $form,
            $this->getUser()->getAdherent()->getCompte(),
            $this->translator->trans('Achat de monnaie locale bien effectuée !'),
            $this->translator->trans('Achat de monnaie locale')
        );
    }
121
}