SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | Méthode côté front en .ts | |
3 | ||
4 | public submitReport = (year: number, month: number, rawData: Object): Promise<void> => { | |
5 | return this.doSave(year, month, rawData, null).combineLatest( | |
6 | this.rest.add('reports/me/' + year + '/' + (month + 1) + '/submit', {}) | |
7 | ).toPromise().then(obs => { | |
8 | this.notif.success('Compte rendu ' + (month + 1) + '/' + year + ' sauvegardé et soumis pour validation.', 'Validation'); | |
9 | }).catch(e => { | |
10 | this.notif.error('Le compte rendu ' + (month + 1) + '/' + year + ' a été refusé.', 'Compte rendu invalide'); | |
11 | }); | |
12 | } | |
13 | ||
14 | public add(entity: string, item: any): Observable<any> { | |
15 | let toAdd = JSON.stringify(item); | |
16 | this.clearCache(entity + '/'); | |
17 | return this.http.post(this.getActionUrl(entity), toAdd, { headers: this.headers }) | |
18 | .map((response: Response) => { | |
19 | if (response.status === 200 || response.status === 201) | |
20 | return response.text; | |
21 | }) | |
22 | .catch(this.handleError); | |
23 | } | |
24 | ||
25 | ||
26 | Méthode POST en .php | |
27 | /** | |
28 | * @Rest\View() | |
29 | * @Rest\Post("/api/leaves/me/submit") | |
30 | * @Rest\Post("/api/leaves/me/submit/") | |
31 | */ | |
32 | public function createAction(Request $request) | |
33 | { | |
34 | $datefrom = new \DateTime($request->get('datefrom')); | |
35 | $dateto = new \DateTime($request->get('dateto')); | |
36 | $nbjour = $request->get('nbjour'); | |
37 | $type = $request->get('type'); | |
38 | ||
39 | //Récupération des infos via Doctrine | |
40 | $user = $this->getUser(); | |
41 | ||
42 | $em = $this->getDoctrine()->getManager(); | |
43 | ||
44 | //ici mettre la logique permettant de vérifier le solde congés user | |
45 | //If $user->getSolde[congestype] > 0 | |
46 | ||
47 | $em->getConnection()->beginTransaction(); | |
48 | ||
49 | try { | |
50 | //Création des nouvelles tables pour l'enregistrement des données dans la base | |
51 | $congesprit = new Entity\CongesPris(); | |
52 | $congestype = new Entity\CongesType(); | |
53 | $congescompteur = new Entity\CongesCompteur(); | |
54 | ||
55 | //Assignation des valeurs des champs de la table en fonction de la demande de congés | |
56 | //Table congesprit | |
57 | $congesprit->setDatedebut($datefrom); | |
58 | $congesprit->setDatefin($dateto); | |
59 | $congesprit->setNbcongesprit($nbjour); | |
60 | $congesprit->setStatut(Entity\CongesPris::STATUS_SUBMITTED); | |
61 | $congesprit->setUser($user); | |
62 | ||
63 | //Table congestype | |
64 | $congestype->setType($type); | |
65 | $congestype->setCongespris($congesprit); | |
66 | $congestype->setCongesCompteur($congescompteur); | |
67 | ||
68 | //Table congescompteur | |
69 | $congescompteur->setUser($user); | |
70 | ||
71 | $em->persist($congesprit); | |
72 | $em->persist($congestype); | |
73 | $em->persist($congescompteur); | |
74 | $em->flush(); | |
75 | ||
76 | $em->getConnection()->commit(); | |
77 | } catch (Exception $e) { | |
78 | $em->getConnection()->rollback(); | |
79 | throw $e; | |
80 | } | |
81 | ||
82 | return new Response('', Response::HTTP_CREATED); | |
83 | } |