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: * Flexible and nicer details or info message boxes
19: * to draw attention to important information.
20: *
21: * <code>
22: * <?php
23: * echo $this->Cakestrap->CallOut()
24: * ->options(['type' => 'bs-callout-info'])
25: * ->title("Note")
26: * ->content("This callout needs your attention, but it's not super important.")
27: * ->set()
28: * ?>
29: * </code>
30: *
31: * @method options(array $options)
32: * @method title(string $title)
33: * @method content(string $content)
34: *
35: * @package Cakestrap\View\Helper
36: */
37:
38: class CallOutHelper extends Basic
39: {
40: /**
41: * Default helper options.
42: * These options are merged with the user-provided options.
43: *
44: * @var array
45: */
46: public $_options = [
47: 'type' => 'bs-callout-info'
48: ];
49:
50: /**
51: * Set all defined values.
52: * This will return the final html template.
53: *
54: * @return string $container
55: */
56: public function set()
57: {
58: $this->_setTitle();
59: $this->_setContent();
60:
61: $this->_addToContainer();
62: $this->_reset();
63:
64: return $this->_container;
65: }
66:
67: /**
68: * Add callout items to parent container
69: *
70: * @return void
71: */
72: protected function _addToContainer()
73: {
74: $contents = $this->_contents();
75: $this->_container = $this->_stringTemplate->format('container', [
76: 'container' => $contents,
77: 'type' => $this->_options['type']
78: ]);
79: }
80:
81: /**
82: * Set the template for callout title
83: *
84: * @return void
85: */
86: protected function _setTitle()
87: {
88: $this->_contents[] = $this->_stringTemplate->format('title', ['title'=>$this->title]);
89: }
90:
91: /**
92: * Set the template for callout contents
93: *
94: * @return void
95: */
96: protected function _setContent()
97: {
98: $this->_contents[] = $this->_stringTemplate->format('content', ['content'=>$this->content]);
99: }
100:
101: /**
102: * Extract and merge the callout contents
103: *
104: * @return void
105: */
106: protected function _contents()
107: {
108: $contents = implode("", $this->_contents);
109:
110: return $contents;
111: }
112: }