Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
98.11% covered (success)
98.11%
52 / 53
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UseraccountAdd
98.11% covered (success)
98.11%
52 / 53
50.00% covered (danger)
50.00%
1 / 2
11
0.00% covered (danger)
0.00%
0 / 1
 readResponse
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
1 / 1
5
 writeNewEntity
93.75% covered (success)
93.75%
15 / 16
0.00% covered (danger)
0.00%
0 / 1
6.01
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsentities\Schema\Loader;
11use BO\Zmsentities\Useraccount as Entity;
12
13class UseraccountAdd extends BaseController
14{
15    /**
16     * @SuppressWarnings(unused)
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        $confirmSuccess = $request->getAttribute('validator')->getParameter('success')->isString()->getValue();
26        $selectedDepartment = $request->getAttribute('validator')->getParameter('department')->isNumber()->getValue();
27        $ownerList = \App::$http->readGetResult('/owner/', ['resolveReferences' => 2])->getCollection();
28
29        $input = $request->getParsedBody();
30        if ($request->getMethod() === 'POST') {
31            $input['password'] = $input['changePassword'][0];
32            $result = $this->writeNewEntity($input);
33            if ($result instanceof Entity) {
34                return \BO\Slim\Render::redirect(
35                    'useraccountEdit',
36                    array(
37                        'loginname' => $result->id
38                    ),
39                    array(
40                        'success' => 'useraccount_added'
41                    )
42                );
43            }
44        }
45
46        $config = \App::$http->readGetResult('/config/', [], \App::CONFIG_SECURE_TOKEN)->getEntity();
47        $allowedProviderList = explode(',', $config->getPreference('oidc', 'provider'));
48
49        return \BO\Slim\Render::withHtml(
50            $response,
51            'page/useraccountEdit.twig',
52            [
53                'ownerList' => $ownerList->toDepartmentListByOrganisationName(),
54                'workstation' => $workstation,
55                'success' => $confirmSuccess,
56                'action' => 'add',
57                'title' => 'Nutzer: Einrichtung und Administration',
58                'menuActive' => 'useraccount',
59                'exception' => (isset($result)) ? $result : null,
60                'userAccount' => (isset($result)) ? $input : null,
61                'selectedDepartment' => $selectedDepartment,
62                'oidcProviderList' => array_filter($allowedProviderList),
63                'metadata' => $this->getSchemaConstraintList(Loader::asArray(Entity::$schema))
64            ]
65        );
66    }
67
68    protected function writeNewEntity($input)
69    {
70        $entity = new Entity($input);
71        if (isset($input['oidcProvider']) && '' != $input['oidcProvider']) {
72            $entity->id = $entity->id . '@' . $input['oidcProvider'];
73        }
74        $entity = $entity->withCleanedUpFormData(true);
75        try {
76            $entity = \App::$http->readPostResult('/useraccount/', $entity)->getEntity();
77        } catch (\BO\Zmsclient\Exception $exception) {
78            $template = Helper\TwigExceptionHandler::getExceptionTemplate($exception);
79            if (
80                '' != $exception->template
81                && \App::$slim->getContainer()->get('view')->getLoader()->exists($template)
82            ) {
83                return [
84                    'template' => $template,
85                    'include' => true,
86                    'data' => $exception->data
87                ];
88            }
89            throw $exception;
90        }
91        return $entity;
92    }
93}