Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.50% covered (warning)
62.50%
10 / 16
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
AvailabilityDelete
62.50% covered (warning)
62.50%
10 / 16
0.00% covered (danger)
0.00%
0 / 1
4.84
0.00% covered (danger)
0.00%
0 / 1
 readResponse
62.50% covered (warning)
62.50%
10 / 16
0.00% covered (danger)
0.00%
0 / 1
4.84
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\Zmsdb\Availability as AvailabilityRepository;
12use BO\Zmsdb\Helper\CalculateSlots as CalculateSlotsHelper;
13use Psr\Http\Message\RequestInterface;
14use Psr\Http\Message\ResponseInterface;
15use BO\Zmsentities\Availability as Entity;
16use App;
17
18class AvailabilityDelete extends BaseController
19{
20    /**
21     * @SuppressWarnings(Param)
22     * @return ResponseInterface
23     */
24    #[\Override]
25    public function readResponse(
26        RequestInterface $request,
27        ResponseInterface $response,
28        array $args
29    ): ResponseInterface {
30        (new Helper\User($request))->checkPermissions('availability');
31        $repository = new AvailabilityRepository();
32        $entity = $repository->readEntity($args['id'], 2);
33
34        if ($entity->scope && $entity->hasId() && $repository->deleteEntity($entity->getId())) {
35            (new CalculateSlotsHelper(\App::DEBUG))->writePostProcessingByScope($entity->scope, \App::$now);
36            App::$log->info('Deleted availability', [
37                'id' => $entity->getId(),
38                'scope_id' => $entity->scope['id'],
39                'operation' => 'delete'
40            ]);
41        } else {
42            $entity = new Entity(['id' => $args['id']]);
43        }
44
45        $message = Response\Message::create($request);
46        $message->data = $entity;
47
48        $response = Render::withLastModified($response, time(), '0');
49        $response = Render::withJson($response, $message->setUpdatedMetaData(), 200);
50        return $response;
51    }
52}