diff --git a/config/merged/etat-instance.config.php b/config/merged/etat-instance.config.php index b45e0cd9b464f1b5f34d1c5201a81f64be12bdc9..40146420164fc4c82dd849f559f197a7708c4971 100644 --- a/config/merged/etat-instance.config.php +++ b/config/merged/etat-instance.config.php @@ -2,6 +2,9 @@ namespace UnicaenEtat; +use UnicaenEtat\Controller\EtatInstanceController; +use UnicaenEtat\Controller\EtatInstanceControllerFactory; +use UnicaenEtat\Provider\Privilege\EtatPrivileges; use UnicaenEtat\Service\EtatInstance\EtatInstanceService; use UnicaenEtat\Service\EtatInstance\EtatInstanceServiceFactory; use UnicaenEtat\View\Helper\EtatInstanceViewHelper; @@ -13,12 +16,57 @@ return [ 'bjyauthorize' => [ 'guards' => [ PrivilegeController::class => [ + [ + 'controller' => EtatInstanceController::class, + 'action' => [ + 'index', + ], + 'privileges' => [ + EtatPrivileges::ETAT_INDEX, + ], + ], + [ + 'controller' => EtatInstanceController::class, + 'action' => [ + 'supprimer', + ], + 'privileges' => [ + EtatPrivileges::ETAT_DETRUIRE, + ], + ], ], ], ], - 'router' => [ + 'router' => [ 'routes' => [ + 'unicaen-etat' => [ + 'child_routes' => [ + 'etat-instance' => [ + 'type' => Literal::class, + 'options' => [ + 'route' => '/etat-instance', + 'defaults' => [ + 'controller' => EtatInstanceController::class, + 'action' => 'index', + ], + ], + 'may_terminate' => true, + 'child_routes' => [ + 'supprimer' => [ + 'type' => Literal::class, + 'options' => [ + 'route' => '/supprimer/:instance', + 'defaults' => [ + 'controller' => EtatInstanceController::class, + 'action' => 'supprimer', + ], + ], + ], + ], + ], + ], + ], ], ], @@ -28,7 +76,9 @@ return [ ], ], 'controllers' => [ - 'factories' => [], + 'factories' => [ + EtatInstanceController::class => EtatInstanceControllerFactory::class, + ], ], 'form_elements' => [ 'factories' => [], diff --git a/src/UnicaenEtat/Controller/EtatInstanceController.php b/src/UnicaenEtat/Controller/EtatInstanceController.php new file mode 100644 index 0000000000000000000000000000000000000000..a37414f3a88798afa5e96005cf07ea81f80504ab --- /dev/null +++ b/src/UnicaenEtat/Controller/EtatInstanceController.php @@ -0,0 +1,45 @@ +<?php + +namespace UnicaenEtat\Controller; + +use Laminas\Http\Request; +use Laminas\Mvc\Controller\AbstractActionController; +use Laminas\View\Model\ViewModel; +use UnicaenEtat\Service\EtatInstance\EtatInstanceServiceAwareTrait; + +class EtatInstanceController extends AbstractActionController { + use EtatInstanceServiceAwareTrait; + + public function indexAction() : ViewModel + { + $instances = $this->getEtatInstanceService()->getEtatsInstances(); + + return new ViewModel([ + 'instances' => $instances, + ]); + } + + public function supprimerAction() + { + $etat = $this->getEtatInstanceService()->getResquestedEtatInstance($this); + + /** @var Request $request */ + $request = $this->getRequest(); + if ($request->isPost()) { + $data = $request->getPost(); + if ($data["reponse"] === "oui") $this->getEtatInstanceService()->delete($etat); + exit(); + } + + $vm = new ViewModel(); + if ($etat !== null) { + $vm->setTemplate('unicaen-etat/default/confirmation'); + $vm->setVariables([ + 'title' => "Suppression de l'instance d'état " . $etat->getId(), + 'text' => "La suppression est définitive êtes-vous sûr·e de vouloir continuer ?", + 'action' => $this->url()->fromRoute('unicaen-etat/etat-instance/supprimer', ["instance" => $etat->getId()], [], true), + ]); + } + return $vm; + } +} \ No newline at end of file diff --git a/src/UnicaenEtat/Controller/EtatInstanceControllerFactory.php b/src/UnicaenEtat/Controller/EtatInstanceControllerFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..b1bb6bb32813a8d260eb105d75ab099fc6c742f0 --- /dev/null +++ b/src/UnicaenEtat/Controller/EtatInstanceControllerFactory.php @@ -0,0 +1,27 @@ +<?php + +namespace UnicaenEtat\Controller; + +use Interop\Container\ContainerInterface; +use UnicaenEtat\Service\EtatInstance\EtatInstanceService; + +class EtatInstanceControllerFactory { + + /** + * @param ContainerInterface $container + * @return EtatInstanceController + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function __invoke(ContainerInterface $container) : EtatInstanceController + { + /** + * @var EtatInstanceService $instanceService + */ + $instanceService = $container->get(EtatInstanceService::class); + + $controller = new EtatInstanceController(); + $controller->setEtatInstanceService($instanceService); + return $controller; + } +} \ No newline at end of file diff --git a/view/unicaen-etat/etat-instance/index.phtml b/view/unicaen-etat/etat-instance/index.phtml new file mode 100644 index 0000000000000000000000000000000000000000..855e8b84e25f8372e9f7cba44edc15555dd239d2 --- /dev/null +++ b/view/unicaen-etat/etat-instance/index.phtml @@ -0,0 +1,85 @@ +<?php + +/** + * @see \UnicaenEtat\Controller\EtatCategorieController::indexAction() + * @var EtatInstance[] $instances + */ + +use UnicaenEtat\Entity\Db\EtatInstance; + +$this->headTitle("Catégories d'état"); + +?> +<div class="row"> + <div class="col-md-8"> + <h1 class="page-header"> + Instances d'état + <span class="badge"><?php echo count($instances); ?></span> + </h1> +<!-- --><?php ///** @see \UnicaenEtat\Controller\EtatCategorieController::ajouterAction() */ ?> +<!-- <a href="--><?php //echo $this->url('unicaen-etat/etat-instance/ajouter', [], [], true); ?><!--"--> +<!-- class="btn btn-primary action ajax-modal" data-event="modification">--> +<!-- <span class="icon ajouter"></span>--> +<!-- Ajouter une catégorie d'état--> +<!-- </a>--> + </div> + <div class="pull-right"> + + <?php /** @see \UnicaenEtat\Controller\EtatTypeController::indexAction() */ ?> + <a href="<?php echo $this->url('unicaen-etat/etat-type', [], [], true); ?>" + class="btn btn-primary action"> + <span class="icon acceder"></span> + Accéder aux types + </a> + <br/> + <a href="<?php echo $this->url('unicaen-etat/etat-categorie', [], [], true); ?>" + class="btn btn-primary action "> + <span class="icon acceder"></span> + Accéder aux catégories + </a> + </div> +</div> + +<span class="todo"> filtre</span> <br><br> + +<table class="table table-condensed table-hover"> + <thead> + <tr> + <th> Badge</th> + <th> Catégorie </th> + <th> Type </th> + <th> Date </th> + <th> Utilisateur </th> + <th> Action </th> + </tr> + </thead> + <tbody> + <?php foreach ($instances as $instance) : ?> + <tr> + <td> <?php echo $this->etattype($instance->getType()); ?> </td> + <td> <?php echo ($instance->getType()->getCategorie())?$instance->getType()->getCategorie()->getCode():"Sans catégorie"; ?> </td> + <td> <?php echo $instance->getType()->getCode(); ?> </td> + <td> <?php echo $instance->getHistoCreation()->format('d/m/Y à H:i'); ?> </td> + <td> <?php echo $instance->getHistoCreateur()->getDisplayName() ?> </td> + <td> + <span class="icon editer"></span> + <a href="<?php echo $this->url(); ?>" + class="ajax-modal" data-event="modification" + > + <span class="icon detruire text-danger"></span></a> + </td> + + </tr> + <?php endforeach; ?> + </tbody> +</table> + + +<script> + $(function() { + $("body").on("modification", function (event) { + event.div.modal('hide'); + window.location.reload(); + }); + }); +</script> \ No newline at end of file diff --git a/view/unicaen-etat/etat-type/index.phtml b/view/unicaen-etat/etat-type/index.phtml index f265a014abeeb97814eb75c78db04fc9b228189f..828ae510414d507f6b23aab336cdb6264ef4bcde 100644 --- a/view/unicaen-etat/etat-type/index.phtml +++ b/view/unicaen-etat/etat-type/index.phtml @@ -31,10 +31,10 @@ $this->headTitle("Types d'état") Accéder aux catégories </a> <br/> - <a href="<?php echo $this->url('unicaen-etat/etat-type/ajouter', [], [], true); ?>" - class="btn btn-primary action disabled"> + <a href="<?php echo $this->url('unicaen-etat/etat-instance', [], [], true); ?>" + class="btn btn-primary action"> <span class="icon acceder"></span> - Accéder aux instances TODO + Accéder aux instances </a> </div>