Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

Repository/AnalyticsSegmentRepository.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\DashboardBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
7
/**
8
 * AnalyticsSegmentRepository
9
 *
10
 * This class was generated by the Doctrine ORM. Add your own custom
11
 * repository methods below.
12
 */
13
class AnalyticsSegmentRepository extends EntityRepository
14
{
15
    /**
16
     * Get a segment
17
     *
18
     * @param int $id
19
     *
20
     * @return AnalyticsOverview|bool
21
     */
22
    public function deleteSegment($id)
23
    {
24
        $em = $this->getEntityManager();
25
        $qb = $em->createQueryBuilder();
26
        $qb->select('s')
27
            ->from('KunstmaanDashboardBundle:AnalyticsSegment', 's')
28
            ->where('s.id = :id')
29
            ->setParameter('id', $id);
30
31
32
        $results = $qb->getQuery()->getResult();
33
        if ($results) {
34
            $em->remove($results[0]);
35
            $em->flush();
36
        }
37
    }
38
39
    /**
40
     * Initialise a segment by adding new overviews if they don't exist yet
41
     *
42
     * @param AnalyticsSegment $segment
43
     * @param int $configId
44
     */
45
    public function initSegment($segment, $configId = false) {
46
        if (!count($segment->getOverviews()->toArray())) {
47
            if ($configId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $configId of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
48
                $config =$this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->find($configId);
49
            } else {
50
                $config =$this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->findFirst();
51
            }
52
            $this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsOverview')->addOverviews($config, $segment);
53
        }
54
    }
55
56
}
57