FluxRepository.php 3.7 KB
Newer Older
1 2 3 4
<?php

namespace App\Repository;

5
use App\Entity\Adherent;
Julien Jorry committed
6
use App\Entity\Comptoir;
7
use App\Entity\Flux;
Julien Jorry committed
8
use App\Entity\Groupe;
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
use App\Entity\Prestataire;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method Flux|null find($id, $lockMode = null, $lockVersion = null)
 * @method Flux|null findOneBy(array $criteria, array $orderBy = null)
 * @method Flux[]    findAll()
 * @method Flux[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class FluxRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, Flux::class);
    }

   /**
    * @param  Prestataire $presta [description]
    * @return Query Returns a query fo finding an array of Flux
    */
    public function getQueryByPrestataire(Prestataire $presta)
    {
        $em = $this->getEntityManager();
        $connection = $em->getConnection();
        $statement = $connection->prepare("SELECT f.id FROM flux f WHERE f.prestataire_id = :id OR f.prestataire_dest_id = :id");
        $statement->bindValue('id', $presta->getId());
        $statement->execute();
        $results = $statement->fetchAll();
        $qb = $this->createQueryBuilder('f');
        return $qb
            ->where($qb->expr()->in('f.id', ':ids'))
            ->setParameter('ids', $results)
Julien Jorry committed
42
            ->orderBy('f.createdAt', 'DESC')
43 44 45 46 47 48 49 50 51 52 53 54
            ->getQuery()
        ;
    }

   /**
    * @param  Adherent $adherent [description]
    * @return Query Returns a query fo finding an array of Flux
    */
    public function getQueryByAdherent(Adherent $adherent)
    {
        $em = $this->getEntityManager();
        $connection = $em->getConnection();
Julien Jorry committed
55
        $statement = $connection->prepare("SELECT f.id FROM flux f WHERE f.adherent_id = :id OR f.adherent_dest_id = :id");
56 57 58 59 60 61 62
        $statement->bindValue('id', $adherent->getId());
        $statement->execute();
        $results = $statement->fetchAll();
        $qb = $this->createQueryBuilder('f');
        return $qb
            ->where($qb->expr()->in('f.id', ':ids'))
            ->setParameter('ids', $results)
Julien Jorry committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
            ->orderBy('f.createdAt', 'DESC')
            ->getQuery()
        ;
    }

   /**
    * @param  Comptoir $comptoir [description]
    * @return Query Returns a query fo finding an array of Flux
    */
    public function getQueryByComptoir(Comptoir $comptoir)
    {
        $em = $this->getEntityManager();
        $connection = $em->getConnection();
        $statement = $connection->prepare("SELECT f.id FROM flux f WHERE f.comptoir_id = :id");
        $statement->bindValue('id', $comptoir->getId());
        $statement->execute();
        $results = $statement->fetchAll();
        $qb = $this->createQueryBuilder('f');
        return $qb
            ->where($qb->expr()->in('f.id', ':ids'))
            ->setParameter('ids', $results)
            ->orderBy('f.createdAt', 'DESC')
            ->getQuery()
        ;
    }

   /**
    * @param  Groupe $groupe [description]
    * @return Query Returns a query fo finding an array of Flux
    */
    public function getQueryByGroupe(Groupe $groupe)
    {
        $em = $this->getEntityManager();
        $connection = $em->getConnection();
        $statement = $connection->prepare("SELECT f.id FROM flux f WHERE f.groupe_id = :id");
        $statement->bindValue('id', $groupe->getId());
        $statement->execute();
        $results = $statement->fetchAll();
        $qb = $this->createQueryBuilder('f');
        return $qb
            ->where($qb->expr()->in('f.id', ':ids'))
            ->setParameter('ids', $results)
            ->orderBy('f.createdAt', 'DESC')
106 107 108 109
            ->getQuery()
        ;
    }
}