Completed
Push — master ( 72c0d5...95f58c )
by Laurent
03:20
created

InventoryRepository::getLastInventory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
7
/**
8
 * InventoryRepository
9
 *
10
 * This class was generated by the Doctrine ORM. Add your own custom
11
 * repository methods below.
12
 */
13
class InventoryRepository extends EntityRepository
14
{
15
    /**
16
     * Affiche les inventaires actifs.
17
     *
18
     * @return QueryBuilder Requête DQL
19
     */
20
    public function getInventory()
21
    {
22
        $query = $this->findActive()
23
            ->getQuery();
24
        
25
        return $query->getResult();
26
    }
27
28
    /**
29
     * Renvoi les derniers inventaires.
30
     *
31
     * @param integer $count Nombre d'élément à afficher
32
     * @return array Query result
33
     */
34
    public function getLastInventory($count)
35
    {
36
        $query = $this->findActive()
37
            ->setMaxResults($count)
38
            ->getQuery();
39
40
        return $query->getResult();
41
    }
42
43
    private function findActive()
44
    {
45
        $query = $this->createQueryBuilder('i')
46
            ->where('i.status > 0')
47
            ->orderBy('i.id', 'DESC');
48
49
        return $query;
50
    }
51
}
52