Skip to content
Snippets Groups Projects
Select Git revision
  • 558f2702113046c93b8a7a00e466885e114e3d3b
  • 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

PeriodeService.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PeriodeService.php 4.40 KiB
    <?php
    
    namespace Application\Service;
    
    use Application\Entity\Db\Structure;
    use Application\Entity\Db\Periode;
    
    use Application\Service\Traits\IntervenantServiceAwareTrait;
    use Application\Service\Traits\MiseEnPaiementServiceAwareTrait;
    use Application\Service\Traits\MiseEnPaiementIntervenantStructureServiceAwareTrait;
    use Doctrine\ORM\QueryBuilder;
    
    
    /**
     * Description of Periode
     *
     * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
     */
    class PeriodeService extends AbstractEntityService
    {
        use MiseEnPaiementServiceAwareTrait;
        use IntervenantServiceAwareTrait;
        use MiseEnPaiementIntervenantStructureServiceAwareTrait;
    
        /**
         * Périodes d'enseignement
         *
         * @var Periode[]
         */
        protected $enseignement;
    
        /**
         * @var Periode[]
         */
        private $cache;
    
    
    
        /**
         * retourne la classe des entités
         *
         * @return string
         * @throws RuntimeException
         */
        public function getEntityClass()
        {
            return Periode::class;
        }
    
    
    
        /**
         * Retourne l'alias d'entité courante
         *
         * @return string
         */
        public function getAlias()
        {
            return 'per';
        }
    
    
    
        /**
         *
         * @param string $code
         *
         * @return Periode
         */
        public function getByCode($code)
        {
            if (!isset($this->cache[$code])) {
                $this->cache[$code] = $this->getRepo()->findOneBy(['code' => $code]);
            }
    
            return $this->cache[$code];
        }
    
    
    
        /**
         *
         * @param \DateTime $date
         *
         * @return Periode
         */
        public function getPeriodePaiement(\DateTime $date = null)
        {
            $anneeDateDebut = $this->getServiceContext()->getAnnee()->getDateDebut();
            $aY             = (int)$anneeDateDebut->format('Y');
            $aM             = (int)$anneeDateDebut->format('n');
    
            if (empty($date)) $date = new \DateTime;
            $dY = (int)$date->format('Y');
            $dM = (int)$date->format('n');
    
            $ecartMoisPaiement = ($dY - $aY) * 12 + $dM - $aM;
    
            return $this->getRepo()->findOneBy(['paiement' => true, 'ecartMoisPaiement' => $ecartMoisPaiement]);
        }
    
    
    
        /**
         * Retourne la liste des périodes d'enseignement
         *
         * @param QueryBuilder|null $queryBuilder
         *
         * @return QueryBuilder
         */
        public function finderByEnseignement(QueryBuilder $qb = null, $alias = null)
        {
            list($qb, $alias) = $this->initQuery($qb, $alias);
            $qb->andWhere("$alias.enseignement = 1");
    
            return $qb;
        }
    
    
    
        public function finderByMiseEnPaiement(Structure $structure = null, QueryBuilder $qb = null, $alias = null)
        {
            $serviceMIS = $this->getServiceMiseEnPaiementIntervenantStructure();
    
            list($qb, $alias) = $this->initQuery($qb, $alias);
    
            $this->join($serviceMIS, $qb, 'miseEnPaiementIntervenantStructure', false, $alias);
            $serviceMIS->join($this->getServiceMiseEnPaiement(), $qb, 'miseEnPaiement');
            $serviceMIS->join($this->getServiceIntervenant(), $qb, 'intervenant', false);
    
            if ($structure) {
                $serviceMIS->finderByStructure($structure, $qb);
            }
    
            $this->getServiceIntervenant()->finderByAnnee($this->getServiceContext()->getAnnee(), $qb);
    
            return $qb;
        }
    
    
    
        /**
         *
         * @param QueryBuilder|null $qb
         * @param string|null       $alias
         */
        public function orderBy(QueryBuilder $qb = null, $alias = null)
        {
            list($qb, $alias) = $this->initQuery($qb, $alias);
    
            $qb->orderBy("$alias.ordre");
    
            return $qb;
        }
    
    
    
        /**
         * Retourne la liste des périodes d'enseignement
         *
         * @return Periode[]
         */
        public function getEnseignement()
        {
            if (!$this->enseignement) {
                $this->enseignement = $this->getList($this->finderByEnseignement());
            }
    
            return $this->enseignement;
        }
    
    
    
        /**
         * Retourne le semestre 1
         *
         * @return Periode
         */
        public function getSemestre1()
        {
            return $this->getRepo()->findOneBy(['code' => Periode::SEMESTRE_1]);
        }
    
    
    
        /**
         * Retourne le semestre 2
         *
         * @return Periode
         */
        public function getSemestre2()
        {
            return $this->getRepo()->findOneBy(['code' => Periode::SEMESTRE_2]);
        }
    
    
    
        /**
         * Retourne le paiement tardif
         *
         * @return Periode
         */
        public function getPaiementTardif()
        {
            return $this->getRepo()->findOneBy(['code' => Periode::PAIEMENT_TARDIF]);
        }
    }