FileSetter::setDescriptionContainerId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Itstructure\MFU\Views;
4
5
/**
6
 * Class FileSetter
7
 * @package Itstructure\MFU\Views
8
 */
9
class FileSetter
10
{
11
    /************************* CONFIG ATTRIBUTES *************************/
12
    /**
13
     * @var string
14
     */
15
    private $attribute;
16
17
    /**
18
     * @var mixed
19
     */
20
    private $value;
21
22
    /**
23
     * @var string|int
24
     */
25
    private $inputId;
26
27
    /**
28
     * @var string|int
29
     */
30
    private $openButtonId;
31
32
    /**
33
     * @var string
34
     */
35
    private $openButtonName = 'Browse';
36
37
    /**
38
     * @var string
39
     */
40
    private $clearButtonName = 'Clear';
41
42
    /**
43
     * @var bool
44
     */
45
    private $deleteBoxDisplay = false;
46
47
    /**
48
     * @var string
49
     */
50
    private $deleteBoxName = 'Delete';
51
52
    /**
53
     * @var string
54
     */
55
    private $deleteBoxAttribute = 'delete[]';
56
57
    /**
58
     * @var int
59
     */
60
    private $deleteBoxValue = 1;
61
62
    /**
63
     * @var string
64
     */
65
    private $mediafileContainerId;
66
67
    /**
68
     * @var string
69
     */
70
    private $titleContainerId;
71
72
    /**
73
     * @var string
74
     */
75
    private $descriptionContainerId;
76
77
    /**
78
     * @var string
79
     */
80
    private $callbackBeforeInsert = '';
81
82
    /**
83
     * @var string
84
     */
85
    private $ownerName;
86
87
    /**
88
     * @var int
89
     */
90
    private $ownerId;
91
92
    /**
93
     * @var string
94
     */
95
    private $ownerAttribute;
96
97
    /**
98
     * @var string
99
     */
100
    private $neededFileType;
101
102
    /**
103
     * @var string
104
     */
105
    private $subDir;
106
107
108
    /************************* PROCESS ATTRIBUTES *************************/
109
    /**
110
     * @var int
111
     */
112
    public static $counter = 0;
113
114
    /**
115
     * @var string
116
     */
117
    public static $autoInputIdPrefix = 'w';
118
119
120
    /********************** PROCESS PUBLIC METHODS ***********************/
121
    /**
122
     * @param array $config
123
     * @return FileSetter
124
     */
125
    public static function getInstance(array $config): self
126
    {
127
        $obj = new static();
128
        foreach ($config as $key => $value) {
129
            $obj->{'set' . ucfirst($key)}($value);
130
        }
131
        return $obj;
132
    }
133
134
    /**
135
     * @param array $config
136
     * @return string
137
     */
138
    public static function run(array $config)
139
    {
140
        return static::getInstance($config)->render();
141
    }
142
143
    /**
144
     * @return string
145
     */
146
    public function render(): string
147
    {
148
        return view('uploader::file_setter.index', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('uploader::f...his->subDir))->render() could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
149
            'attribute' => $this->attribute,
150
            'value' => $this->value,
151
            'inputId' => $this->getInputId(),
152
            'openButtonId' => $this->getOpenButtonId(),
153
            'openButtonName' => $this->openButtonName,
154
            'clearButtonName' => $this->clearButtonName,
155
            'deleteBoxDisplay' => $this->deleteBoxDisplay,
156
            'deleteBoxName' => $this->deleteBoxName,
157
            'deleteBoxAttribute' => $this->deleteBoxAttribute,
158
            'deleteBoxValue' => $this->deleteBoxValue,
159
            'mediafileContainerId' => $this->mediafileContainerId,
160
            'titleContainerId' => $this->titleContainerId,
161
            'descriptionContainerId' => $this->descriptionContainerId,
162
            'callbackBeforeInsert' => $this->callbackBeforeInsert,
163
            'ownerName' => $this->ownerName,
164
            'ownerId' => $this->ownerId,
165
            'ownerAttribute' => $this->ownerAttribute,
166
            'neededFileType' => $this->neededFileType,
167
            'subDir' => $this->subDir
168
        ])->render();
169
    }
170
171
172
    /************************* CONFIG SETTERS *****************************/
173
    /**
174
     * @param string $attribute
175
     * @return FileSetter
176
     */
177
    public function setAttribute(string $attribute): self
178
    {
179
        $this->attribute = $attribute;
180
        return $this;
181
    }
182
183
    /**
184
     * @param $value
185
     * @return FileSetter
186
     */
187
    public function setValue($value): self
188
    {
189
        $this->value = $value;
190
        return $this;
191
    }
192
193
    /**
194
     * @param string $value
195
     * @return FileSetter
196
     */
197
    public function setInputId(string $value): self
198
    {
199
        $this->inputId = $value;
200
        return $this;
201
    }
202
203
    /**
204
     * @param string $openButtonId
205
     * @return FileSetter
206
     */
207
    public function setOpenButtonId(string $openButtonId): self
208
    {
209
        $this->openButtonId = $openButtonId;
210
        return $this;
211
    }
212
213
    /**
214
     * @param string $openButtonName
215
     * @return FileSetter
216
     */
217
    public function setOpenButtonName(string $openButtonName): self
218
    {
219
        $this->openButtonName = $openButtonName;
220
        return $this;
221
    }
222
223
    /**
224
     * @param string $clearButtonName
225
     * @return FileSetter
226
     */
227
    public function setClearButtonName(string $clearButtonName): self
228
    {
229
        $this->clearButtonName = $clearButtonName;
230
        return $this;
231
    }
232
233
    /**
234
     * @param bool $deleteBoxDisplay
235
     * @return FileSetter
236
     */
237
    public function setDeleteBoxDisplay(bool $deleteBoxDisplay): self
238
    {
239
        $this->deleteBoxDisplay = $deleteBoxDisplay;
240
        return $this;
241
    }
242
243
    /**
244
     * @param string $deleteBoxName
245
     * @return FileSetter
246
     */
247
    public function setDeleteBoxName(string $deleteBoxName): self
248
    {
249
        $this->deleteBoxName = $deleteBoxName;
250
        return $this;
251
    }
252
253
    /**
254
     * @param string $deleteBoxAttribute
255
     * @return FileSetter
256
     */
257
    public function setDeleteBoxAttribute(string $deleteBoxAttribute): self
258
    {
259
        $this->deleteBoxAttribute = $deleteBoxAttribute;
260
        return $this;
261
    }
262
263
    /**
264
     * @param mixed $deleteBoxValue
265
     * @return FileSetter
266
     */
267
    public function setDeleteBoxValue($deleteBoxValue): self
268
    {
269
        $this->deleteBoxValue = $deleteBoxValue;
270
        return $this;
271
    }
272
273
    /**
274
     * @param string $mediafileContainerId
275
     * @return FileSetter
276
     */
277
    public function setMediafileContainerId(string $mediafileContainerId): self
278
    {
279
        $this->mediafileContainerId = $mediafileContainerId;
280
        return $this;
281
    }
282
283
    /**
284
     * @param string $titleContainerId
285
     * @return FileSetter
286
     */
287
    public function setTitleContainerId(string $titleContainerId): self
288
    {
289
        $this->titleContainerId = $titleContainerId;
290
        return $this;
291
    }
292
293
    /**
294
     * @param string $descriptionContainerId
295
     * @return FileSetter
296
     */
297
    public function setDescriptionContainerId(string $descriptionContainerId): self
298
    {
299
        $this->descriptionContainerId = $descriptionContainerId;
300
        return $this;
301
    }
302
303
    /**
304
     * @param string $callbackBeforeInsert
305
     * @return FileSetter
306
     */
307
    public function setCallbackBeforeInsert(string $callbackBeforeInsert): self
308
    {
309
        $this->callbackBeforeInsert = $callbackBeforeInsert;
310
        return $this;
311
    }
312
313
    /**
314
     * @param string $ownerName
315
     * @return FileSetter
316
     */
317
    public function setOwnerName(string $ownerName): self
318
    {
319
        $this->ownerName = $ownerName;
320
        return $this;
321
    }
322
323
    /**
324
     * @param int $ownerId
325
     * @return FileSetter
326
     */
327
    public function setOwnerId(int $ownerId): self
328
    {
329
        $this->ownerId = $ownerId;
330
        return $this;
331
    }
332
333
    /**
334
     * @param string $ownerAttribute
335
     * @return FileSetter
336
     */
337
    public function setOwnerAttribute(string $ownerAttribute): self
338
    {
339
        $this->ownerAttribute = $ownerAttribute;
340
        return $this;
341
    }
342
343
    /**
344
     * @param string|null $neededFileType
345
     * @return FileSetter
346
     */
347
    public function setNeededFileType(?string $neededFileType): self
348
    {
349
        $this->neededFileType = $neededFileType;
350
        return $this;
351
    }
352
353
    /**
354
     * @param null|string $subDir
355
     * @return FileSetter
356
     */
357
    public function setSubDir(?string $subDir): self
358
    {
359
        $this->subDir = $subDir;
360
        return $this;
361
    }
362
363
364
    /********************** PROCESS INTERNAL METHODS *********************/
365
    /**
366
     * @return string
367
     */
368
    private function getInputId(): string
369
    {
370
        if (empty($this->inputId)) {
371
            $this->inputId = $this->getInputIdGenerated();
372
        }
373
        return $this->inputId;
374
    }
375
376
    /**
377
     * @return string
378
     */
379
    private function getInputIdGenerated(): string
380
    {
381
        return static::$autoInputIdPrefix . static::$counter++;
382
    }
383
384
    /**
385
     * @return string
386
     */
387
    private function getOpenButtonId(): string
388
    {
389
        if (empty($this->openButtonId)) {
390
            $this->openButtonId = $this->inputId . '-btn';
391
        }
392
        return $this->openButtonId;
393
    }
394
}
395