1: <?php
2: /**
3: * Copyright (c) CMNWorks
4: *
5: * Licensed under The MIT License
6: * For full copyright and license information, please see the LICENSE.txt
7: * Redistributions of files must retain the above copyright notice.
8: *
9: * @copyright Copyright (c) CMNWorks Christopher M. Natan
10: * @author Christopher M. Natan
11: * @link http://cmnworks.com
12: * @since 1.8.8
13: * @license http://www.opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cakestrap\View\Helper;
16:
17: /**
18: * Provide contextual feedback messages for typical user actions
19: * with the handful of available and flexible alert messages.
20: *
21: * <code>
22: * <?php
23: * echo $this->Cakestrap->Alert()
24: * ->options(['type' => 'alert-danger', 'dismissible' => true])
25: * ->content("<strong>Heads up!</strong> This alert needs your attention.")
26: * ->set()
27: * ?>
28: * </code>
29: *
30: * @method options(array $options)
31: * @method content(string $content)
32: *
33: * @package Cakestrap\View\Helper
34: * @link http://getbootstrap.com/components/#alerts
35: */
36: class AlertHelper extends Basic
37: {
38:
39: /**
40: * Constant dismissible
41: *
42: * @var string
43: */
44: const DISMISSIBLE = 'alert-dismissible';
45:
46: /**
47: * Default helper options.
48: * These options are merged with the user-provided options.
49: *
50: * @var array
51: */
52: public $_options = [
53: 'type' => 'alert-info',
54: 'dismissible' => false
55: ];
56:
57: /**
58: * Set all defined values.
59: * This will return the final html template.
60: *
61: * @return string
62: */
63: public function set()
64: {
65: $container = $this->_stringTemplate->format('container', [
66: 'container' => $this->content,
67: 'type' => $this->_options['type'],
68: 'dismissible' => $this->_isDismissible()['dismissible'],
69: 'button' => $this->_isDismissible()['button']
70: ]);
71: return $container;
72: }
73:
74: /**
75: * Assign dismissible settings.
76: *
77: * @return string | null
78: */
79: protected function _isDismissible()
80: {
81: if($this->_options['dismissible']) {
82: return [
83: 'button' => $this->_template['button'],
84: 'dismissible' => self::DISMISSIBLE
85: ];
86: }
87:
88: return ['button' => null, 'dismissible' => null];
89: }
90: }