robsonsuzin /
Smodal
| 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 $smodaltemplate; |
||
| 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 | * @var |
||
| 83 | */ |
||
| 84 | private $sfocus; |
||
| 85 | /** |
||
| 86 | * @var |
||
| 87 | */ |
||
| 88 | private $resultstring; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var |
||
| 92 | */ |
||
| 93 | private $methods; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Smodal constructor. |
||
| 97 | */ |
||
| 98 | public function __construct(string $smodalname = 'suzin_smodal_dialog') |
||
| 99 | { |
||
| 100 | $this->setSmodalname($smodalname); |
||
| 101 | |||
| 102 | $this->methods = [ |
||
| 103 | 'smodalname', |
||
| 104 | 'smodaltemplate', |
||
| 105 | 'smodalhtml', |
||
| 106 | 'smodalwidth', |
||
| 107 | 'smodalprint', |
||
| 108 | 'smodaleffect', |
||
| 109 | 'smodaldata', |
||
| 110 | 'sadddata', |
||
| 111 | 'sremovedata', |
||
| 112 | 'saddattr', |
||
| 113 | 'sremoveattr', |
||
| 114 | 'saddhtml', |
||
| 115 | 'saddclass', |
||
| 116 | 'sremoveclass', |
||
| 117 | 'sremoveelement', |
||
| 118 | 'saddcss', |
||
| 119 | 'sfocus', |
||
| 120 | 'sdebug' |
||
| 121 | ]; |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param string $smodalname |
||
| 126 | * @return Smodal |
||
| 127 | */ |
||
| 128 | public function setSmodalname(string $smodalname): Smodal |
||
| 129 | { |
||
| 130 | $this->smodalname = $smodalname; |
||
| 131 | return $this; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @param bool $sdebug |
||
| 136 | * @return Smodal |
||
| 137 | */ |
||
| 138 | public function setSdebug(bool $sdebug): Smodal |
||
| 139 | { |
||
| 140 | $this->sdebug = $sdebug; |
||
| 141 | return $this; |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @param string $smodaltemplate |
||
| 146 | * @return Smodal |
||
| 147 | */ |
||
| 148 | public function setSmodaltemplate(string $smodaltemplate): Smodal |
||
| 149 | { |
||
| 150 | $this->smodaltemplate = $smodaltemplate; |
||
| 151 | return $this; |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param string $smodaltemplate |
||
| 156 | * @return Smodal |
||
| 157 | * Função para ser retrocompativel |
||
| 158 | */ |
||
| 159 | public function setSmodaltype(string $smodaltemplate): Smodal |
||
| 160 | { |
||
| 161 | $this->smodaltemplate = $smodaltemplate; |
||
| 162 | return $this; |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @param string $smodalhtml |
||
| 167 | * @return Smodal |
||
| 168 | */ |
||
| 169 | public function setSmodalhtml(string $smodalhtml): Smodal |
||
| 170 | { |
||
| 171 | $this->smodalhtml = $smodalhtml; |
||
| 172 | return $this; |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @param int $smodalwidth |
||
| 177 | * @return Smodal |
||
| 178 | */ |
||
| 179 | public function setSmodalwidth(int $smodalwidth): Smodal |
||
| 180 | { |
||
| 181 | $this->smodalwidth = $smodalwidth; |
||
| 182 | return $this; |
||
| 183 | } |
||
| 184 | |||
| 185 | |||
| 186 | /** |
||
| 187 | * @param string $smodalprint |
||
| 188 | * @return Smodal |
||
| 189 | */ |
||
| 190 | public function setSmodalprint(bool $smodalprint): Smodal |
||
| 191 | { |
||
| 192 | $this->smodalprint = $smodalprint; |
||
| 193 | return $this; |
||
| 194 | } |
||
| 195 | |||
| 196 | |||
| 197 | /** |
||
| 198 | * @param string $smodaleffect |
||
| 199 | * @return Smodal |
||
| 200 | */ |
||
| 201 | public function setSmodaleffect(string $smodaleffect): Smodal |
||
| 202 | { |
||
| 203 | $this->smodaleffect = $smodaleffect; |
||
| 204 | return $this; |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param string $smodaldata |
||
| 209 | * @return Smodal |
||
| 210 | */ |
||
| 211 | public function setSmodaldata(string $smodaldata): Smodal |
||
| 212 | { |
||
| 213 | $this->smodaldata = $smodaldata; |
||
| 214 | return $this; |
||
| 215 | } |
||
| 216 | |||
| 217 | |||
| 218 | /** |
||
| 219 | * @param string $element |
||
| 220 | * @param string $data |
||
| 221 | * @param string $value |
||
| 222 | * @return Smodal |
||
| 223 | */ |
||
| 224 | public function setSadddata(string $element, string $data, string $value): Smodal |
||
| 225 | { |
||
| 226 | $this->sadddata[] = [$element => [$data => $value]]; |
||
| 227 | return $this; |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @param string $element |
||
| 232 | * @param string $data |
||
| 233 | * @return Smodal |
||
| 234 | */ |
||
| 235 | public function setSremovedata(string $element, string $data): Smodal |
||
| 236 | { |
||
| 237 | $this->sremovedata[] = [$element => $data]; |
||
| 238 | return $this; |
||
| 239 | } |
||
| 240 | |||
| 241 | |||
| 242 | /** |
||
| 243 | * @param string $element |
||
| 244 | * @param string $attr |
||
| 245 | * @param string $value |
||
| 246 | * @return Smodal |
||
| 247 | */ |
||
| 248 | public function setSaddattr(string $element, string $attr, string $value): Smodal |
||
| 249 | { |
||
| 250 | $this->saddattr[] = [$element => [$attr => $value]]; |
||
| 251 | return $this; |
||
| 252 | } |
||
| 253 | |||
| 254 | |||
| 255 | /** |
||
| 256 | * @param string $element |
||
| 257 | * @param string $attr |
||
| 258 | * @return Smodal |
||
| 259 | */ |
||
| 260 | public function setSremoveattr(string $element, string $attr): Smodal |
||
| 261 | { |
||
| 262 | $this->sremoveattr[] = [$element => $attr]; |
||
| 263 | return $this; |
||
| 264 | } |
||
| 265 | |||
| 266 | |||
| 267 | /** |
||
| 268 | * @param string $element |
||
| 269 | * @param string $value |
||
| 270 | * @return Smodal |
||
| 271 | */ |
||
| 272 | public function setSaddhtml(string $element, string $value): Smodal |
||
| 273 | { |
||
| 274 | $this->saddhtml[] = [$element => $value]; |
||
| 275 | return $this; |
||
| 276 | } |
||
| 277 | |||
| 278 | |||
| 279 | /** |
||
| 280 | * @param string $element |
||
| 281 | * @param string $class |
||
| 282 | * @return Smodal |
||
| 283 | */ |
||
| 284 | public function setSaddclass(string $element, string $class): Smodal |
||
| 285 | { |
||
| 286 | $this->saddclass[] = [$element => $class]; |
||
| 287 | return $this; |
||
| 288 | } |
||
| 289 | |||
| 290 | |||
| 291 | /** |
||
| 292 | * @param string $element |
||
| 293 | * @param string $class |
||
| 294 | * @return Smodal |
||
| 295 | */ |
||
| 296 | public function setSremoveclass(string $element, string $class): Smodal |
||
| 297 | { |
||
| 298 | $this->sremoveclass[] = [$element => $class]; |
||
| 299 | return $this; |
||
| 300 | } |
||
| 301 | |||
| 302 | |||
| 303 | /** |
||
| 304 | * @param string $element |
||
| 305 | * @return Smodal |
||
| 306 | */ |
||
| 307 | public function setSremoveelement(string $element): Smodal |
||
| 308 | { |
||
| 309 | $this->sremoveelement[] = [$element]; |
||
| 310 | return $this; |
||
| 311 | } |
||
| 312 | |||
| 313 | |||
| 314 | /** |
||
| 315 | * @param string $element |
||
| 316 | * @param string $css |
||
| 317 | * @param string $value |
||
| 318 | * @return Smodal |
||
| 319 | */ |
||
| 320 | public function setSaddcss(string $element, string $css, string $value): Smodal |
||
| 321 | { |
||
| 322 | $this->saddcss[] = [$element => [$css => $value]]; |
||
| 323 | return $this; |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @param string $element |
||
| 328 | * @param string $css |
||
| 329 | * @param string $value |
||
| 330 | * @return Smodal |
||
| 331 | */ |
||
| 332 | public function setSfocus(string $element): Smodal |
||
| 333 | { |
||
| 334 | $this->sfocus = $element; |
||
| 335 | return $this; |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param mixed $resultstring |
||
| 340 | */ |
||
| 341 | public function setResultstring($resultstring): void |
||
| 342 | { |
||
| 343 | $this->resultstring = $resultstring; |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @return mixed |
||
| 348 | */ |
||
| 349 | private function getResultstring(): ?string |
||
| 350 | { |
||
| 351 | return $this->resultstring; |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return string |
||
| 356 | */ |
||
| 357 | public function renderString(): string |
||
| 358 | { |
||
| 359 | foreach ($this->methods as $method) { |
||
| 360 | $this->setResultstring($this->getResultstring() . $this->createString($method)); |
||
| 361 | } |
||
| 362 | return $this->getResultstring(); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @return object |
||
| 367 | */ |
||
| 368 | public function renderObject(): object |
||
| 369 | { |
||
| 370 | $objectSmodal = new \stdClass(); |
||
| 371 | |||
| 372 | foreach ($this->methods as $method) { |
||
| 373 | $objectSmodal->$method = $this->convertString($this->$method); |
||
| 374 | } |
||
| 375 | $objectSmodal->sdebug = $this->sdebug; |
||
| 376 | return $objectSmodal; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @param $name |
||
| 381 | * @return string |
||
| 382 | */ |
||
| 383 | private function createString($name): ?string |
||
| 384 | { |
||
| 385 | $result = ""; |
||
| 386 | if ($this->$name) { |
||
| 387 | $result = "{$name}='{$this->convertString($this->$name)}' "; |
||
| 388 | $this->setResultstring($this->getResultstring() . $result); |
||
| 389 | } |
||
| 390 | return $result; |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @param $options |
||
| 395 | * @return string|null |
||
| 396 | */ |
||
| 397 | private function convertStringForeach($options): ?string |
||
| 398 | { |
||
| 399 | $result = ''; |
||
| 400 | foreach ($options as $option) { |
||
| 401 | foreach ($option as $subkey => $subvalue) { |
||
| 402 | if (is_int($subkey)) { |
||
| 403 | $result .= "{$subvalue}|"; |
||
| 404 | } else { |
||
| 405 | if (!is_array($subvalue)) { |
||
| 406 | $result .= "{$subkey}::{$subvalue}|"; |
||
| 407 | } else { |
||
| 408 | foreach ($subvalue as $ssbkey => $ssvalue) { |
||
| 409 | |||
| 410 | $result .= "{$subkey}::{$ssbkey}=={$ssvalue}|"; |
||
| 411 | } |
||
| 412 | } |
||
| 413 | } |
||
| 414 | } |
||
| 415 | } |
||
| 416 | return $result; |
||
| 417 | } |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @param $options |
||
| 421 | * @return string |
||
| 422 | */ |
||
| 423 | private function convertString($options): string |
||
| 424 | { |
||
| 425 | |||
| 426 | $result = ""; |
||
| 427 | if (!is_array($options)) { |
||
| 428 | $result .= $options; |
||
| 429 | } else { |
||
| 430 | $result .= $this->convertStringForeach($options); |
||
| 431 | $result = substr($result, 0, -1); |
||
| 432 | } |
||
| 433 | |||
| 434 | return $result; |
||
| 435 | } |
||
| 436 | |||
| 437 | |||
| 438 | } |