MotifModificationServiceController.php 2.44 KB
Newer Older
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
<?php

namespace Application\Controller;

use Application\Service\Traits\MotifModificationServiceServiceAwareTrait;
use Application\Entity\Db\MotifModificationServiceDu;
use Application\Form\MotifModificationService\Traits\MotifModificationServiceSaisieFormAwareTrait;
use UnicaenApp\View\Model\MessengerViewModel;

class MotifModificationServiceController extends AbstractController
{
    use MotifModificationServiceServiceAwareTrait;
    use MotifModificationServiceSaisieFormAwareTrait;



    public function indexAction()
    {
        $this->em()->getFilters()->enable('historique')->init([
            MotifModificationServiceDu::class,
        ]);

        $motifModificationServices = $this->getServiceMotifModificationService()->getList();

        return compact('motifModificationServices');
    }



    public function saisieAction()
    {
        /* @var $motifModificationService MotifModificationServiceDu */

34
        $motifModificationServiceDu = $this->getEvent()->getParam('motifModificationServiceDu');
35
36
37

        $form = $this->getFormMotifModificationServiceSaisie();
        if (empty($motifModificationServiceDu)) {
38
            $title                      = 'Création d\'un nouveau motif de modification de service dû';
39
40
            $motifModificationServiceDu = $this->getServiceMotifModificationService()->newEntity();
        } else {
41
            $title = 'Édition d\'un motif de modification de service dû';
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        }

        $form->bindRequestSave($motifModificationServiceDu, $this->getRequest(), function (MotifModificationServiceDu $fr) {
            try {
                $this->getServiceMotifModificationService()->save($fr);
                $this->flashMessenger()->addSuccessMessage('Enregistrement effectué');
            } catch (\Exception $e) {
                $this->flashMessenger()->addErrorMessage($this->translate($e));
            }
        });

        return compact('form', 'title');
    }



    public function deleteAction()
    {
60
        $motifModificationServiceDu = $this->getEvent()->getParam('motifModificationServiceDu');
61
62
63
64
65
66
67
68

        try {
            $this->getServiceMotifModificationService()->delete($motifModificationServiceDu);
            $this->flashMessenger()->addSuccessMessage("Motif de Modification de Service supprimé avec succès.");
        } catch (\Exception $e) {
            $this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage());
        }

69
        return new MessengerViewModel();
70
71
    }
}