Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.43% covered (success)
96.43%
27 / 28
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
DepartmentAddScope
96.43% covered (success)
96.43%
27 / 28
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 readResponse
96.43% covered (success)
96.43%
27 / 28
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * @package 115Mandant
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Mellon\Validator;
11use BO\Zmsentities\Scope as Entity;
12use BO\Zmsentities\Exception\UserAccountMissingRights;
13
14/**
15  * Handle requests concerning services
16  *
17  */
18class DepartmentAddScope extends Scope
19{
20    /**
21     * @return \Psr\Http\Message\ResponseInterface
22     */
23    #[\Override]
24    public function readResponse(
25        \Psr\Http\Message\RequestInterface $request,
26        \Psr\Http\Message\ResponseInterface $response,
27        array $args
28    ): \Psr\Http\Message\ResponseInterface {
29        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
30        if (!$workstation->getUseraccount()->hasPermissions(['scope'])) {
31            throw new UserAccountMissingRights();
32        }
33        $departmentId = Validator::value($args['id'])->isNumber()->getValue();
34        $department = \App::$http
35            ->readGetResult('/department/' . $departmentId . '/', ['resolveReferences' => 0])->getEntity();
36        $organisation = \App::$http->readGetResult('/department/' . $departmentId . '/organisation/')->getEntity();
37        $providerList = Helper\ProviderHandler::readProviderList($workstation->getScope()->getSource());
38        $sourceList = $this->readSourceList();
39        $input = $request->getParsedBody();
40
41        if (is_array($input) && array_key_exists('save', $input)) {
42            $result = $this->writeUpdatedEntity($input, $department->id, null, $workstation);
43            if ($result instanceof Entity) {
44                $this->writeUploadedImage($request, $result->id, $input);
45                return \BO\Slim\Render::redirect('scope', ['id' => $result->id], [
46                    'success' => 'scope_created'
47                ]);
48            }
49        }
50        return \BO\Slim\Render::withHtml($response, 'page/scope.twig', array(
51            'title' => 'Standort',
52            'action' => 'add',
53            'menuActive' => 'owner',
54            'workstation' => $workstation,
55            'organisation' => $organisation,
56            'department' => $department,
57            'sourceList' => $sourceList,
58            'exception' => (isset($result)) ? $result : null,
59            'providerList' => $providerList
60        ));
61    }
62}