1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RobsonSuzin\Smodal; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Smodal |
7
|
|
|
* @package Source\Support |
8
|
|
|
*/ |
9
|
|
|
class Smodal |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var |
14
|
|
|
*/ |
15
|
|
|
private $smodalname; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var |
19
|
|
|
*/ |
20
|
|
|
private $sdebug; |
21
|
|
|
/** |
22
|
|
|
* @var |
23
|
|
|
*/ |
24
|
|
|
private $smodaltype; |
25
|
|
|
/** |
26
|
|
|
* @var |
27
|
|
|
*/ |
28
|
|
|
private $smodalhtml; |
29
|
|
|
/** |
30
|
|
|
* @var |
31
|
|
|
*/ |
32
|
|
|
private $smodalwidth; |
33
|
|
|
/** |
34
|
|
|
* @var |
35
|
|
|
*/ |
36
|
|
|
private $smodalprint; |
37
|
|
|
/** |
38
|
|
|
* @var |
39
|
|
|
*/ |
40
|
|
|
private $smodaleffect; |
41
|
|
|
/** |
42
|
|
|
* @var |
43
|
|
|
*/ |
44
|
|
|
private $smodaldata; |
45
|
|
|
/** |
46
|
|
|
* @var |
47
|
|
|
*/ |
48
|
|
|
private $sadddata; |
49
|
|
|
/** |
50
|
|
|
* @var |
51
|
|
|
*/ |
52
|
|
|
private $sremovedata; |
53
|
|
|
/** |
54
|
|
|
* @var |
55
|
|
|
*/ |
56
|
|
|
private $saddattr; |
57
|
|
|
/** |
58
|
|
|
* @var |
59
|
|
|
*/ |
60
|
|
|
private $sremoveattr; |
61
|
|
|
/** |
62
|
|
|
* @var |
63
|
|
|
*/ |
64
|
|
|
private $saddhtml; |
65
|
|
|
/** |
66
|
|
|
* @var |
67
|
|
|
*/ |
68
|
|
|
private $saddclass; |
69
|
|
|
/** |
70
|
|
|
* @var |
71
|
|
|
*/ |
72
|
|
|
private $sremoveclass; |
73
|
|
|
/** |
74
|
|
|
* @var |
75
|
|
|
*/ |
76
|
|
|
private $sremoveelement; |
77
|
|
|
/** |
78
|
|
|
* @var |
79
|
|
|
*/ |
80
|
|
|
private $saddcss; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var |
84
|
|
|
*/ |
85
|
|
|
private $resultstring; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Smodal constructor. |
89
|
|
|
*/ |
90
|
|
|
public function __construct(string $smodalname = 'app_modal_dialog') |
91
|
|
|
{ |
92
|
|
|
$this->setSmodalname($smodalname); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $smodalname |
97
|
|
|
* @return Smodal |
98
|
|
|
*/ |
99
|
|
|
public function setSmodalname(string $smodalname): Smodal |
100
|
|
|
{ |
101
|
|
|
$this->smodalname = $smodalname; |
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param bool $sdebug |
107
|
|
|
* @return Smodal |
108
|
|
|
*/ |
109
|
|
|
public function setSdebug(bool $sdebug): Smodal |
110
|
|
|
{ |
111
|
|
|
$this->sdebug = $sdebug; |
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $smodaltype |
117
|
|
|
* @return Smodal |
118
|
|
|
*/ |
119
|
|
|
public function setSmodaltype(string $smodaltype): Smodal |
120
|
|
|
{ |
121
|
|
|
$this->smodaltype = $smodaltype; |
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param string $smodalhtml |
127
|
|
|
* @return Smodal |
128
|
|
|
*/ |
129
|
|
|
public function setSmodalhtml(string $smodalhtml): Smodal |
130
|
|
|
{ |
131
|
|
|
$this->smodalhtml = $smodalhtml; |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param int $smodalwidth |
137
|
|
|
* @return Smodal |
138
|
|
|
*/ |
139
|
|
|
public function setSmodalwidth(int $smodalwidth): Smodal |
140
|
|
|
{ |
141
|
|
|
$this->smodalwidth = $smodalwidth; |
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param string $smodalprint |
148
|
|
|
* @return Smodal |
149
|
|
|
*/ |
150
|
|
|
public function setSmodalprint(string $smodalprint): Smodal |
151
|
|
|
{ |
152
|
|
|
$this->smodalprint = $smodalprint; |
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $smodaleffect |
159
|
|
|
* @return Smodal |
160
|
|
|
*/ |
161
|
|
|
public function setSmodaleffect(string $smodaleffect): Smodal |
162
|
|
|
{ |
163
|
|
|
$this->smodaleffect = $smodaleffect; |
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param string $smodaldata |
169
|
|
|
* @return Smodal |
170
|
|
|
*/ |
171
|
|
|
public function setSmodaldata(string $smodaldata): Smodal |
172
|
|
|
{ |
173
|
|
|
$this->smodaldata = $smodaldata; |
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string $element |
180
|
|
|
* @param string $data |
181
|
|
|
* @param string $value |
182
|
|
|
* @return Smodal |
183
|
|
|
*/ |
184
|
|
|
public function setSadddata(string $element, string $data, string $value): Smodal |
185
|
|
|
{ |
186
|
|
|
$this->sadddata[] = [$element => [$data => $value]]; |
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $element |
192
|
|
|
* @param string $data |
193
|
|
|
* @return Smodal |
194
|
|
|
*/ |
195
|
|
|
public function setSremovedata(string $element, string $data): Smodal |
196
|
|
|
{ |
197
|
|
|
$this->sremovedata[] = [$element => $data]; |
198
|
|
|
return $this; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param string $element |
204
|
|
|
* @param string $attr |
205
|
|
|
* @param string $value |
206
|
|
|
* @return Smodal |
207
|
|
|
*/ |
208
|
|
|
public function setSaddattr(string $element, string $attr, string $value): Smodal |
209
|
|
|
{ |
210
|
|
|
$this->saddattr[] = [$element => [$attr => $value]]; |
211
|
|
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param string $element |
217
|
|
|
* @param string $attr |
218
|
|
|
* @return Smodal |
219
|
|
|
*/ |
220
|
|
|
public function setSremoveattr(string $element, string $attr): Smodal |
221
|
|
|
{ |
222
|
|
|
$this->sremoveattr[] = [$element => $attr]; |
223
|
|
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param string $element |
229
|
|
|
* @param string $value |
230
|
|
|
* @return Smodal |
231
|
|
|
*/ |
232
|
|
|
public function setSaddhtml(string $element, string $value): Smodal |
233
|
|
|
{ |
234
|
|
|
$this->saddhtml[] = [$element => $value]; |
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @param string $element |
241
|
|
|
* @param string $class |
242
|
|
|
* @return Smodal |
243
|
|
|
*/ |
244
|
|
|
public function setSaddclass(string $element, string $class): Smodal |
245
|
|
|
{ |
246
|
|
|
$this->saddclass[] = [$element => $class]; |
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param string $element |
253
|
|
|
* @param string $class |
254
|
|
|
* @return Smodal |
255
|
|
|
*/ |
256
|
|
|
public function setSremoveclass(string $element, string $class): Smodal |
257
|
|
|
{ |
258
|
|
|
$this->sremoveclass[] = [$element => $class]; |
259
|
|
|
return $this; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @param string $element |
265
|
|
|
* @return Smodal |
266
|
|
|
*/ |
267
|
|
|
public function setSremoveelement(string $element): Smodal |
268
|
|
|
{ |
269
|
|
|
$this->sremoveelement = $element; |
270
|
|
|
return $this; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param string $element |
276
|
|
|
* @param string $css |
277
|
|
|
* @param string $value |
278
|
|
|
* @return Smodal |
279
|
|
|
*/ |
280
|
|
|
public function setSaddcss(string $element, string $css, string $value): Smodal |
281
|
|
|
{ |
282
|
|
|
$this->saddcss[] = [$element => [$css => $value]]; |
283
|
|
|
return $this; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @param mixed $resultstring |
288
|
|
|
*/ |
289
|
|
|
public function setResultstring($resultstring): void |
290
|
|
|
{ |
291
|
|
|
$this->resultstring = $resultstring; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @return mixed |
296
|
|
|
*/ |
297
|
|
|
private function getResultstring(): ?string |
298
|
|
|
{ |
299
|
|
|
return $this->resultstring; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @return string |
304
|
|
|
*/ |
305
|
|
|
public function renderString(): string |
306
|
|
|
{ |
307
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('smodalname')); |
308
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('smodaltype')); |
309
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('smodalhtml')); |
310
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('smodalwidth')); |
311
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('smodalprint')); |
312
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('smodaleffect')); |
313
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('smodaldata')); |
314
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('sadddata')); |
315
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('sremovedata')); |
316
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('saddattr')); |
317
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('sremoveattr')); |
318
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('saddhtml')); |
319
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('saddclass')); |
320
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('sremoveclass')); |
321
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('sremoveelement')); |
322
|
|
|
$this->setResultstring($this->getResultstring() . $this->createString('saddcss')); |
323
|
|
|
|
324
|
|
|
return $this->getResultstring(); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @return object |
329
|
|
|
*/ |
330
|
|
|
public function renderObject(): object |
331
|
|
|
{ |
332
|
|
|
$smodal = new \stdClass(); |
333
|
|
|
$smodal->smodalname = $this->convertString($this->smodalname); |
334
|
|
|
$smodal->smodaltype = $this->convertString($this->smodaltype); |
335
|
|
|
$smodal->smodalhtml = $this->convertString($this->smodalhtml); |
336
|
|
|
$smodal->smodalwidth = $this->convertString($this->smodalwidth); |
337
|
|
|
$smodal->smodalprint = $this->convertString($this->smodalprint); |
338
|
|
|
$smodal->smodaleffect = $this->convertString($this->smodaleffect); |
339
|
|
|
$smodal->smodaldata = $this->convertString($this->smodaldata); |
340
|
|
|
$smodal->sadddata = $this->convertString($this->sadddata); |
341
|
|
|
$smodal->sremovedata = $this->convertString($this->sremovedata); |
342
|
|
|
$smodal->saddattr = $this->convertString($this->saddattr); |
343
|
|
|
$smodal->sremoveattr = $this->convertString($this->sremoveattr); |
344
|
|
|
$smodal->saddhtml = $this->convertString($this->saddhtml); |
345
|
|
|
$smodal->saddclass = $this->convertString($this->saddclass); |
346
|
|
|
$smodal->sremoveclass = $this->convertString($this->sremoveclass); |
347
|
|
|
$smodal->sremoveelement = $this->convertString($this->sremoveelement); |
348
|
|
|
$smodal->saddcss = $this->convertString($this->saddcss); |
349
|
|
|
$smodal->sdebug = $this->sdebug; |
350
|
|
|
return $smodal; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @param $name |
355
|
|
|
* @return string |
356
|
|
|
*/ |
357
|
|
|
private function createString($name): ?string |
358
|
|
|
{ |
359
|
|
|
$result = ""; |
360
|
|
|
if ($this->$name) { |
361
|
|
|
$result = "{$name}='{$this->convertString($this->$name)}' "; |
362
|
|
|
$this->setResultstring($this->getResultstring() . $result); |
363
|
|
|
} |
364
|
|
|
return $result; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @param $options |
369
|
|
|
* @return string|null |
370
|
|
|
*/ |
371
|
|
|
private function convertStringForeach($options): ?string |
372
|
|
|
{ |
373
|
|
|
$result = ''; |
374
|
|
|
foreach ($options as $option) { |
375
|
|
|
foreach ($option as $subkey => $subvalue) { |
376
|
|
|
if (is_int($subkey)) { |
377
|
|
|
$result .= "{$subvalue}|"; |
378
|
|
|
} else { |
379
|
|
|
if (!is_array($subvalue)) { |
380
|
|
|
$result .= "{$subkey}::{$subvalue}|"; |
381
|
|
|
} else { |
382
|
|
|
foreach ($subvalue as $ssbkey => $ssvalue) { |
383
|
|
|
|
384
|
|
|
$result .= "{$subkey}::{$ssbkey}=={$ssvalue}|"; |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
} |
390
|
|
|
return $result; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* @param $options |
395
|
|
|
* @return string |
396
|
|
|
*/ |
397
|
|
|
private function convertString($options): string |
398
|
|
|
{ |
399
|
|
|
|
400
|
|
|
$result = ""; |
401
|
|
|
if (!is_array($options)) { |
402
|
|
|
$result .= $options; |
403
|
|
|
} else { |
404
|
|
|
$result .= $this->convertStringForeach($options); |
405
|
|
|
$result = substr($result, 0, -1); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
return $result; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
|
412
|
|
|
} |