Periode.php 2.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

namespace Application\Service;

use Application\Service\AbstractService;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Application\Entity\Db\TypeIntervenant as EntityTypeIntervenant;


/**
 * Description of Periode
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
class Periode extends AbstractService
{

    /**
     * Repository
     *
     * @var Repository
     */
    protected $repo;





    /**
     * Retourne la liste des périodes pour un type d'intervenant donné
     *
     * @param EntityTypeIntervenant $typeIntervenant
     * @param QueryBuilder|null $queryBuilder
     * @return QueryBuilder
     */
    public function finderByTypeIntervenant( EntityTypeIntervenant $typeIntervenant, QueryBuilder $qb=null )
    {
        if (empty($qb)) $qb = $this->getRepo()->createQueryBuilder('p');

        $qb->andWhere('p.typeIntervenant = :type')->setParameter('type', $typeIntervenant);
        return $qb;
    }

45
46
47
48
49
50
51
52
53
54
55
56
57
    /**
     * Retourne la liste des périodes d'enseignement
     *
     * @param QueryBuilder|null $queryBuilder
     * @return QueryBuilder
     */
    public function finderByEnseignement( QueryBuilder $qb=null )
    {
        if (empty($qb)) $qb = $this->getRepo()->createQueryBuilder('p');

        $qb->andWhere('p.enseignement = 1');
        return $qb;
    }
58
59

    /**
60
     * Retourne la liste des périodes
61
     *
62
63
     * @param QueryBuilder|null $queryBuilder
     * @return Application\Entity\Db\Periode[]
64
     */
65
    public function getList( QueryBuilder $qb=null )
66
    {
67
68
69
70
71
72
73
        if (empty($qb)) $qb = $this->getRepo()->createQueryBuilder('p');

        $qb->orderBy('p.ordre');
        $periodes = $qb->getQuery()->execute();
        $result = array();
        foreach( $periodes as $periode ){
            $result[$periode->getId()] = $periode;
74
        }
75
        return $result;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    }

    /**
     *
     * @return EntityRepository
     */
    public function getRepo()
    {
        if( empty($this->repo) ){
            $this->getEntityManager()->getFilters()->enable("historique");
            $this->repo = $this->getEntityManager()->getRepository('Application\Entity\Db\Periode');
        }
        return $this->repo;
    }
}