Periode.php 4.14 KB
Newer Older
1
2
3
4
<?php

namespace Application\Service;

lecluse's avatar
lecluse committed
5
use Application\Entity\Db\Structure as StructureEntity;
lecluse's avatar
#3930    
lecluse committed
6
use Application\Entity\Db\Periode as PeriodeEntity;
lecluse's avatar
lecluse committed
7

8
9
10
11
12
13
14
15
use Doctrine\ORM\QueryBuilder;


/**
 * Description of Periode
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
16
class Periode extends AbstractEntityService
17
{
18
19
20
    /**
     * Périodes d'enseignement
     *
lecluse's avatar
#3930    
lecluse committed
21
     * @var PeriodeEntity[]
22
23
24
25
26
     */
    protected $enseignement;



27
    /**
28
     * retourne la classe des entités
29
     *
30
31
     * @return string
     * @throws RuntimeException
32
     */
33
34
    public function getEntityClass()
    {
lecluse's avatar
#3930    
lecluse committed
35
        return PeriodeEntity::class;
36
    }
37

lecluse's avatar
#3930    
lecluse committed
38
39


40
    /**
41
     * Retourne l'alias d'entité courante
42
     *
43
     * @return string
44
     */
lecluse's avatar
#3930    
lecluse committed
45
46
    public function getAlias()
    {
47
        return 'per';
48
49
    }

lecluse's avatar
#3930    
lecluse committed
50
51


lecluse's avatar
lecluse committed
52
53
54
    /**
     *
     * @param \DateTime $date
lecluse's avatar
#3930    
lecluse committed
55
     *
lecluse's avatar
lecluse committed
56
57
     * @return PeriodeEntity
     */
lecluse's avatar
#3930    
lecluse committed
58
    public function getPeriodePaiement(\DateTime $date = null)
lecluse's avatar
lecluse committed
59
    {
60
        $anneeDateDebut = $this->getServiceContext()->getAnnee()->getDateDebut();
lecluse's avatar
#3930    
lecluse committed
61
62
        $aY             = (int)$anneeDateDebut->format('Y');
        $aM             = (int)$anneeDateDebut->format('n');
63

lecluse's avatar
lecluse committed
64
        if (empty($date)) $date = new \DateTime;
65
66
67
        $dY = (int)$date->format('Y');
        $dM = (int)$date->format('n');

lecluse's avatar
#3930    
lecluse committed
68
        $ecartMoisPaiement = ($dY - $aY) * 12 + $dM - $aM;
69
70

        return $this->getRepo()->findOneBy(['paiement' => true, 'ecartMoisPaiement' => $ecartMoisPaiement]);
lecluse's avatar
lecluse committed
71
72
    }

lecluse's avatar
#3930    
lecluse committed
73
74


75
76
77
78
    /**
     * Retourne la liste des périodes d'enseignement
     *
     * @param QueryBuilder|null $queryBuilder
lecluse's avatar
#3930    
lecluse committed
79
     *
80
81
     * @return QueryBuilder
     */
lecluse's avatar
#3930    
lecluse committed
82
    public function finderByEnseignement(QueryBuilder $qb = null, $alias = null)
83
    {
lecluse's avatar
#3930    
lecluse committed
84
        list($qb, $alias) = $this->initQuery($qb, $alias);
85
        $qb->andWhere("$alias.enseignement = 1");
lecluse's avatar
#3930    
lecluse committed
86

87
88
        return $qb;
    }
89

lecluse's avatar
#3930    
lecluse committed
90
91
92


    public function finderByMiseEnPaiement(StructureEntity $structure = null, QueryBuilder $qb = null, $alias = null)
