Skip to content
Snippets Groups Projects
Select Git revision
  • d3a73ff6e56a6f75482637f3f4924562671a8719
  • master default protected
  • b24
  • ll-workflow
  • alc-scindage-donnees-pj
  • FJ_LL_Tbl_Contrat
  • alc-docker-node
  • ll-apiplatform
  • php84
  • ll-rgpd
  • b23
  • alc-filtre-type-intervenant
  • ll-sans-mdb5
  • formules-ancienne-infra
  • ll-formules
  • alc-intervenant-dmep
  • ll-suppr-v_vol-s
  • b20
  • ll-postgresql
  • b23.0.1
  • b22
  • 24.8
  • 24.7
  • 24.6
  • 24.5
  • 24.4
  • 24.3
  • 24.2
  • 24.1
  • 24.0
  • 23.15
  • 24.0-beta19
  • 24.0-beta18
  • 24.0-beta17
  • 24.0-beta16
  • 24.0-beta15
  • 24.0-beta14
  • 24.0-beta13
  • 23.14
  • 24.0-beta12
  • 24.0-beta11
41 results

StatutService.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    StatutService.php 4.09 KiB
    <?php
    
    namespace Intervenant\Service;
    
    use Application\Service\AbstractEntityService;
    use Intervenant\Entity\Db\Statut;
    use Doctrine\ORM\QueryBuilder;
    use UnicaenApp\Traits\SessionContainerTrait;
    
    /**
     * Description of Statut
     *
     * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
     */
    class StatutService extends AbstractEntityService
    {
        use SessionContainerTrait;
    
        private array $statuts = [];
    
    
        /**
         * retourne la classe des entités
         *
         * @return string
         * @throws RuntimeException
         */
        public function getEntityClass()
        {
            return Statut::class;
        }
    
    
        /**
         * Retourne l'alias d'entité courante
         *
         * @return string
         */
        public function getAlias()
        {
            return 'statut';
        }
    
    
        /**
         * @param string $code
         *
         * @return ?Statut
         */
        public function getByCode(string $code): ?Statut
        {
            return $this->getRepo()->findOneBy(['code' => $code, 'annee' => $this->getServiceContext()->getAnnee()]);
        }
    
    
        /**
         * @return Statut
         */
        public function getAutres()
        {
            return $this->getByCode(Statut::CODE_AUTRES);
        }
    
    
        /**
         * @return Statut[]
         */
        public function getStatuts(): array
        {
            if (empty($this->statuts)) {
                $dql = "SELECT s FROM " . Statut::class . " s WHERE s.annee = :annee AND s.histoDestruction IS NULL ORDER BY s.ordre";
                $query = $this->getEntityManager()->createQuery($dql)->setParameter('annee', $this->getServiceContext()->getAnnee());
    
                $this->statuts = $query->getResult();
            }
    
            return $this->statuts;
        }
    
    
        public function getStatutSelectable(Statut $statut, QueryBuilder $qb = null, $alias = null)
        {
            [$qb, $alias] = $this->initQuery($qb, $alias);
            $qb->andWhere("$alias.dossierSelectionnable = 1");
            $qb->andWhere("$alias.annee = " . $this->getServiceContext()->getAnnee()->getId());
    
            $entities = $qb->getQuery()->execute();
            $qb->addOrderBy("$alias.code");
    
            var_dump($qb->getQuery()->getSql());
    
            $result = [];
            $entityClass = $this->getEntityClass();
            foreach ($entities as $entity) {
                if ($entity instanceof $entityClass) {
                    /**
                     * @var Statut $entity
                     */
                    //Je prends le statut si il n'est pas détruit ou si l'intervenant a ce statut
                    if (is_null($entity->getHistoDestruction()) ||
                        $statut->getCode() == $entity->getCode()) {
                        $result[] = $entity;
                    }
                }
            }
    
            return $result;
        }
    
    
        /**
         * @param QueryBuilder|null $qb
         * @param null $alias
         *
         * @return QueryBuilder
         */
        public function orderBy(QueryBuilder $qb = null, $alias = null)
        {
            [$qb, $alias] = $this->initQuery($qb, $alias);
            $qb->addOrderBy("$alias.ordre");
    
            return $qb;
        }
    
    
        public function fetchMaxOrdre(): int
        {
            $sql = 'SELECT MAX(ordre) max_ordre FROM statut WHERE histo_destruction IS NULL';
    
            return (int)$this->getEntityManager()->getConnection()->fetchOne($sql);
        }
    
    
        /**
         * Retourne une nouvelle entité, initialisée avec les bons paramètres
         *
         */
        public function newEntity(): Statut
        {
            /** @var Statut $entity */
            $statut = parent::newEntity();
    
            $statut->setOrdre($this->fetchMaxOrdre() + 1);
    
            return $statut;
        }
    
    
        public function delete($entity, $softDelete = true)
        {
            $this->getSessionContainer()->offsetUnset('privileges' . $entity->getAnnee()->getId());
    
            return parent::delete($entity, $softDelete); // TODO: Change the autogenerated stub
        }
    
    
        /**
         * @param Statut $entity
         *
         * @return mixed
         */
        public function save($entity)
        {
            if (!$entity->getAnnee()) {
                $entity->setAnnee($this->getServiceContext()->getAnnee());
            }
            $this->getSessionContainer()->offsetUnset('privileges' . $entity->getAnnee()->getId());
    
            return parent::save($entity); // TODO: Change the autogenerated stub
        }
    
    }