Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
97.06% covered (success)
97.06%
33 / 34
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
DepartmentAddCluster
97.06% covered (success)
97.06%
33 / 34
0.00% covered (danger)
0.00%
0 / 1
4
0.00% covered (danger)
0.00%
0 / 1
 readResponse
97.06% covered (success)
97.06%
33 / 34
0.00% covered (danger)
0.00%
0 / 1
4
1<?php
2
3/**
4 * @package 115Mandant
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsentities\Cluster;
11use BO\Zmsentities\Collection\ScopeList;
12use BO\Zmsentities\Exception\UserAccountMissingRights;
13use BO\Mellon\Validator;
14
15class DepartmentAddCluster extends BaseController
16{
17    /**
18     * @return \Psr\Http\Message\ResponseInterface
19     */
20    #[\Override]
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ): \Psr\Http\Message\ResponseInterface {
26        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
27        if (!$workstation->getUseraccount()->hasPermissions(['cluster'])) {
28            throw new UserAccountMissingRights();
29        }
30        $departmentId = Validator::value($args['departmentId'])->isNumber()->getValue();
31        $department = \App::$http
32            ->readGetResult('/department/' . $departmentId . '/', ['resolveReferences' => 2])->getEntity();
33        $organisation = \App::$http->readGetResult('/department/' . $departmentId . '/organisation/')->getEntity();
34        $input = $request->getParsedBody();
35
36        if (is_array($input) && array_key_exists('save', $input)) {
37            $entity = (new Cluster($input))->withCleanedUpFormData();
38            $entity->scopes = (new ScopeList($entity->scopes))->withUniqueScopes();
39            $entity = \App::$http
40                ->readPostResult('/department/' . $department->id . '/cluster/', $entity)
41                ->getEntity();
42            (new Helper\FileUploader($request, 'uploadCallDisplayImage'))->writeUploadToCluster($entity->id);
43            return \BO\Slim\Render::redirect(
44                'cluster',
45                array(
46                    'departmentId' => $department->id,
47                    'clusterId' => $entity->id
48                ),
49                array(
50                    'success' => 'cluster_created'
51                )
52            );
53        }
54
55        return \BO\Slim\Render::withHtml($response, 'page/cluster.twig', array(
56            'title' => 'Cluster einrichten',
57            'action' => 'add',
58            'menuActive' => 'owner',
59            'workstation' => $workstation,
60            'scopeList' => $department->getScopeList()->withUniqueScopes(),
61            'organisation' => $organisation,
62            'department' => $department
63        ));
64    }
65}