Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProcessPreconfirm
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 readResponse
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
6
 testProcessData
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
30
 validateProcessLimits
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsapi;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsdb\Process;
13
14/**
15 * @SuppressWarnings(CouplingBetweenObjects)
16 */
17class ProcessPreconfirm extends BaseController
18{
19    /**
20     * @SuppressWarnings(Param)
21     * @return String
22     */
23    public function readResponse(
24        \Psr\Http\Message\RequestInterface $request,
25        \Psr\Http\Message\ResponseInterface $response,
26        array $args
27    ) {
28        \BO\Zmsdb\Connection\Select::setCriticalReadSession();
29
30        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(3)->getValue();
31        $input = Validator::input()->isJson()->assertValid()->getValue();
32        $entity = new \BO\Zmsentities\Process($input);
33        $entity->testValid();
34        $this->testProcessData($entity);
35
36        $userAccount = (new Helper\User($request))->readWorkstation()->getUseraccount();
37        $process = (new Process())->readEntity($entity->id, $entity->authKey, 2);
38
39        //$this->validateProcessLimits($process); Should be moved to zmscitizenapi.
40        if ('reserved' != $process->status) {
41            throw new Exception\Process\ProcessNotReservedAnymore();
42        }
43
44        $process = (new Process())->updateProcessStatus(
45            $process,
46            'preconfirmed',
47            \App::$now,
48            $resolveReferences,
49            $userAccount
50        );
51        $message = Response\Message::create($request);
52        $message->data = $process;
53
54        $response = Render::withLastModified($response, time(), '0');
55        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
56        return $response;
57    }
58
59    protected function testProcessData($entity)
60    {
61        $authCheck = (new Process())->readAuthKeyByProcessId($entity->id);
62
63        if (! (new Process())->isAppointmentAllowedWithSameMail($entity)) {
64            throw new Exception\Process\MoreThanAllowedAppointmentsPerMail();
65        }
66
67        if (! $authCheck) {
68            throw new Exception\Process\ProcessNotFound();
69        } elseif ($authCheck['authKey'] != $entity->authKey && $authCheck['authName'] != $entity->authKey) {
70            throw new Exception\Process\AuthKeyMatchFailed();
71        }
72    }
73
74    protected function validateProcessLimits(\BO\Zmsentities\Process $process)
75    {
76        if (! (new Process())->isAppointmentSlotCountAllowed($process)) {
77            throw new Exception\Process\MoreThanAllowedSlotsPerAppointment();
78        }
79
80        if (! (new Process())->isServiceQuantityAllowed($process)) {
81            throw new Exception\Process\MoreThanAllowedQuantityPerService();
82        }
83    }
84}