Skip to content
Snippets Groups Projects
Select Git revision
  • 05ceaa5697ebc632a779b25ee87e31ce2a74d59e
  • master default protected
  • main
  • update_github_actions
  • 144_rocky8_support
  • 195-update-pdk-to-300
  • 144-rocky8
  • add_test_github_test_workflow
  • pdk_2.4.0
  • fix_unclosed_let_block_in_defines_client_spec
  • validation_fixes
  • freeradius_3_0_21_config_updates
  • data_types
  • PrepareBuster
  • travis
  • 4.0.1
  • 4.0.0
  • 3.9.2
  • 3.9.1
  • 3.9.0
  • 3.8.2
  • 3.8.1
  • 3.8.0
  • 3.7.0
  • 3.6.0
  • 3.5.0
  • 3.4.3
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.3.1
35 results

instantiate.pp

Blame
  • 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;
        }
    
    
    }