Completed
Push — master ( a7f5a2...7520cc )
by Craig
06:59
created

setEmptyValueWhereAttributeNameIn()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 3
dl 0
loc 18
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\UsersModule\Entity\Repository;
13
14
use Doctrine\ORM\EntityRepository;
15
use Zikula\UsersModule\Constant;
16
use Zikula\UsersModule\Entity\RepositoryInterface\UserAttributeRepositoryInterface;
17
18
class UserAttributeRepository extends EntityRepository implements UserAttributeRepositoryInterface
19
{
20
    /**
21
     * @param array $attributeNames
22
     * @param array $users
23
     * @param array $forbiddenUsers
24
     * @return mixed
25
     */
26
    public function setEmptyValueWhereAttributeNameIn(
27
        array $attributeNames,
28
        array $users = [],
29
        array $forbiddenUsers = [Constant::USER_ID_ADMIN, Constant::USER_ID_ANONYMOUS]
30
    ) {
31
        $qb = $this->createQueryBuilder('a')
32
            ->set('a.value', '\'\'')
33
            ->where('a.name IN (:attributeNames)')
34
            ->setParameter('attributeNames', $attributeNames);
35
        if (!empty($users)) {
36
            $qb->andWhere('a.user IN (:users)')
37
                ->setParameter('users', $users);
38
        }
39
        $qb->andWhere('a.user NOT IN (:forbidden_users)')
40
            ->setParameter('forbidden_users', $forbiddenUsers);
41
42
        return $qb->getQuery()->execute();
43
    }
44
}
45