Completed
Push — master ( 28dda4...aabe55 )
by Craig
06:13
created

HookBindingRepository::findByOwners()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\Bundle\HookBundle\Dispatcher\Storage\Doctrine\Entity\Repository;
13
14
use Doctrine\ORM\EntityRepository;
15
use Doctrine\ORM\Query\Expr\OrderBy;
16
use Zikula\Bundle\HookBundle\Dispatcher\Storage\Doctrine\Entity\HookBindingEntity;
17
use Zikula\Bundle\HookBundle\Dispatcher\Storage\Doctrine\Entity\RepositoryInterface\HookBindingRepositoryInterface;
18
19
class HookBindingRepository extends EntityRepository implements HookBindingRepositoryInterface
20
{
21
    public function deleteByBothAreas($subscriberArea, $providerArea)
22
    {
23
        $qb = $this->_em->createQueryBuilder();
24
        $qb->delete(HookBindingEntity::class, 't')
25
            ->where('t.pareaid = ?1 AND t.sareaid = ?2')
26
            ->setParameters([1 => $providerArea, 2 => $subscriberArea])
27
            ->getQuery()
28
            ->execute();
29
    }
30
31
    public function selectByAreaName($areaName, $type = 'sareaid')
32
    {
33
        $type = in_array($type, ['sareaid', 'pareaid']) ? $type : 'sareaid';
34
        $order = new OrderBy();
35
        $order->add('t.sortorder', 'ASC');
36
        $order->add('t.sareaid', 'ASC');
37
38
        return $this->createQueryBuilder('t')
39
            ->where("t.$type = ?1")
40
            ->orderBy($order)
41
            ->setParameter(1, $areaName)
42
            ->getQuery()
43
            ->getArrayResult();
44
    }
45
46
    public function setSortOrder($order, $subscriberAreaName, $providerAreaName)
47
    {
48
        $this->_em->createQueryBuilder()
49
            ->update(HookBindingEntity::class, 't')
50
            ->set('t.sortorder', $order)
51
            ->where('t.sareaid = ?1 AND t.pareaid = ?2')
52
            ->setParameters([1 => $subscriberAreaName, 2 => $providerAreaName])
53
            ->getQuery()
54
            ->execute();
55
    }
56
57
    public function findOneOrNullByAreas($subscriberArea, $providerArea)
58
    {
59
        return $this->createQueryBuilder('t')
60
            ->where('t.sareaid = ?1 AND t.pareaid = ?2')
61
            ->setParameters([1 => $subscriberArea, 2 => $providerArea])
62
            ->getQuery()
63
            ->getOneOrNullResult();
64
    }
65
66
    public function findByOwners($subscriberOwner, $providerOwner)
67
    {
68
        return $this->createQueryBuilder('t')
69
            ->where('t.sowner = ?1 AND t.powner = ?2')
70
            ->setParameters([1 => $subscriberOwner, 2 => $providerOwner])
71
            ->getQuery()
72
            ->getArrayResult();
73
    }
74
75 View Code Duplication
    public function deleteAllByOwner($owner)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $qb = $this->_em->createQueryBuilder();
78
        $qb->delete(HookBindingEntity::class, 't')
79
            ->where('t.sowner = ?1 OR t.powner = ?2')
80
            ->setParameters([1 => $owner, 2 => $owner])
81
            ->getQuery()
82
            ->execute();
83
    }
84
}
85