Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
53 / 53
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Calldisplay
100.00% covered (success)
100.00%
53 / 53
100.00% covered (success)
100.00%
4 / 4
18
100.00% covered (success)
100.00%
1 / 1
 readResolvedEntity
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
5
 readResolvedOrganisation
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 readImage
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
4
 readContactData
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
6
1<?php
2
3namespace BO\Zmsdb;
4
5use BO\Zmsentities\Calldisplay as Entity;
6
7/**
8 *
9 * @SuppressWarnings(CouplingBetweenObjects)
10 */
11class Calldisplay extends Base
12{
13    /**
14     * read Ticketprinter by comma separated buttonlist
15     *
16     * @param
17     * ticketprinter Entity
18     * now DateTime
19     *
20     * @return Resource Entity
21     */
22    public function readResolvedEntity(Entity $calldisplay, \DateTimeImmutable $dateTime, $resolveReferences = 0)
23    {
24        if ($calldisplay->hasScopeList()) {
25            $scopeList = new \BO\Zmsentities\Collection\ScopeList();
26            foreach ($calldisplay->scopes as $key => $entity) {
27                $query = new Scope();
28                $scope = $query->readEntity($entity['id'], $resolveReferences - 1);
29                /* test in zmsapi CalldisplayGet
30                if (! $scope) {
31                    throw new Exception\Calldisplay\ScopeNotFound();
32                }
33                */
34                $scopeList->addEntity($scope);
35            }
36            $calldisplay->scopes = $scopeList;
37        }
38        if ($calldisplay->hasClusterList()) {
39            $clusterList = new \BO\Zmsentities\Collection\ClusterList();
40            foreach ($calldisplay->clusters as $key => $entity) {
41                $query = new Cluster();
42                $cluster = $query->readEntity($entity['id'], $resolveReferences);
43                /* test in zmsapi CalldisplayGet
44                if (! $cluster) {
45                    throw new Exception\Calldisplay\ClusterNotFound();
46                }
47                */
48                $clusterList->addEntity($cluster);
49            }
50            $calldisplay->clusters = $clusterList;
51        }
52        $calldisplay->setServerTime($dateTime->getTimestamp());
53        $calldisplay->organisation = $this->readResolvedOrganisation($calldisplay);
54        $calldisplay->image = $this->readImage($calldisplay);
55        $calldisplay->contact = $this->readContactData($calldisplay);
56        return $calldisplay->withOutClusterDuplicates();
57    }
58
59    public function readResolvedOrganisation(Entity $entity)
60    {
61        $organisation = null;
62        $query = new Organisation();
63        $scope = $entity->getScopeList()->getFirst();
64        $cluster = $entity->getClusterList()->getFirst();
65        if ($scope) {
66            $organisation = $query->readByScopeId($scope->id);
67        } elseif ($cluster) {
68            $organisation = $query->readByClusterId($cluster->id);
69        }
70        return $organisation;
71    }
72
73    public function readImage(Entity $entity)
74    {
75        $name = $entity->getImageName();
76        $image = null;
77        if ($name) {
78            $image = $this->getReader()
79                ->fetchOne((new Query\Calldisplay(Query\Base::SELECT))
80                ->getQueryImage(), ['name' => "$name%"]);
81        }
82        if (! $image) {
83            $image = $this->getReader()
84            ->fetchOne((new Query\Calldisplay(Query\Base::SELECT))
85                ->getQueryImage(), ['name' => "logo.png"]);
86        }
87
88        $mime = pathinfo($image['name'], PATHINFO_EXTENSION);
89        $image['mime'] = ($mime == 'jpg') ? 'jpeg' : $mime;
90        return $image;
91    }
92
93    public function readContactData(Entity $entity)
94    {
95        $contact = new \BO\Zmsentities\Contact();
96        $contactNames = [];
97        if ($entity->hasClusterList()) {
98            foreach ($entity->getClusterList() as $cluster) {
99                $contactNames[] = $cluster->name;
100            }
101        } elseif ($entity->hasScopeList()) {
102            foreach ($entity->getScopeList() as $scope) {
103                $department = (new Department())->readByScopeId($scope->id);
104                $contactNames[] = $department->name;
105            }
106        }
107
108        $contactNames = array_unique($contactNames);
109        $contact->name = count($contactNames) > 1 ? '' : $contactNames[0];
110
111        return $contact;
112    }
113}