Skip to content
Snippets Groups Projects
Select Git revision
  • 7eed13702767a9930cb6360701bbee7d0a300028
  • master default protected
  • release-1.3.10
  • popover-bootstrap-3.4
  • zf-3.x
  • 3.0.9
  • 3.0.8
  • 1.3.10
  • 3.0.7
  • 3.0.6
  • 3.0.5
  • 3.0.4
  • 3.0.3
  • 3.0.2
  • 3.0.1
  • 3.0.0
  • 1.3.9
  • 1.3.8
  • 1.3.7
  • 1.3.6
  • 1.3.5
  • 1.3.4
  • 1.3.3
  • 1.3.2
  • 1.3.1
25 results

autoload_classmap.php

Blame
  • Forked from lib / unicaen / auth
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CategorieController.php 3.52 KiB
    <?php
    
    namespace UnicaenParametre\Controller;
    
    use UnicaenParametre\Entity\Db\Categorie;
    use UnicaenParametre\Form\Categorie\CategorieFormAwareTrait;
    use UnicaenParametre\Service\Categorie\CategorieServiceAwareTrait;
    use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;
    use Laminas\Mvc\Controller\AbstractActionController;
    use Laminas\View\Model\ViewModel;
    
    class CategorieController extends AbstractActionController {
        use CategorieServiceAwareTrait;
        use ParametreServiceAwareTrait;
        use CategorieFormAwareTrait;
    
        public function indexAction()
        {
            $categories = $this->getCategorieService()->getCategories();
            $parametres = $this->getParametreService()->getParametres();
            $selection = $this->getCategorieService()->getRequestedCategorie($this);
    
            return new ViewModel([
                'categories' => $categories,
                'parametres' => $parametres,
                'selection' => $selection,
            ]);
        }
    
        public function ajouterAction() {
    
            $categorie = new Categorie();
            $form = $this->getCategorieForm();
            $form->setAttribute('action', $this->url()->fromRoute('parametre/categorie/ajouter', [], [], true));
            $form->bind($categorie);
    
            $request = $this->getRequest();
            if ($request->isPost()) {
                $data = $request->getPost();
                $form->setData($data);
                if ($form->isValid()) {
                    $this->getCategorieService()->create($categorie);
                }
            }
    
            $vm = new ViewModel([
                'title' => "Ajout d'une catégorie de paramètre",
                'form' => $form,
            ]);
            $vm->setTemplate('unicaen-parametre/default/default-form');
            return $vm;
        }
    
        public function modifierAction()
        {
            $categorie = $this->getCategorieService()->getRequestedCategorie($this);
            $form = $this->getCategorieForm();
            $form->setOldCode($categorie->getCode());
            $form->setAttribute('action', $this->url()->fromRoute('parametre/categorie/modifier', ['categorie' => $categorie->getId()], [], true));
            $form->bind($categorie);
    
            $request = $this->getRequest();
            if ($request->isPost()) {
                $data = $request->getPost();
                $form->setData($data);
                if ($form->isValid()) {
                    $this->getCategorieService()->update($categorie);
                }
            }
    
            $vm = new ViewModel([
                'title' => "Modification de la catégorie [".$categorie->getCode()."] ",
                'form' => $form,
            ]);
            $vm->setTemplate('unicaen-parametre/default/default-form');
            return $vm;
        }
    
        public function supprimerAction()
        {
            $categorie = $this->getCategorieService()->getRequestedCategorie($this);
    
            $request = $this->getRequest();
            if ($request->isPost()) {
                $data = $request->getPost();
                if ($data["reponse"] === "oui") $this->getCategorieService()->delete($categorie);
                exit();
            }
    
            $vm = new ViewModel();
            if ($categorie !== null) {
                $vm->setTemplate('unicaen-parametre/default/confirmation');
                $vm->setVariables([
                    'title' => "Suppression de la catégorie de  paramètre [" . $categorie->getCode() . "]",
                    'text' => "La suppression est définitive êtes-vous sûr&middot;e de vouloir continuer ?",
                    'action' => $this->url()->fromRoute('parametre/categorie/supprimer', ["categorie" => $categorie->getId()], [], true),
                ]);
            }
            return $vm;
        }
    
    
    }