FormFlags   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
c 1
b 0
f 0
dl 0
loc 119
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 0 3 1
A isSet() 0 3 1
A getButtonFlags() 0 4 1
A getFlags() 0 3 1
A remove() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SKien\Formgenerator;
5
6
/**
7
 * Class to handle all the different flags to control the form elements.
8
 *
9
 * @package Formgenerator
10
 * @author Stefanius <[email protected]>
11
 * @copyright MIT License - see the LICENSE file for details
12
 */
13
class FormFlags
14
{
15
    /** mandatory/required field. Attribute 'required' is set    */
16
    const   MANDATORY               = 0x0000001;
17
    /** mandatory/required field. Attribute 'required' is set    */
18
    const   REQUIRED                = 0x0000001;
19
    /** hidden field    */
20
    const   HIDDEN                  = 0x0000002;
21
    /** readonly field  */
22
    const   READ_ONLY               = 0x0000004;
23
    /** right text-align (buttons: align of the button)   */
24
    const   ALIGN_RIGHT             = 0x0000008;
25
    /** field is extended with DTU (Date-Time-User) Button  */
26
    const   ADD_DTU                 = 0x0000010;
27
    /** field is extendet with selectbutton (click calls javascript function OnSelect(strField) with fieldname    */
28
    const   ADD_SELBTN              = 0x0000020;
29
    /** static field is displayed as hint (set CSS class `.hint`)  */
30
    const   HINT                    = 0x0000040;
31
    /** static field is displayed as error (set CSS class `.error`)   */
32
    const   ERROR                   = 0x0000080;
33
    /** button with selectlist  */
34
    const   SELECT_BTN              = 0x0000100;
35
    /** display value for range/progress/meter element  */
36
    const   SHOW_VALUE              = 0x0000100;
37
    /** connect edit/image with filemanager   */
38
    const   BROWSE_SERVER           = 0x0000200;
39
    /** field is disabled   */
40
    const   DISABLED                = 0x0000400;
41
    /** display static field as info (set CSS class `.info`)    */
42
    const   INFO                    = 0x0000800;
43
    /** center text-align (buttons: align of the button)   */
44
    const   ALIGN_CENTER            = 0x0001000;
45
    /** field is extended with Calendar-Button for datepicker    */
46
    const   ADD_DATE_PICKER         = 0x0002000;
47
    /** field is extended with Clock-Button for timepicker  */
48
    const   ADD_TIME_PICKER         = 0x0004000;
49
    /** suppress zero-values    */
50
    const   NO_ZERO                 = 0x0008000;
51
    /** input for password    */
52
    const   PASSWORD                = 0x0010000;
53
    /** file input  */
54
    const   FILE                    = 0x0020000;
55
    /** add Currency - Suffix    */
56
    const   ADD_CUR                 = 0x0040000;
57
    /** trim content (leading / trailing blanks)    */
58
    const   TRIM                    = 0x0080000;
59
    /** set data for CKEdit through JS  */
60
    const   SET_JSON_DATA           = 0x0200000;
61
    /** font-weight: bold   */
62
    const   BOLD                    = 0x0400000;
63
    /** replace '&lt;br/&gt;' / '&lt;br&gt; with CR */
64
    const   REPLACE_BR_CR           = 0x0800000;
65
    /** arrange radio - buttons horizontal in a row */
66
    const   HORZ_ARRANGE            = 0x1000000;
67
    /** allow multi selection */
68
    const   MULTI_SELECT            = 0x0200000;
69
70
    /** @var integer the flags specified     */
71
    protected int $wFlags = 0;
72
73
    /**
74
     * create a flag object
75
     * @param int $wFlags   any combination of FormFlag constants
76
     */
77
    public function __construct(int $wFlags = 0)
78
    {
79
        $this->wFlags = $wFlags;
80
    }
81
82
    /**
83
     * Get current flags.
84
     * @return int
85
     * @internal
86
     */
87
    public function getFlags() : int
88
    {
89
        return $this->wFlags;
90
    }
91
92
    /**
93
     * Add specified flags.
94
     * @param int $wFlags
95
     * @internal
96
     */
97
    public function add(int $wFlags) : void
98
    {
99
        $this->wFlags |= $wFlags;
100
    }
101
102
    /**
103
     * Remove specified flag(s).
104
     * @param int $wFlags
105
     * @internal
106
     */
107
    public function remove(int $wFlags) : void
108
    {
109
        $this->wFlags &= ~$wFlags;
110
    }
111
112
    /**
113
     * Check if one of the requested flags is set.
114
     * @param int $wFlags
115
     * @return bool
116
     * @internal
117
     */
118
    public function isSet(int $wFlags) : bool
119
    {
120
        return ($this->wFlags & $wFlags) != 0;
121
    }
122
123
    /**
124
     * Check if one of the selectbutton - flags is specified.
125
     * @return int
126
     * @internal
127
     */
128
    public function getButtonFlags() : int
129
    {
130
        $wButtonFlags = FormFlags::ADD_DTU | FormFlags::ADD_TIME_PICKER | FormFlags::ADD_DATE_PICKER | FormFlags::ADD_SELBTN | FormFlags::BROWSE_SERVER;
131
        return ($this->wFlags & $wButtonFlags);
132
    }
133
}
134
135