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

Merge branch 'master' of https://git.unicaen.fr/lib/unicaen/indicateur into HEAD

parents 5a44d9f6 8607c4dc
Loading
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@ use UnicaenIndicateur\Form\Indicateur\IndicateurHydratorFactory;
use UnicaenIndicateur\Provider\Privilege\IndicateurPrivileges;
use UnicaenIndicateur\Service\Indicateur\IndicateurService;
use UnicaenIndicateur\Service\Indicateur\IndicateurServiceFactory;
use UnicaenIndicateur\View\Helper\DefaultItemViewHelper;
use UnicaenIndicateur\View\Helper\IndicateurViewHelperFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
use Laminas\Mvc\Console\Router\Simple;
use Laminas\Router\Http\Literal;
@@ -200,6 +202,13 @@ return [
        'factories' => [
            IndicateurHydrator::class => IndicateurHydratorFactory::class,
        ],
    ]

    ],
    'view_helpers' => [
        'invokables' => [
            'defaultItem' => DefaultItemViewHelper::class,
        ],
        'factories' => [
            'indicateur' => IndicateurViewHelperFactory::class,
        ],
    ],
];
 No newline at end of file
+36 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenIndicateur\View\Helper;

use Laminas\View\Helper\AbstractHelper;

class DefaultItemViewHelper extends AbstractHelper implements ItemViewHelperInterface
{
    public function getHeader(array $data) : string
    {
        $headers = $data[0];
        $texte  = "<thead>";
        $texte .= "<tr>";
        foreach ($headers as $header) {
            $texte .= "<th>";
            $texte .= $header;
            $texte .= "</th>";
        }
        $texte .= "</tr>";
        $texte .= "</thead>";
        return $texte;
    }

    public function getItem(array $data, int $position) : string
    {
        $values = $data[1][$position];
        $texte  = "<tr>";
        foreach ($values as $value) {
            $texte .= "<td>";
            $texte .= $value;
            $texte .= "</td>";
        }
        $texte .= "</tr>";
        return $texte;
    }
}
 No newline at end of file
+31 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenIndicateur\View\Helper;

use Laminas\View\Helper\AbstractHelper;
use Laminas\View\Renderer\PhpRenderer;
use Laminas\View\Resolver\TemplatePathStack;
use UnicaenIndicateur\Entity\Db\Indicateur;
use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait;

class IndicateurViewHelper extends AbstractHelper {
    use IndicateurServiceAwareTrait;

    /**
     * @param Indicateur $indicateur
     * @param array $options
     * @return \Laminas\View\Helper\Partial|string
     *
     * La clef $options['ViewHelper'] permet d'indiquer le ViewHelperpour réaliser l'affichage
     * attention celui-ci doit implementer l'interface ItemViewHelperInterface
     */
    public function __invoke(Indicateur $indicateur, array $options = [])
    {
        /** @var PhpRenderer $view */
        $view = $this->getView();
        $view->resolver()->attach(new TemplatePathStack(['script_paths' => [__DIR__ . "/partial"]]));

        $data = $this->getIndicateurService()->getIndicateurData($indicateur);
        return $view->partial('indicateur', ['indicateur' => $indicateur, 'data' => $data, 'options' => $options]);
    }
}
 No newline at end of file
+29 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenIndicateur\View\Helper;

use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenIndicateur\Service\Indicateur\IndicateurService;

class IndicateurViewHelperFactory {

    /**
     * @param ContainerInterface $container
     * @return IndicateurViewHelper
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container) : IndicateurViewHelper
    {
        /**
         * @var IndicateurService $indicateurService
         */
        $indicateurService = $container->get(IndicateurService::class);

        $helper = new IndicateurViewHelper();
        $helper->setIndicateurService($indicateurService);
        return $helper;
    }
}
 No newline at end of file
+12 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenIndicateur\View\Helper;

interface ItemViewHelperInterface
{
    /** Retourne le header du tableau */
    public function getHeader(array $data) : string ;

    /** Retourne la line du tableau associée avec l'item à la position $position */
    public function getItem(array $data, int $position) : string ;
}
 No newline at end of file
Loading