1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
121
<?php
namespace App\Controller;
use App\Entity\Adherent;
use App\Entity\Cotisation;
use App\Entity\Geoloc;
use App\Entity\TransactionAdherentAdherent;
use App\Entity\Usergroup;
use App\Form\Type\AdherentInfosFormType;
use App\Form\Type\AdhererFormType;
use App\Form\Type\TransactionAdherentAdherentFormType;
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;
class UserAdherentController extends AbstractController
{
protected $em;
protected $um;
public function __construct(EntityManagerInterface $em, UserManagerInterface $um)
{
$this->em = $em;
$this->um = $um;
}
/**
* @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()) {
}
return $this->render('adherent/infos.html.twig', array(
'user' => $this->getUser(),
'form' => $form->createView()
));
}
/**
* @Route("/adherent/transaction/prestataire/", name="transactionAdherentPrestataire")
* @IsGranted("ROLE_ADHERENT")
*/
public function transactionAdherentPrestataireAction(Request $request)
{
$entity = new TransactionAdherentPrestataire();
$entity->setOperateur($this->getUser());
$form = $this->createForm(TransactionAdherentPrestataireFormType::class, $entity);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$this->em->persist($data);
$this->em->flush();
$this->addFlash(
'success',
'Transaction bien effectuée !'
);
$referer = $request->headers->get('referer');
if ($referer && !$request->isXmlHttpRequest()) {
return $this->redirect($referer);
} elseif (!$request->isXmlHttpRequest()) {
return new Response('', Response::HTTP_BAD_REQUEST);
}
}
return $this->render('flux/transaction.html.twig', [
'form' => $form->createView(),
'compte' => $this->getUser()->getAdherent()->getCompte(),
'title' => 'Transaction à un prestataire'
]);
}
/**
* @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);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$this->em->persist($data);
$this->em->flush();
$this->addFlash(
'success',
'Transaction bien effectuée !'
);
$referer = $request->headers->get('referer');
if ($referer && !$request->isXmlHttpRequest()) {
return $this->redirect($referer);
} elseif (!$request->isXmlHttpRequest()) {
return new Response('', Response::HTTP_BAD_REQUEST);
}
}
return $this->render('flux/transaction.html.twig', [
'form' => $form->createView(),
'compte' => $this->getUser()->getAdherent()->getCompte(),
'title' => 'Transaction à un adhérent'
]);
}
}