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 as Entity;
11use BO\Mellon\Validator;
12
13class DepartmentAddCluster extends BaseController
14{
15    /**
16     * @return String
17     */
18    public function readResponse(
19        \Psr\Http\Message\RequestInterface $request,
20        \Psr\Http\Message\ResponseInterface $response,
21        array $args
22    ) {
23        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
24        if (!$workstation->getUseraccount()->hasPermissions(['cluster'])) {
25            throw new \BO\Zmsentities\Exception\UserAccountMissingRights();
26        }
27        $departmentId = Validator::value($args['departmentId'])->isNumber()->getValue();
28        $department = \App::$http
29            ->readGetResult('/department/' . $departmentId . '/', ['resolveReferences' => 2])->getEntity();
30        $organisation = \App::$http->readGetResult('/department/' . $departmentId . '/organisation/')->getEntity();
31        $input = $request->getParsedBody();
32
33        if (is_array($input) && array_key_exists('save', $input)) {
34            $entity = (new Entity($input))->withCleanedUpFormData();
35            $entity->scopes = (new \BO\Zmsentities\Collection\ScopeList($entity->scopes))->withUniqueScopes();
36            $entity = \App::$http
37                ->readPostResult('/department/' . $department->id . '/cluster/', $entity)
38                ->getEntity();
39            (new Helper\FileUploader($request, 'uploadCallDisplayImage'))->writeUploadToCluster($entity->id);
40            return \BO\Slim\Render::redirect(
41                'cluster',
42                array(
43                    'departmentId' => $department->id,
44                    'clusterId' => $entity->id
45                ),
46                array(
47                    'success' => 'cluster_created'
48                )
49            );
50        }
51
52        return \BO\Slim\Render::withHtml($response, 'page/cluster.twig', array(
53            'title' => 'Cluster einrichten',
54            'action' => 'add',
55            'menuActive' => 'owner',
56            'workstation' => $workstation,
57            'scopeList' => $department->getScopeList()->withUniqueScopes(),
58            'organisation' => $organisation,
59            'department' => $department
60        ));
61    }
62}