Commit a70ec1af authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Nouveau viewHelper etatlegende

parent d9d065f4
Loading
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ use UnicaenEtat\Provider\Privilege\EtatPrivileges;
use UnicaenEtat\Service\EtatCategorie\EtatCategorieService;
use UnicaenEtat\Service\EtatCategorie\EtatCategorieServiceFactory;
use UnicaenEtat\View\Helper\EtatCategorieViewHelper;
use UnicaenEtat\View\Helper\EtatLegendeViewHelper;
use UnicaenEtat\View\Helper\EtatLegendeViewHelperFactory;
use UnicaenPrivilege\Guard\PrivilegeController;

return [
@@ -161,7 +163,14 @@ return [
    'view_helpers' => [
        'invokables' => [
            'etatcategorie'  => EtatCategorieViewHelper::class,

        ],
        'factories' => [
            EtatLegendeViewHelper::class => EtatLegendeViewHelperFactory::class,
        ],
        'aliases' => [
            'etatlegende' => EtatLegendeViewHelper::class,
        ]
    ],


+10 −0
Original line number Diff line number Diff line
@@ -29,3 +29,13 @@
    text-align: center;
    height: 1.75rem;
}

.cartouche {
    border-radius: 0.25rem;
    border: 1px gray solid;
    padding: 1rem;
}

.element {
    padding: 0.25rem;
}
 No newline at end of file
+3 −1
Original line number Diff line number Diff line
@@ -11,11 +11,13 @@ use Laminas\View\Resolver\TemplatePathStack;
class EtatCategorieViewHelper extends AbstractHelper
{
    /**
     *  -- OPTIONS --
     *  'display-libelle' : affiche de le libelle de la catégorie | default: false;
     * @param EtatCategorie $etatCategorie
     * @param array $options
     * @return string|Partial
     */
    public function __invoke(EtatCategorie $etatCategorie, array $options = [])
    public function __invoke(EtatCategorie $etatCategorie, array $options = []): string|Partial
    {
        /** @var PhpRenderer $view */
        $view = $this->getView();
+38 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenEtat\View\Helper;

use Laminas\View\Renderer\PhpRenderer;
use RuntimeException;
use UnicaenEtat\Entity\Db\EtatCategorie;
use Laminas\View\Helper\AbstractHelper;
use Laminas\View\Helper\Partial;
use Laminas\View\Resolver\TemplatePathStack;
use UnicaenEtat\Service\EtatCategorie\EtatCategorieServiceAwareTrait;

class EtatLegendeViewHelper extends AbstractHelper
{
    use EtatCategorieServiceAwareTrait;

    /**
     * TODO :: par code aussi
     *
     * @param EtatCategorie|string $etatCategorie
     * @param array $options
     * @return string|Partial
     */
    public function __invoke(EtatCategorie|string $etatCategorie, array $options = []): Partial|string
    {
        if (is_string($etatCategorie)) {
            $code = $etatCategorie;
            $etatCategorie = $this->getEtatCategorieService()->getEtatCategorieByCode($code);
            if ($etatCategorie === null) throw new RuntimeException("Aucune catégorie d'état ne correspond au code [".$code."]");
        }

        /** @var PhpRenderer $view */
        $view = $this->getView();
        $view->resolver()->attach(new TemplatePathStack(['script_paths' => [__DIR__ . "/partial"]]));

        return $view->partial('etat-legende', ['etatCategorie' => $etatCategorie, 'options' => $options]);
    }
}
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenEtat\View\Helper;

use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenEtat\Service\EtatCategorie\EtatCategorieService;

class EtatLegendeViewHelperFactory
{

    /**
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container): EtatLegendeViewHelper
    {
        /**
         * @var EtatCategorieService $etatCategorieService
         */
        $etatCategorieService = $container->get(EtatCategorieService::class);

        $helper = new EtatLegendeViewHelper();
        $helper->setEtatCategorieService($etatCategorieService);
        return $helper;
    }
}
 No newline at end of file
Loading