summaryrefslogtreecommitdiffstats
path: root/library/Director/Field/FieldSpec.php
blob: 29baa0bcae7869ac325d105ee96f3fbf0e334664 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php


namespace Icinga\Module\Director\Field;

use Icinga\Module\Director\Objects\DirectorDatafield;
use Icinga\Module\Director\Objects\IcingaObject;

class FieldSpec
{
    /** @var string */
    protected $varName;

    /** @var string */
    protected $category;

    /** @var string */
    protected $caption;

    /** @var boolean */
    protected $isRequired = false;

    /** @var string */
    protected $description;

    /** @var string */
    protected $dataType;

    /** @var string */
    protected $varFilter;

    /** @var string */
    protected $format = "string";

    /**
     * FieldSpec constructor.
     * @param $dataType
     * @param $varName
     * @param $caption
     */
    public function __construct($dataType, $varName, $caption)
    {
        $this->dataType = $dataType;
        $this->varName = $varName;
        $this->caption = $caption;
    }

    public function toDataField(IcingaObject $object)
    {
        return DirectorDatafield::create([
            'varname'     => $this->getVarName(),
            'category'    => $this->getCategory(),
            'caption'     => $this->getCaption(),
            'description' => $this->getDescription(),
            'datatype'    => $this->getDataType(),
            'format'      => $this->getFormat(),
            'var_filter'  => $this->getVarFilter(),
            'icinga_type' => $object->getShortTableName(),
            'object_id'   => $object->get('id'),
        ]);
    }

    /**
     * @return string
     */
    public function getVarName()
    {
        return $this->varName;
    }

    /**
     * @param string $varName
     * @return FieldSpec
     */
    public function setVarName($varName)
    {
        $this->varName = $varName;
        return $this;
    }

    /**
     * @return string
     */
    public function getCaption()
    {
        return $this->caption;
    }

    /**
     * @param string $caption
     * @return FieldSpec
     */
    public function setCaption($caption)
    {
        $this->caption = $caption;
        return $this;
    }

    /**
     * @return bool
     */
    public function isRequired()
    {
        return $this->isRequired;
    }

    /**
     * @param bool $isRequired
     * @return FieldSpec
     */
    public function setIsRequired($isRequired)
    {
        $this->isRequired = $isRequired;
        return $this;
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @param string $description
     * @return FieldSpec
     */
    public function setDescription($description)
    {
        $this->description = $description;
        return $this;
    }

    /**
     * @return string
     */
    public function getDataType()
    {
        return $this->dataType;
    }

    /**
     * @param string $dataType
     * @return FieldSpec
     */
    public function setDataType($dataType)
    {
        $this->dataType = $dataType;
        return $this;
    }

    /**
     * @return string
     */
    public function getVarFilter()
    {
        return $this->varFilter;
    }

    /**
     * @param string $varFilter
     * @return FieldSpec
     */
    public function setVarFilter($varFilter)
    {
        $this->varFilter = $varFilter;
        return $this;
    }

    /**
     * @return string
     */
    public function getFormat()
    {
        return $this->format;
    }

    /**
     * @param string $format
     * @return FieldSpec
     */
    public function setFormat($format)
    {
        $this->format = $format;
        return $this;
    }

    /**
     * @return string
     */
    public function getCategory()
    {
        return $this->category;
    }

    /**
     * @param string $category
     * @return FieldSpec
     */
    public function setCategory($category)
    {
        $this->category = $category;
        return $this;
    }
}