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

Merge branch 'main' of https://git.unicaen.fr/lib/unicaen/parametre into HEAD

parents 41cf07ad 6809c5cd
Loading
Loading
Loading
Loading
Loading
+37 −9
Original line number Diff line number Diff line
image: registre.unicaen.fr:5000/unicaen-dev-php7.3-apache
#update-satis:
#  stage: publish
#  script:
#    - curl https://gest.unicaen.fr/packagist/update


---
variables:
  PROXY_UNICAEN: $HTTPS_PROXY


stages:
- publish
  - cleanup-runner
  - tag_this_branch_if_success


cleanup-runner:
  stage: cleanup-runner
  script:
    - docker system prune -af
  

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
  - vendor/
services:
  - docker:dind

update-satis:
  stage: publish
tag_this_branch_if_success:
  stage: tag_this_branch_if_success
  image:
    name: docker:dind
  script:
    - curl https://gest.unicaen.fr/packagist/update
    - echo "Configure PROXY Unicaen" && true
    - export http_proxy=$PROXY_UNICAEN
    - export https_proxy=$PROXY_UNICAEN
    - echo "Installation of packages" && true
    - apk update
    - apk add git
    - apk add php
    - git config --global user.email "gitlab-runner@mail.com"
    - git config --global user.name "Gitlab runner"
    - git clone https://git.unicaen.fr/lib/unicaen/parametre.git
    - cd parametre/ 
    - git tag -n $(git describe --tags --abbrev=0) 
+11 −1
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@ use UnicaenParametre\Form\Parametre\ParametreFormFactory;
use UnicaenParametre\Provider\Privilege\ParametrePrivileges;
use UnicaenParametre\Service\Parametre\ParametreService;
use UnicaenParametre\Service\Parametre\ParametreServiceFactory;
use UnicaenParametre\View\Helper\ParametreValueViewHelper;
use UnicaenParametre\View\Helper\ParametreValueViewHelperFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
@@ -122,6 +124,14 @@ return [
        'factories' => [
            ParametreService::class => ParametreServiceFactory::class,
        ],
    ]
    ],

    'view_helpers' => [
        'factories' => [
            ParametreValueViewHelper::class => ParametreValueViewHelperFactory::class,
        ],
        'aliases' => [
            'parametreValue' => ParametreValueViewHelper::class,
        ],
    ],
];
 No newline at end of file
+17 −0
Original line number Diff line number Diff line
@@ -67,6 +67,23 @@ class ParametreService
        return $result;
    }

    /** @return Parametre[] */
    public function getParametresByCategorieCode(string $categorieCode, string $champ = 'ordre', string $ordre = 'ASC'): array
    {
        $qb = $this->createQueryBuilder()
            ->andWhere('categorie.code = :categorie')
            ->setParameter('categorie', $categorieCode)
            ->orderBy('parametre.' . $champ, $ordre);
        $result = $qb->getQuery()->getResult();

        $dictionnaire = [];
        foreach ($result as $item) {
            $dictionnaire[$item->getCode()] = $item;
        }
        return $dictionnaire;
    }


    public function getParametre(int $id): ?Parametre
    {
        $qb = $this->createQueryBuilder()
+16 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenParametre\View\Helper;

use Laminas\View\Helper\AbstractHelper;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;

class ParametreValueViewHelper extends AbstractHelper
{
    use ParametreServiceAwareTrait;

    public function __invoke(string $categorieCode, string $parametreCode, array $options = []) : string
    {
        return "".$this->getParametreService()->getValeurForParametre($categorieCode, $parametreCode);
    }
}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenParametre\View\Helper;

use Laminas\View\Helper\AbstractHelper;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenParametre\Service\Parametre\ParametreService;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;

class ParametreValueViewHelperFactory
{
    /**
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container): ParametreValueViewHelper
    {
        /** @var ParametreService $parametreService */
        $parametreService = $container->get(ParametreService::class);

        $helper = new ParametreValueViewHelper();
        $helper->setParametreService($parametreService);
        return $helper;
    }
}
 No newline at end of file