Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
LoginForm
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
4 / 4
10
100.00% covered (success)
100.00%
1 / 1
 fromLoginParameters
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 fromAdditionalParameters
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
5
 fromQuickLogin
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 writeWorkstationUpdate
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 *
5 * @package 115Mandant
6 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
7 *
8 */
9
10namespace BO\Zmsadmin\Helper;
11
12use BO\Mellon\Validator;
13use BO\Mellon\Collection;
14
15class LoginForm
16{
17    /**
18     * form data for reuse in multiple controllers
19     */
20    public static function fromLoginParameters(): Collection
21    {
22        $collection = array();
23        // loginName
24        $collection['loginName'] = Validator::param('loginName')->isString()
25            ->isBiggerThan(2, "Es muss ein aussagekräftiger Name eingegeben werden")
26            ->isSmallerThan(40, "Der Name sollte 40 Zeichen nicht überschreiten");
27
28        // password
29        $collection['password'] = Validator::param('password')->isString()
30            ->isBiggerThan(2, "Es muss ein Passwort eingegeben werden")
31            ->isSmallerThan(20, "Das Passwort sollte 20 Zeichen nicht überschreiten");
32
33        // return validated collection
34        $collection = Validator::collection($collection);
35        return $collection;
36    }
37
38    /**
39     * form data for reuse in multiple controllers
40     */
41    public static function fromAdditionalParameters(): Collection
42    {
43        $collection = array();
44
45        // scope
46        if ('cluster' == Validator::param('scope')->isString()->getValue()) {
47            $collection['scope'] = Validator::param('scope')
48                ->isString('Bitte wählen Sie einen Standort aus');
49        } else {
50            $collection['scope'] = Validator::param('scope')
51                ->isNumber('Bitte wählen Sie einen Standort aus');
52        }
53
54        if (! Validator::param('appointmentsOnly')->isDeclared()->hasFailed()) {
55            $collection['appointmentsOnly'] = Validator::param('appointmentsOnly')
56                ->isNumber();
57        }
58
59        // workstation
60        if (! Validator::param('workstation')->isDeclared()->hasFailed()) {
61            $collection['workstation'] = Validator::param('workstation')
62                 ->isString('Bitte wählen Sie einen Arbeitsplatz oder den Tresen aus')
63                 ->isSmallerThan(8, "Die Arbeitsplatz-Bezeichnung sollte 8 Zeichen nicht überschreiten");
64        }
65        // hint
66        if (! Validator::param('hint')->isDeclared()->hasFailed()) {
67            $collection['hint'] = Validator::param('hint')
68                ->isString();
69        }
70
71        // return validated collection
72        $collection = Validator::collection($collection);
73        return $collection;
74    }
75
76    public static function fromQuickLogin(): Collection
77    {
78        $loginData = static::fromLoginParameters();
79        $additionalData = static::fromAdditionalParameters();
80        $collection = array_merge($loginData->getValues(), $additionalData->getValues());
81        $collection['redirectUrl'] = Validator::param('url')->isString();
82        $collection = Validator::collection($collection);
83        return $collection;
84    }
85
86    public static function writeWorkstationUpdate($data, \BO\Zmsentities\Workstation $workstation): bool
87    {
88        if (isset($workstation->useraccount)) {
89            $formData = $data->getValues();
90            $workstation->setValidatedName($formData);
91            $workstation->setValidatedHint($formData);
92            $workstation->setValidatedScope($formData);
93            $workstation->setValidatedAppointmentsOnly($formData);
94            unset($workstation->useraccount['departments']);
95            $result = \App::$http->readPostResult('/workstation/', $workstation)->getEntity();
96        }
97        return ($result) ? true : false;
98    }
99}