Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
50 / 50
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
Provider
100.00% covered (success)
100.00%
50 / 50
100.00% covered (success)
100.00%
7 / 7
12
100.00% covered (success)
100.00%
1 / 1
 getEntityMapping
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
2
 addConditionIsAssigned
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
3
 addConditionProviderId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionProviderIdList
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionProviderSource
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionRequestCsv
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 postProcess
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace BO\Zmsbackend\Provider\Repository;
4
5class Provider extends \BO\Zmsbackend\Query\Base
6{
7    const TABLE = 'provider';
8
9    public function getEntityMapping()
10    {
11        $mapping = [
12            'contact__city' => 'provider.contact__city',
13            'contact__country' => self::expression('"Germany"'),
14            'contact__name' => 'provider.name',
15            'contact__postalCode' => 'provider.contact__postalCode',
16            'contact__region' => 'provider.contact__region',
17            'contact__street' => 'provider.contact__street',
18            'contact__streetNumber' => 'provider.contact__streetNumber',
19            'id' => 'provider.id',
20            'link' => 'provider.link',
21            'name' => 'provider.name',
22            'displayName' => 'provider.display_name',
23            'source' => 'provider.source',
24            'parent_id' => 'provider.parent_id'
25        ];
26        if ($this->getResolveLevel() > 0) {
27            $mapping['data'] = 'provider.data';
28        }
29        return $mapping;
30    }
31
32    public function addConditionIsAssigned($isAssigned)
33    {
34        $this->leftJoin(
35            new \BO\Zmsbackend\Query\Alias(\BO\Zmsbackend\Query\Scope::TABLE, 'assignedscope'),
36            'provider.id',
37            '=',
38            'assignedscope.InfoDienstleisterID'
39        );
40        if (true === $isAssigned) {
41            $this->query->where('assignedscope.InfoDienstleisterID', 'IS NOT', null);
42        } elseif (false === $isAssigned) {
43            $this->query->where('assignedscope.InfoDienstleisterID', 'IS', null);
44        }
45        return $this;
46    }
47
48    public function addConditionProviderId($providerId)
49    {
50        $this->query->where('provider.id', '=', $providerId);
51        return $this;
52    }
53
54    public function addConditionProviderIdList(array $providerIds): self
55    {
56        $this->query->where('provider.id', 'IN', array_map('intval', $providerIds));
57
58        return $this;
59    }
60
61    public function addConditionProviderSource($source)
62    {
63        $this->query->where('provider.source', '=', $source);
64        return $this;
65    }
66
67    /**
68     * @todo find calls and implement "sourceName"-parameter to remove default value
69     */
70    public function addConditionRequestCsv($requestIdCsv, $sourceName = 'dldb')
71    {
72        $requestIdList = explode(',', $requestIdCsv);
73        $this->leftJoin(
74            new \BO\Zmsbackend\Query\Alias("request_provider", 'xprovider'),
75            'provider.id',
76            '=',
77            'xprovider.provider__id'
78        );
79        $this->query->where(function (\BO\Zmsbackend\Query\Builder\ConditionBuilder $query) use ($requestIdList, $sourceName) {
80            $query->andWith('xprovider.request__id', 'IN', $requestIdList);
81            $query->andWith('xprovider.bookable', '=', 1);
82            $query->andWith('xprovider.source', '=', $sourceName);
83        });
84    }
85
86    #[\Override]
87    public function postProcess($data)
88    {
89        if (isset($data[$this->getPrefixed('data')]) && $data[$this->getPrefixed('data')]) {
90            $data[$this->getPrefixed('data')] = json_decode($data[$this->getPrefixed('data')], true);
91        }
92        return $data;
93    }
94}