Periode.php 4.1 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
use Application\Service\Traits\IntervenantAwareTrait;
use Application\Service\Traits\MiseEnPaiementAwareTrait;
use Application\Service\Traits\MiseEnPaiementIntervenantStructureAwareTrait;
11
12
13
14
15
16
17
18
use Doctrine\ORM\QueryBuilder;


/**
 * Description of Periode
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
19
class Periode extends AbstractEntityService
20
{
21
22
23
24
    use MiseEnPaiementAwareTrait;
    use IntervenantAwareTrait;
    use MiseEnPaiementIntervenantStructureAwareTrait;

25
26
27
    /**
     * Périodes d'enseignement
     *
lecluse's avatar
#3930    
lecluse committed
28
     * @var PeriodeEntity[]
29
30
31
32
33
     */
    protected $enseignement;



34
    /**
35
     * retourne la classe des entités
36
     *
37
38
     * @return string
     * @throws RuntimeException
39
     */
40
41
    public function getEntityClass()
    {
lecluse's avatar
#3930    
lecluse committed
42
        return PeriodeEntity::class;
43
    }
44

lecluse's avatar
#3930    
lecluse committed
45
46


47
    /**
48
     * Retourne l'alias d'entité courante
49
     *
50
     * @return string
51
     */
lecluse's avatar
#3930    
lecluse committed
52
53
    public function getAlias()
    {
54
        return 'per';
55
56
    }

lecluse's avatar
#3930    
lecluse committed
57
58


lecluse's avatar
lecluse committed
59
60
61
    /**
     *
     * @param \DateTime $date
lecluse's avatar
#3930    
lecluse committed
62
     *
lecluse's avatar
lecluse committed
63
64
     * @return PeriodeEntity
     */
lecluse's avatar
#3930    
lecluse committed
65
    public function getPeriodePaiement(\DateTime $date = null)
lecluse's avatar
lecluse committed
66
    {
67
        $anneeDateDebut = $this->getServiceContext()->getAnnee()->getDateDebut();
lecluse's avatar
#3930    
lecluse committed
68
69
        $aY             = (int)$anneeDateDebut->format('Y');
        $aM             = (int)$anneeDateDebut->format('n');
70

lecluse's avatar
lecluse committed
71
        if (empty($date)) $date = new \DateTime;
72
73
74
        $dY = (int)$date->format('Y');
        $dM = (int)$date->format('n');

lecluse's avatar
#3930    
lecluse committed
75
        $ecartMoisPaiement = ($dY - $aY) * 12 + $dM - $aM;
76
77

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

lecluse's avatar
#3930    
lecluse committed
80
81


82
83
84
85
    /**
     * Retourne la liste des périodes d'enseignement
     *
     * @param QueryBuilder|null $queryBuilder
lecluse's avatar
#3930    
lecluse committed
86
     *
87
88
     * @return QueryBuilder
     */
lecluse's avatar
#3930    
lecluse committed
89
    public function finderByEnseignement(QueryBuilder $qb = null, $alias = null)
90
    {
lecluse's avatar
#3930    
lecluse committed
91
        list($qb, $alias) = $this->initQuery($qb, $alias);
92
        $qb->andWhere("$alias.enseignement = 1");
lecluse's avatar
#3930    
lecluse committed
93

94
95
        return $qb;
    }
96

lecluse's avatar
#3930    
lecluse committed
97
98
99


    public function finderByMiseEnPaiement(StructureEntity $structure = null, QueryBuilder $qb = null, $alias = null)
lecluse's avatar
lecluse committed
100
    {
101
        $serviceMIS = $this->getServiceMiseEnPaiementIntervenantStructure();
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
        $this->join($serviceMIS, $qb, 'miseEnPaiementIntervenantStructure', false, $alias);
106
107
        $serviceMIS->join($this->getServiceMiseEnPaiement(), $qb, 'miseEnPaiement');
        $serviceMIS->join($this->getServiceIntervenant(), $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
        }

113
        $this->getServiceIntervenant()->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
}