1 <?php
2 /**
3 * @copyright Copyright © 2amigOS! Consulting Group 2013-
4 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
5 * @package foundation.components
6 * @version 1.0.0
7 */
8 namespace foundation\helpers;
9
10 use foundation\enum\Enum;
11
12 /**
13 * Alert renders a Foundation alert
14 *
15 * @author Antonio Ramirez <amigo.cobos@gmail.com>
16 * @package foundation\helpers
17 */
18 class Alert
19 {
20 /**
21 * Generates a success alert
22 *
23 * @param string $content the text within the alert box
24 * @param array $htmlOptions the HTML attributes of the alert box
25 * @param string $close the label for the close button. Set to false if you don't wish to display it.
26 * @return string the alert box
27 */
28 public static function success($content, $htmlOptions = array(), $close = '×')
29 {
30 ArrayHelper::addValue('class', Enum::COLOR_SUCCESS, $htmlOptions);
31 return static::alert($content, $htmlOptions, $close);
32 }
33
34 /**
35 * Generates an red coloured alert box
36 *
37 * @param string $content the text within the alert box
38 * @param array $htmlOptions the HTML attributes of the alert box
39 * @param string $close the label for the close button. Set to false if you don't wish to display it.
40 * @return string the alert box
41 */
42 public static function important($content, $htmlOptions = array(), $close = '×')
43 {
44 ArrayHelper::addValue('class', Enum::COLOR_ALERT, $htmlOptions);
45 return static::alert($content, $htmlOptions, $close);
46 }
47
48 /**
49 * Generates a secondary alert box
50 *
51 * @param string $content the text within the alert box
52 * @param array $htmlOptions the HTML attributes of the alert box
53 * @param string $close the label for the close button. Set to false if you don't wish to display it.
54 * @return string the alert box
55 */
56 public static function secondary($content, $htmlOptions = array(), $close = '×')
57 {
58 ArrayHelper::addValue('class', Enum::COLOR_SECONDARY, $htmlOptions);
59 return static::alert($content, $htmlOptions, $close);
60 }
61
62 /**
63 * Returns an alert box
64 *
65 * @param string $content the text within the alert box
66 * @param array $htmlOptions the HTML attributes of the alert box
67 * @param string $close the label for the close button. Set to false if you don't wish to display it.
68 * @return string the alert box
69 * @see http://foundation.zurb.com/docs/components/alert-boxes.html
70 */
71 public static function alert($content, $htmlOptions = array(), $close = '×')
72 {
73 Arrayhelper::addValue('class', 'alert-box', $htmlOptions);
74
75 ob_start();
76 echo '<div data-alert ' . \CHtml::renderAttributes($htmlOptions) . '>';
77 echo $content;
78 if ($close !== false)
79 echo static::closeLink($close);
80 echo '</div>';
81 return ob_get_clean();
82 }
83
84 /**
85 * Generates a close link.
86 * @param string $label the link label text.
87 * @param array $htmlOptions additional HTML attributes.
88 * @return string the generated link.
89 */
90 public static function closeLink($label = '×', $htmlOptions = array())
91 {
92 $htmlOptions = ArrayHelper::defaultValue('href', '#', $htmlOptions);
93 ArrayHelper::addValue('class', 'close', $htmlOptions);
94 return \CHtml::openTag('a', $htmlOptions) . $label . \CHtml::closeTag('a');
95 }
96 }