1 | <?php |
||
49 | class ModalBuilder { |
||
50 | |||
51 | /** |
||
52 | * @var string $content |
||
53 | */ |
||
54 | private $content; |
||
55 | |||
56 | /** |
||
57 | * @var string|false $footer |
||
58 | */ |
||
59 | private $footer; |
||
60 | |||
61 | /** |
||
62 | * @var string|false $header |
||
63 | */ |
||
64 | private $header; |
||
65 | |||
66 | /** |
||
67 | * @var string $id |
||
68 | */ |
||
69 | private $id; |
||
70 | |||
71 | /** |
||
72 | * @var string|false $bodyClass |
||
73 | */ |
||
74 | private $bodyClass; |
||
75 | |||
76 | /** |
||
77 | * @var string|false $bodyStyle |
||
78 | */ |
||
79 | private $bodyStyle; |
||
80 | |||
81 | /** |
||
82 | * @var string|false $dialogClass |
||
83 | */ |
||
84 | private $dialogClass; |
||
85 | |||
86 | /** |
||
87 | * @var string|false $dialogStyle |
||
88 | */ |
||
89 | private $dialogStyle; |
||
90 | |||
91 | /** |
||
92 | * @var string|false $outerClass |
||
93 | */ |
||
94 | private $outerClass; |
||
95 | |||
96 | /** |
||
97 | * @var string|false $outerStyle |
||
98 | */ |
||
99 | private $outerStyle; |
||
100 | |||
101 | /** |
||
102 | * @var ParserOutputHelper $parserOutputHelper |
||
103 | */ |
||
104 | private $parserOutputHelper; |
||
105 | |||
106 | /** |
||
107 | * @var string $trigger |
||
108 | */ |
||
109 | private $trigger; |
||
110 | |||
111 | /** |
||
112 | * With this, you can wrap a generic trigger element inside a span block, that hopefully should |
||
113 | * work as a trigger for the modal |
||
114 | * |
||
115 | * @param string $element |
||
116 | * @param string $id |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | 7 | public static function wrapTriggerElement( $element, $id ) { |
|
131 | |||
132 | /** |
||
133 | * ModalBase constructor. |
||
134 | * |
||
135 | * Takes $id, $trigger and $content and produces a modal with the html id $id, using $content as the |
||
136 | * body content of the opening modal. For trigger, you can use a generic html code and wrap it in |
||
137 | * {@see \BootstrapComponents\ModalBase::wrapTriggerElement}, or you make sure you generate |
||
138 | * a correct trigger for yourself, using the necessary attributes and especially the id, you supplied |
||
139 | * here (see {@see \BootstrapComponents\Component\Modal::generateButton} for example). |
||
140 | * |
||
141 | * Do not instantiate directly, but use {@see ApplicationFactory::getModalBuilder} |
||
142 | * instead. |
||
143 | * |
||
144 | * @see ApplicationFactory::getModalBuilder |
||
145 | * @see \BootstrapComponents\Component\Modal::generateButton |
||
146 | * |
||
147 | * @param string $id |
||
148 | * @param string $trigger must be safe raw html (best run through {@see Parser::recursiveTagParse}) |
||
149 | * @param string $content must be fully parsed html (use {@see Parser::recursiveTagParseFully}) |
||
150 | * @param ParserOutputHelper $parserOutputHelper |
||
151 | */ |
||
152 | |||
153 | 9 | public function __construct( $id, $trigger, $content, $parserOutputHelper ) { |
|
159 | |||
160 | /** |
||
161 | * Parses the modal. |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | 8 | public function parse() { |
|
172 | |||
173 | /** |
||
174 | * Lets you set the class attribute for the modal body. The body is the element holding the content. |
||
175 | * |
||
176 | * @param string|false $bodyClass |
||
177 | * |
||
178 | * @return ModalBuilder |
||
179 | */ |
||
180 | public function setBodyClass( $bodyClass ) { |
||
184 | |||
185 | /** |
||
186 | * Lets you set the style attribute for the modal body. The body is the element holding the content. |
||
187 | * |
||
188 | * @param string|false $bodyStyle |
||
189 | * |
||
190 | * @return ModalBuilder |
||
191 | */ |
||
192 | public function setBodyStyle( $bodyStyle ) { |
||
196 | |||
197 | /** |
||
198 | * Lets you set the class attribute for the dialog part. The dialog is the container, holding header, body, and footer. |
||
199 | * The dialog is surrounded by the outer modal. See {@see ModalBuilder::setOuterClass}. |
||
200 | * |
||
201 | * @param string|false $dialogClass |
||
202 | * |
||
203 | * @return ModalBuilder |
||
204 | */ |
||
205 | 3 | public function setDialogClass( $dialogClass ) { |
|
209 | |||
210 | /** |
||
211 | * Lets you set the style attribute for the dialog part. The dialog is the container, holding header, body, and footer. |
||
212 | * The dialog is surrounded by the outer modal. See {@see ModalBuilder::setOuterClass}. |
||
213 | * |
||
214 | * @param string|false $dialogStyle |
||
215 | * |
||
216 | * @return ModalBuilder |
||
217 | */ |
||
218 | public function setDialogStyle( $dialogStyle ) { |
||
222 | |||
223 | /** |
||
224 | * Sets the content for the footer section. |
||
225 | * |
||
226 | * @param string|false $footer must be safe raw html (best run through {@see Parser::recursiveTagParse}) |
||
227 | * |
||
228 | * @return ModalBuilder |
||
229 | */ |
||
230 | 7 | public function setFooter( $footer ) { |
|
234 | |||
235 | /** |
||
236 | * Sets the content for the header section. |
||
237 | * |
||
238 | * @param string|false $header must be safe raw html (best run through {@see Parser::recursiveTagParse}) |
||
239 | * |
||
240 | * @return ModalBuilder |
||
241 | */ |
||
242 | 7 | public function setHeader( $header ) { |
|
246 | |||
247 | /** |
||
248 | * Lets you set the class attribute for the outermost modal container. |
||
249 | * |
||
250 | * @param string|false $outerClass |
||
251 | * |
||
252 | * @return ModalBuilder |
||
253 | */ |
||
254 | 3 | public function setOuterClass( $outerClass ) { |
|
258 | |||
259 | /** |
||
260 | * Lets you set the style attribute for the outermost modal container. |
||
261 | * |
||
262 | * @param string|false $outerStyle |
||
263 | * |
||
264 | * @return ModalBuilder |
||
265 | */ |
||
266 | 3 | public function setOuterStyle( $outerStyle ) { |
|
270 | |||
271 | /** |
||
272 | * From all the data passed by caller, this builds the dialog part (the one inside the modal holding the actual content). |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | 8 | protected function buildDialog() { |
|
301 | |||
302 | /** |
||
303 | * From all the data passed by caller, this builds the dialog part (the one that pops up when engaging the trigger). |
||
304 | * |
||
305 | * @return string |
||
306 | */ |
||
307 | 8 | protected function buildModal() { |
|
323 | |||
324 | /** |
||
325 | * Performs the necessary steps to convert the string passed by caller into a working trigger for the modal. |
||
326 | * |
||
327 | * @return string |
||
328 | */ |
||
329 | 8 | protected function buildTrigger() { |
|
339 | |||
340 | /** |
||
341 | * Used to merge different class attributes. |
||
342 | * |
||
343 | * @param string $baseClass |
||
344 | * @param string|false $additionalClass |
||
345 | * |
||
346 | * @return string |
||
347 | */ |
||
348 | 8 | protected function compileClass( $baseClass, $additionalClass ) { |
|
354 | |||
355 | /** |
||
356 | * @return string|false |
||
357 | */ |
||
358 | 8 | protected function getBodyClass() { |
|
361 | |||
362 | /** |
||
363 | * @return string|false |
||
364 | */ |
||
365 | 8 | protected function getBodyStyle() { |
|
368 | |||
369 | /** |
||
370 | * Build the modal, with all sections, requested content and necessary control elements. |
||
371 | * |
||
372 | * @return string |
||
373 | */ |
||
374 | 8 | protected function getContent() { |
|
377 | |||
378 | /** |
||
379 | * @return string|false |
||
380 | */ |
||
381 | 8 | protected function getDialogClass() { |
|
384 | |||
385 | /** |
||
386 | * @return string|false |
||
387 | */ |
||
388 | 8 | protected function getDialogStyle() { |
|
391 | |||
392 | /** |
||
393 | * @return string|false |
||
394 | */ |
||
395 | 8 | protected function getFooter() { |
|
398 | |||
399 | /** |
||
400 | * @return string|false |
||
401 | */ |
||
402 | 8 | protected function getHeader() { |
|
405 | |||
406 | /** |
||
407 | * @return string |
||
408 | */ |
||
409 | 8 | protected function getId() { |
|
412 | |||
413 | /** |
||
414 | * @return string|false |
||
415 | */ |
||
416 | 8 | protected function getOuterClass() { |
|
419 | |||
420 | /** |
||
421 | * @return string|false |
||
422 | */ |
||
423 | 8 | protected function getOuterStyle() { |
|
426 | |||
427 | /** |
||
428 | * Returns the supplied trigger. Wraps it with {@see ModalBuilder::wrapTriggerElement} if certain attributes are not detected. |
||
429 | * |
||
430 | * @return string |
||
431 | */ |
||
432 | 8 | protected function getTrigger() { |
|
435 | |||
436 | /** |
||
437 | * Generates the body section. |
||
438 | * |
||
439 | * @param string $content must be safe raw html (best run through {@see Parser::recursiveTagParse}) |
||
440 | * |
||
441 | * @return string |
||
442 | */ |
||
443 | 8 | private function generateBody( $content ) { |
|
453 | |||
454 | /** |
||
455 | * Generates the footer section. |
||
456 | * |
||
457 | * @param string|false $footer must be safe raw html (best run through {@see Parser::recursiveTagParse}) |
||
458 | * |
||
459 | * @return string |
||
460 | */ |
||
461 | 8 | private function generateFooter( $footer = '' ) { |
|
481 | |||
482 | /** |
||
483 | * Generates the header section together with the dismiss X and the heading, if provided. |
||
484 | * |
||
485 | * @param string|false $header must be safe raw html (best run through {@see Parser::recursiveTagParse}) |
||
486 | * |
||
487 | * @return string |
||
488 | */ |
||
489 | 8 | private function generateHeader( $header = '' ) { |
|
519 | } |