Completed
Push — master ( a3cce1...d6fbcc )
by Marcel
09:39
created

ServiceAttributeValueRepository::rollBack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\ServiceAttributeRegistrationCodeValue;
6
use App\Entity\ServiceAttributeUserRoleValue;
7
use App\Entity\ServiceAttributeUserTypeValue;
8
use App\Entity\ServiceAttributeValue;
9
use App\Entity\User;
10
use App\Entity\RegistrationCode;
11
use App\Entity\UserRole;
12
use App\Entity\UserType;
13
use Doctrine\ORM\EntityManagerInterface;
14
15
class ServiceAttributeValueRepository implements ServiceAttributeValueRepositoryInterface, TransactionalRepositoryInterface {
16
17
    private $em;
18
19 1
    public function __construct(EntityManagerInterface $objectManager) {
20 1
        $this->em = $objectManager;
21 1
    }
22
23
    /**
24
     * @inheritDoc
25
     */
26
    public function persist($attributeValue) {
27
        $this->em->persist($attributeValue);
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function remove($attributeValue) {
34
        $this->em->remove($attributeValue);
35
    }
36
37
    public function beginTransaction() {
38
        $this->em->beginTransaction();
39
    }
40
41
    public function commit() {
42
        $this->em->commit();
43
        $this->em->flush();
44
    }
45
46
    public function rollBack() {
47
        $this->em->rollback();
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53
    public function getAttributeValuesForUser(User $user) {
54
        $query = $this->em
55
            ->createQueryBuilder()
56
            ->select(['v', 'a'])
57
            ->from(ServiceAttributeValue::class, 'v')
58
            ->leftJoin('v.attribute', 'a')
59
            ->where('v.user = :user')
60
            ->setParameter('user', $user->getId());
61
62
        return $query->getQuery()->getResult();
63
    }
64
65
66
    /**
67
     * @inheritDoc
68
     */
69
    public function getAttributeValuesForUserType(UserType $userType) {
70
        $query = $this->em
71
            ->createQueryBuilder()
72
            ->select(['v', 'a'])
73
            ->from(ServiceAttributeUserTypeValue::class, 'v')
74
            ->leftJoin('v.attribute', 'a')
75
            ->where('v.userType = :type')
76
            ->setParameter('type', $userType->getId());
77
78
        return $query->getQuery()->getResult();
79
    }
80
81
    /**
82
     * @inheritDoc
83
     */
84
    public function getAttributeValuesForUserRole(UserRole $userRole) {
85
        $query = $this->em
86
            ->createQueryBuilder()
87
            ->select(['v', 'a'])
88
            ->from(ServiceAttributeUserRoleValue::class, 'v')
89
            ->leftJoin('v.attribute', 'a')
90
            ->where('v.userRole = :role')
91
            ->setParameter('role', $userRole->getId());
92
93
        return $query->getQuery()->getResult();
94
    }
95
96
    /**
97
     * @inheritDoc
98
     */
99
    public function getAttributeValuesForRegistrationCode(RegistrationCode $code) {
100
        $query = $this->em
101
            ->createQueryBuilder()
102
            ->select(['v', 'a'])
103
            ->from(ServiceAttributeRegistrationCodeValue::class, 'v')
104
            ->leftJoin('v.attribute', 'a')
105
            ->where('v.registrationCode = :code')
106
            ->setParameter('code', $code->getId());
107
108
        return $query->getQuery()->getResult();
109
    }
110
}