GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c7f4e3...a41792 )
by Mario
18:09
created

EzInfoCollectionAttributeRepository   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 13

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 13
dl 0
loc 119
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 4 1
A createNewFromValues() 0 14 1
A save() 0 9 2
A remove() 0 12 3
A findByCollectionIdAndFieldDefinitionIds() 0 12 1
A findByCollectionId() 0 10 1
A getCountByContentId() 0 13 2
A search() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\Doctrine\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use Doctrine\ORM\NonUniqueResultException;
9
use Doctrine\ORM\NoResultException;
10
use Doctrine\ORM\ORMException;
11
use Doctrine\ORM\ORMInvalidArgumentException;
12
use eZ\Publish\API\Repository\Values\Content\Content;
13
use Netgen\InformationCollection\API\Exception\RemoveAttributeFailedException;
14
use Netgen\InformationCollection\API\Exception\RetrieveCountException;
15
use Netgen\InformationCollection\API\Exception\StoringAttributeFailedException;
16
use Netgen\InformationCollection\API\Value\Legacy\FieldValue;
17
use Netgen\InformationCollection\Doctrine\Entity\EzInfoCollection;
18
use Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute;
19
20
class EzInfoCollectionAttributeRepository extends EntityRepository
21
{
22
    /**
23
     * Get new \Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute instance.
24
     *
25
     * @return \Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute
26
     */
27
    public function getInstance()
28
    {
29
        return new EzInfoCollectionAttribute();
30
    }
31
32
    public function createNewFromValues(Content $content, EzInfoCollection $collection, FieldValue $fieldValue, string $fieldDefIdentifier): EzInfoCollectionAttribute
33
    {
34
        $ezInfoAttribute = $this->getInstance();
35
36
        $ezInfoAttribute->setContentObjectId($content->contentInfo->id);
37
        $ezInfoAttribute->setInformationCollectionId($collection->getId());
38
        $ezInfoAttribute->setContentClassAttributeId($fieldValue->getFieldDefinitionId());
39
        $ezInfoAttribute->setContentObjectAttributeId($content->getField($fieldDefIdentifier)->id);
40
        $ezInfoAttribute->setDataInt($fieldValue->getDataInt());
41
        $ezInfoAttribute->setDataFloat($fieldValue->getDataFloat());
42
        $ezInfoAttribute->setDataText($fieldValue->getDataText());
43
44
        return $ezInfoAttribute;
45
    }
46
47
    /**
48
     * Save object.
49
     *
50
     * @param \Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute $infoCollectionAttribute
51
     *
52
     * @throws StoringAttributeFailedException
53
     */
54
    public function save(EzInfoCollectionAttribute $infoCollectionAttribute)
55
    {
56
        try {
57
            $this->_em->persist($infoCollectionAttribute);
58
            $this->_em->flush($infoCollectionAttribute);
59
        } catch (ORMException | ORMInvalidArgumentException $exception) {
60
            throw new StoringAttributeFailedException('', '');
61
        }
62
    }
63
64
    /**
65
     * @param \Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute[] $attributes
66
     *
67
     * @throws ORMException
68
     */
69
    public function remove(array $attributes)
70
    {
71
        try {
72
            foreach ($attributes as $attribute) {
73
                $this->_em->remove($attribute);
74
            }
75
76
            $this->_em->flush();
77
        } catch (ORMException | ORMInvalidArgumentException $exception) {
78
            throw  new RemoveAttributeFailedException('', '');
79
        }
80
    }
81
82
    public function findByCollectionIdAndFieldDefinitionIds($collectionId, $fieldDefinitionIds)
83
    {
84
        $qb = $this->createQueryBuilder('eica');
85
86
        return $qb->select('eica')
87
            ->where('eica.informationCollectionId = :collection-id')
88
            ->setParameter('collection-id', $collectionId)
89
            ->andWhere($qb->expr()->in('eica.contentClassAttributeId', ':fields'))
90
            ->setParameter('fields', $fieldDefinitionIds)
91
            ->getQuery()
92
            ->getResult();
93
    }
94
95
    public function findByCollectionId($collectionId)
96
    {
97
        $qb = $this->createQueryBuilder('eica');
98
99
        return $qb->select('eica')
100
            ->where('eica.informationCollectionId = :collection-id')
101
            ->setParameter('collection-id', $collectionId)
102
            ->getQuery()
103
            ->getResult();
104
    }
105
106
    public function getCountByContentId($contentId)
107
    {
108
        try {
109
            return (int)$this->createQueryBuilder('eica')
110
                ->andWhere('eica.contentObjectId = :contentId')
111
                ->setParameter('contentId', $contentId)
112
                ->select('COUNT(eica) as children_count')
113
                ->getQuery()
114
                ->getSingleScalarResult();
115
        } catch (NonUniqueResultException | NoResultException $exception) {
116
            throw new RetrieveCountException('', '');
117
        }
118
    }
119
120
    public function search($contentId, $searchText)
121
    {
122
        $searchText = mb_strtolower($searchText);
123
124
        $qb = $this->createQueryBuilder('eica');
125
126
        $result = $qb->select('eica.informationCollectionId')
127
            ->where('eica.contentObjectId = :contentId')
128
            ->setParameter('contentId', $contentId)
129
            ->andWhere($qb->expr()->andX(
130
                $qb->expr()->like('LOWER(eica.dataText)', ':searchText')
131
            ))
132
            ->setParameter('searchText', '%' . $searchText . '%')
133
            ->getQuery()
134
            ->getScalarResult();
135
136
        return array_column($result, 'informationCollectionId');
137
    }
138
}
139