Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.67% covered (success)
91.67%
44 / 48
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Cluster
91.67% covered (success)
91.67%
44 / 48
50.00% covered (danger)
50.00%
1 / 2
8.04
0.00% covered (danger)
0.00%
0 / 1
 readResponse
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
1 / 1
5
 testOrganisation
33.33% covered (danger)
33.33%
2 / 6
0.00% covered (danger)
0.00%
0 / 1
5.67
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsentities\Cluster as Entity;
11use BO\Mellon\Validator;
12
13class Cluster extends BaseController
14{
15    /**
16     * @SuppressWarnings(Param)
17     * @return String
18     */
19    public function readResponse(
20        \Psr\Http\Message\RequestInterface $request,
21        \Psr\Http\Message\ResponseInterface $response,
22        array $args
23    ) {
24        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
25        $entityId = Validator::value($args['clusterId'])->isNumber()->getValue();
26        $departmentId = Validator::value($args['departmentId'])->isNumber()->getValue();
27
28        $entity = \App::$http
29                ->readGetResult('/cluster/' . $entityId . '/', ['resolveReferences' => 2])
30                ->getEntity();
31        $organisation = $this->testOrganisation($entityId);
32
33        $success = $request->getAttribute('validator')->getParameter('success')->isString()->getValue();
34
35        $department = \App::$http->readGetResult(
36            '/department/' . $departmentId . '/',
37            ['resolveReferences' => 2]
38        )->getEntity();
39
40        $callDisplayImage = \App::$http->readGetResult('/cluster/' . $entityId . '/imagedata/calldisplay/')->getEntity();
41        $input = $request->getParsedBody();
42        if (is_array($input) && array_key_exists('save', $input)) {
43            $entity = (new Entity($input))->withCleanedUpFormData();
44            $entity->id = $entityId;
45            $entity = \App::$http->readPostResult('/cluster/' . $entity->id . '/', $entity)->getEntity();
46            if (isset($input['removeImage']) && $input['removeImage']) {
47                \App::$http->readDeleteResult('/cluster/' . $entityId . '/imagedata/calldisplay/');
48            } else {
49                (new Helper\FileUploader($request, 'uploadCallDisplayImage'))->writeUploadToCluster($entityId);
50            }
51
52            return \BO\Slim\Render::redirect('cluster', [
53                'clusterId' => $entityId,
54                'departmentId' => $departmentId,
55            ], [
56                'success' => 'cluster_saved'
57            ]);
58        }
59
60        return \BO\Slim\Render::withHtml(
61            $response,
62            'page/cluster.twig',
63            array(
64                'title' => 'Cluster',
65                'menuActive' => 'owner',
66                'workstation' => $workstation,
67                'organisation' => $organisation,
68                'cluster' => $entity->getArrayCopy(),
69                'department' => $department,
70                'scopeList' => $department->getScopeList()->sortByContactName(),
71                'callDisplayImage' => $callDisplayImage,
72                'success' => $success,
73            )
74        );
75    }
76
77    protected function testOrganisation($entityId)
78    {
79        try {
80            $organisation = \App::$http->readGetResult('/cluster/' . $entityId . '/organisation/')->getEntity();
81        } catch (\BO\Zmsclient\Exception $exception) {
82            if ($exception->template == 'BO\Zmsdb\Exception\ClusterWithoutScopes') {
83                $organisation = new \BO\Zmsentities\Organisation();
84            } else {
85                throw $exception;
86            }
87        }
88        return $organisation;
89    }
90}