Completed
Push — master ( 5b7ff5...aa63f9 )
by Stepan
16:48 queued 07:41
created

TicketCostRepository::getEventTicketsCostQB()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Application\Bundle\DefaultBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Stfalcon\Bundle\EventBundle\Entity\Event;
7
8
/**
9
 * Class TicketCostRepository.
10
 */
11
class TicketCostRepository extends EntityRepository
12
{
13
    /**
14
     * Get event current cost.
15
     *
16
     * @param Event $event
17
     *
18
     * @return float
19
     */
20
    public function getEventCurrentCost(Event $event)
21
    {
22
        $qb = $this->getEventTicketsCostQB($event);
23
        $qb->select('tc.amount');
24
        $qb->andWhere($qb->expr()->eq('tc.enabled', 1));
25
26
        $result = $qb->getQuery()->getResult();
27
        $result = is_array($result) ? array_shift($result) : null;
0 ignored issues
show
introduced by
The condition is_array($result) is always true.
Loading history...
28
29
        $currentCost = $result ? $result['amount'] : null;
30
31
        return $currentCost;
32
    }
33
34
    /**
35
     * Get Event tickets cost.
36
     *
37
     * @param Event $event
38
     *
39
     * @return array
40
     */
41
    public function getEventTicketsCost(Event $event)
42
    {
43
        $qb = $this->getEventTicketsCostQB($event);
44
45
        return $qb->getQuery()->getResult();
46
    }
47
48
    /**
49
     * Get Event enabled tickets cost.
50
     *
51
     * @param Event $event
52
     *
53
     * @return array
54
     */
55
    public function getEventEnabledTicketsCost(Event $event)
56
    {
57
        $qb = $this->getEventTicketsCostQB($event);
58
        $qb->andWhere($qb->expr()->eq('tc.enabled', 1));
59
60
        return  $qb->getQuery()->getResult();
61
    }
62
63
    /**
64
     * @param Event $event
65
     *
66
     * @return \Doctrine\ORM\QueryBuilder
67
     */
68
    private function getEventTicketsCostQB(Event $event)
69
    {
70
        $qb = $this->createQueryBuilder('tc');
71
        $qb->where($qb->expr()->eq('tc.event', ':event'))
72
            ->setParameter(':event', $event)
73
            ->orderBy('tc.amount');
74
75
        return $qb;
76
    }
77
}
78