lecluse's avatar
lecluse committed
93
94
95
96
97
98
99
    {
        $serviceMIS = $this->getServiceLocator()->get('applicationMiseEnPaiementIntervenantStructure');
        /* @var $serviceMIS MiseEnPaiementIntervenantStructure */

        $serviceMiseEnPaiement = $this->getServiceLocator()->get('applicationMiseEnPaiement');
        /* @var $serviceMiseEnPaiement MiseEnPaiement */

100
101
        $serviceIntervenant = $this->getServiceLocator()->get('applicationIntervenant');
        /* @var $serviceIntervenant Intervenant */
lecluse's avatar
lecluse committed
102

lecluse's avatar
#3930    
lecluse committed
103
        list($qb, $alias) = $this->initQuery($qb, $alias);
lecluse's avatar
lecluse committed
104

lecluse's avatar
#3930    
lecluse committed
105
106
107
        $this->join($serviceMIS, $qb, 'miseEnPaiementIntervenantStructure', false, $alias);
        $serviceMIS->join($serviceMiseEnPaiement, $qb, 'miseEnPaiement');
        $serviceMIS->join($serviceIntervenant, $qb, 'intervenant', false);
lecluse's avatar
lecluse committed
108

lecluse's avatar
#3930    
lecluse committed
109
110
        if ($structure) {
            $serviceMIS->finderByStructure($structure, $qb);
lecluse's avatar
lecluse committed
111
112
        }

lecluse's avatar
#3930    
lecluse committed
113
        $serviceIntervenant->finderByAnnee($this->getServiceContext()->getAnnee(), $qb);
114

lecluse's avatar
lecluse committed
115
116
117
        return $qb;
    }

lecluse's avatar
#3930    
lecluse committed
118
119


120
121
    /**
     *
lecluse's avatar
#3930    
lecluse committed
122
123
     * @param QueryBuilder|null $qb
     * @param string|null       $alias
124
     */
lecluse's avatar
#3930    
lecluse committed
125
    public function orderBy(QueryBuilder $qb = null, $alias = null)
126
    {
lecluse's avatar
#3930    
lecluse committed
127
128
        list($qb, $alias) = $this->initQuery($qb, $alias);

129
        $qb->orderBy("$alias.ordre");
lecluse's avatar
#3930    
lecluse committed
130
131

        return $qb;
132
    }
lecluse's avatar
lecluse committed
133

lecluse's avatar
#3930    
lecluse committed
134
135


136
    /**
lecluse's avatar
#3930    
lecluse committed
137
     * Retourne la liste des périodes d'enseignement
138
     *
lecluse's avatar
#3930    
lecluse committed
139
     * @return PeriodeEntity[]
140
141
142
     */
    public function getEnseignement()
    {
lecluse's avatar
#3930    
lecluse committed
143
144
        if (!$this->enseignement) {
            $this->enseignement = $this->getList($this->finderByEnseignement());
145
        }
lecluse's avatar
#3930    
lecluse committed
146

147
148
149
        return $this->enseignement;
    }

lecluse's avatar
#3930    
lecluse committed
150
151


lecluse's avatar
lecluse committed
152
153
154
    /**
     * Retourne le semestre 1
     *
lecluse's avatar
#3930    
lecluse committed
155
     * @return PeriodeEntity
lecluse's avatar
lecluse committed
156
157
158
     */
    public function getSemestre1()
    {
159
        return $this->getRepo()->findOneBy(['code' => PeriodeEntity::SEMESTRE_1]);
lecluse's avatar
lecluse committed
160
161
    }

lecluse's avatar
#3930    
lecluse committed
162
163


lecluse's avatar
lecluse committed
164
165
166
    /**
     * Retourne le semestre 2
     *
lecluse's avatar
#3930    
lecluse committed
167
     * @return PeriodeEntity
lecluse's avatar
lecluse committed
168
169
170
     */
    public function getSemestre2()
    {
171
        return $this->getRepo()->findOneBy(['code' => PeriodeEntity::SEMESTRE_2]);
lecluse's avatar
lecluse committed
172
    }
lecluse's avatar
#3930    
lecluse committed
173
174
175
176
177
178
179
180
181
182
183
184



    /**
     * Retourne le paiement tardif
     *
     * @return PeriodeEntity
     */
    public function getPaiementTardif()
    {
        return $this->getRepo()->findOneBy(['code' => PeriodeEntity::PAIEMENT_TARDIF]);
    }
185
}