UtilisateurRepository.php 3.51 KB
Newer Older
1 2 3 4
<?php

namespace PotageBundle\Repository;

Mat's avatar
Mat committed
5 6
use PotageBundle\Entity\Utilisateur;

7 8 9 10 11 12 13 14
/**
 * UtilisateurRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class UtilisateurRepository extends \Doctrine\ORM\EntityRepository
{
Mat's avatar
Mat committed
15 16
    
    /**
Mat's avatar
Mat committed
17 18 19 20
     * @param $paginate
     * @param $start
     * @param null $column
     * @param null $order
Mat's avatar
Mat committed
21 22
     * @return array
     */
Mat's avatar
Mat committed
23
    public function findAllForAPIReadPaginate($paginate, $start, $column = null, $order = null)
Mat's avatar
Mat committed
24 25
    {
        $qb = $this->createQueryBuilder('u')
Mat's avatar
Mat committed
26 27 28 29 30
            ->setMaxResults($paginate)
            ->setFirstResult(($start - 1) * $paginate);
        if ($column !== null) {
            $qb ->orderBy(sprintf('u.%s', $column), $order);
        }
Mat's avatar
Mat committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
        return $qb->getQuery()->getResult();
    }
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForRead($id)
    {
        $qb = $this->createQueryBuilder('u')
            ->where('u.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForUpdate($id)
    {
        $qb = $this->createQueryBuilder('u')
            ->where('u.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForDelete($id)
    {
        $qb = $this->createQueryBuilder('u')
            ->where('u.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
    
Mat's avatar
Mat committed
73 74 75 76 77 78 79 80 81 82 83 84
    /**
     * @return mixed
     * @throws \Doctrine\ORM\NoResultException
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function countRowsForAPI()
    {
        $qb = $this->createQueryBuilder('u')
            ->select('count(u.id)');
        
        return $qb->getQuery()->getSingleScalarResult();
    }
Mat's avatar
Mat committed
85
    
Mat's avatar
Mat committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    /**
     * Champs de recherche
     * @param $string
     * @return Utilisateur[]
     */
    public function findRowsByString($string)
    {
        return $this->getEntityManager()
            ->createQuery(
                'SELECT u
                FROM PotageBundle\Entity\Utilisateur u
                WHERE u.nom LIKE :string
                OR u.prenom LIKE :string
                OR u.email LIKE :string ')
            ->setParameter(':string', '%'.$string.'%')
            ->getResult();
    }
103 104 105 106 107 108 109 110 111 112 113
    
    /**
     * Les groupes d'un utilisateur
     * @param $id
     * @return array
     */
    public function findAllGroups($id)
    {
        $qb = $this->createQueryBuilder('u')
            ->join('u.groupes', 'g')
            ->join('g.depot', 'd')
Mat's avatar
Mat committed
114
            ->select('g.id', 'g.nom', 'd.jourPanier', 'd.heurePanier', 'd.localisation adresseDepot', 'd.responsable responsableDepot')
115 116 117 118 119
            ->where('u.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getResult();
    }
    
120
    /**
Mat's avatar
Mat committed
121
     * Tous les utilisateurs d'un groupe
122 123 124 125 126 127 128 129 130 131 132 133
     * @param int $id_group
     * @return array
     */
    public function findAllByGroup($id_group)
    {
        $qb = $this->createQueryBuilder('u')
            ->join('u.groupes', 'g')
            ->where('g.id = :id')
            ->setParameter(':id', $id_group);
        return $qb->getQuery()->getResult();
    }
    
134
}