ImageRepository.php 3.45 KB
Newer Older
1 2 3 4
<?php

namespace TechnoBundle\Repository;

5
use \TechnoBundle\Entity\Image;
6 7 8 9 10 11 12 13
/**
 * ImageRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ImageRepository extends \Doctrine\ORM\EntityRepository
{
14

15 16 17 18
    /**
     * @param $nb
     * @return Image[]
     */
19 20 21
    public function getLastImages($nb)
    {
        $dql = "SELECT I FROM TechnoBundle\Entity\Image I ORDER BY I.createdAt DESC";
Mat's avatar
Mat committed
22
        $em = $this->getEntityManager();
23 24 25 26 27 28
        $query = $em->createQuery($dql);
        $query->setMaxResults($nb);
        $result = $query->getResult();

        return $result;
    }
Mat's avatar
Mat committed
29

30 31 32 33
    /**
     * @return Image[]
     */
    public function findAllForIndex()
34
    {
35 36 37 38
        $qb = $this->createQueryBuilder('i')
            ->join('i.owner', 'o')
            ->addSelect('o')
            ->orderBy('i.id', 'ASC');
39

40 41
        return $qb->getQuery()->getResult();
    }
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56
    /**
     * @param $id
     * @return Image
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneByUpdate($id)
    {
        $qb = $this->createQueryBuilder('i')
            ->join('i.owner', 'o')
            ->addSelect('o')
            ->where('i.id = :id')
            ->setParameter(':id', $id);

        return $qb->getQuery()->getOneOrNullResult();
57
    }
Mat's avatar
Mat committed
58

59 60 61 62 63 64
    /**
     * @param $id
     * @return Image
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneByDelete($id)
65
    {
66 67 68 69 70
        $qb = $this->createQueryBuilder('i')
            ->where('i.id = :id')
            ->setParameter(':id', $id);

        return $qb->getQuery()->getOneOrNullResult();
71
    }
Mat's avatar
Mat committed
72

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    /**
     * @param $id
     * @return Image
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneByRead($id)
    {
        $qb = $this->createQueryBuilder('i')
            ->join('i.owner', 'o')
            ->addSelect('o')
            ->where('i.id = :id')
            ->setParameter(':id', $id);

        return $qb->getQuery()->getOneOrNullResult();
    }

89 90 91 92 93 94 95 96 97 98 99 100

    /**
     * @return Image[]
     */
    public function findAllForAPIRead()
    {
        $qb = $this->createQueryBuilder('i')
            ->join('i.owner', 'o')
            ->addSelect('o');
        return $qb->getQuery()->getResult();
    }

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

    /**
    * @param $id
    * @return Image
    * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAPIRead($id)
    {
        $qb = $this->createQueryBuilder('i')
            ->join('i.owner', 'o')
            ->addSelect('o')
            ->where('i.id = :id')
            ->setParameter(':id', $id);

        return $qb->getQuery()->getOneOrNullResult();
    }

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    /**
    * @param $id
    * @return Image
    * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAPIdelete($id)
    {
        $qb = $this->createQueryBuilder('i')
            ->join('i.owner', 'o')
            ->addSelect('o')
            ->where('i.id = :id')
            ->setParameter(':id', $id);

        return $qb->getQuery()->getOneOrNullResult();
    }
133

134
    
Mat's avatar
Mat committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    /**
     * @param $id
     * @return Image
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAPIUpdate($id)
    {
        $qb = $this->createQueryBuilder('i')
            ->join('i.owner', 'o')
            ->addSelect('o')
            ->where('i.id = :id')
            ->setParameter(':id', $id);

        return $qb->getQuery()->getOneOrNullResult();

    }

152
}