Skip to content
Snippets Groups Projects
Commit 40774100 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Début de développement des viewhelpers

parent a17e0dad
No related branches found
No related tags found
No related merge requests found
Pipeline #17329 passed
......@@ -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
<?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
<?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;
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
<?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
<?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
<?php
use UnicaenIndicateur\Entity\Db\Indicateur;
/**
* @see \UnicaenIndicateur\View\Helper\IndicateurViewHelper
* @var Indicateur $indicateur
* @var array $data
* @var array $options
*/
?>
<div>
<table
id="indicateur_<?php echo $indicateur->getId(); ?>"
class="datatable table table-condensed table-hover"
>
<?php echo $this->defaultItem($indicateur)->getHeader($data); ?>
<tbody>
<?php $nbLine = count($data[1]); ?>
<?php
for($position = 0 ; $position < count($data[1]) ; $position++) {
echo $this->defaultItem($indicateur)->getItem($data, $position);
}
?>
</tbody>
</table>
</div>
\ No newline at end of file
......@@ -95,8 +95,6 @@ $width = 12 / ((int) ($tableau?$tableau->getNbColumn():1));
<?php endif; ?>
</div>
</div>
<span class="todo">Faire le view helper des données des indicateurs </span>
<?php
$exists = $indicateurService->verifierExistanceMaterializedView($indicateur->getViewId());
if ($exists === true) {
......@@ -106,24 +104,7 @@ $width = 12 / ((int) ($tableau?$tableau->getNbColumn():1));
}
?>
<?php if ($exists) : ?>
<table id="indicateur_<?php echo $indicateur->getId(); ?>" class="datatable">
<thead>
<tr>
<?php foreach ($header as $key ) : ?>
<th> <?php echo $key; ?> </th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($data as $item) : ?>
<tr>
<?php foreach ($item as $i) : ?>
<td> <?php echo $i; ?> </td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo $this->indicateur($indicateur); ?>
<?php else : ?>
Problème détecté sur l'indicateur.
<?php endif; ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment