Lines
96.29%
26 / 27
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProcessDelete | 96.29% | 26 / 27 | 50.00% | 1 / 2 | 6 | 0.00% | 0 / 1 | |||
| readResponse | 94.44% | 17 / 18 | 0.00% | 0 / 1 | 2.00 | |||||
| writeDeleteMailNotifications | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 4 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * | |
| 5 | * @package Zmsadmin | |
| 6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 7 | * | |
| 8 | */ | |
| 9 | ||
| 10 | namespace BO\Zmsadmin; | |
| 11 | ||
| 12 | use BO\Mellon\Validator; | |
| 13 | use BO\Slim\Render; | |
| 14 | use BO\Zmsentities\Process; | |
| 15 | ||
| 16 | /** | |
| 17 | * Delete a process | |
| 18 | */ | |
| 19 | class ProcessDelete extends BaseController | |
| 20 | { | |
| 21 | /** | |
| 22 | * @SuppressWarnings(Param) | |
| 23 | * @return \Psr\Http\Message\ResponseInterface | |
| 24 | */ | |
| 25 | #[\Override] | |
| 26 | public function readResponse( | |
| 27 | \Psr\Http\Message\RequestInterface $request, | |
| 28 | \Psr\Http\Message\ResponseInterface $response, | |
| 29 | array $args | |
| 30 | ): \Psr\Http\Message\ResponseInterface { | |
| 31 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity(); | |
| 32 | $processId = Validator::value($args['id'])->isNumber()->getValue(); | |
| 33 | $initiator = Validator::param('initiator')->isString()->getValue(); | |
| 34 | $process = \App::$http->readGetResult('/process/' . $processId . '/')->getEntity(); | |
| 35 | if (!$process instanceof Process) { | |
| 36 | throw new \BO\Zmsclient\Exception('Process not found'); | |
| 37 | } | |
| 38 | $process->status = 'deleted'; | |
| 39 | $workstation->validateProcessScopeAccess((new Helper\ClusterHelper($workstation))->getScopeList(), $process); | |
| 40 | ||
| 41 | static::writeDeleteMailNotifications($process); | |
| 42 | \App::$http->readDeleteResult('/process/' . $process->getId() . '/', ['initiator' => $initiator]); | |
| 43 | ||
| 44 | return \BO\Slim\Render::withHtml( | |
| 45 | $response, | |
| 46 | 'element/helper/messageHandler.twig', | |
| 47 | array( | |
| 48 | 'success' => 'process_deleted', | |
| 49 | 'selectedprocess' => $process, | |
| 50 | ) | |
| 51 | ); | |
| 52 | } | |
| 53 | ||
| 54 | public static function writeDeleteMailNotifications($process): void | |
| 55 | { | |
| 56 | #email only for clients with appointment if email address is given | |
| 57 | if ( | |
| 58 | $process->getFirstClient()->hasEmail() && | |
| 59 | $process->isWithAppointment() && | |
| 60 | $process->scope->hasEmailFrom() | |
| 61 | ) { | |
| 62 | \App::$http | |
| 63 | ->readPostResult( | |
| 64 | '/process/' . $process->getId() . '/' . $process->getAuthKey() . '/delete/mail/', | |
| 65 | $process, | |
| 66 | ['initiator' => 'admin'] | |
| 67 | )->getEntity(); | |
| 68 | } | |
| 69 | } | |
| 70 | } |