1 <?php
2 3 4 5 6 7
8
9 namespace foundation\helpers;
10
11 use foundation\widgets\Dropdown;
12 use foundation\enum\Enum;
13
14 15 16 17 18 19
20 class Button
21 {
22 23 24 25 26 27
28 public static function button($label = 'button', $htmlOptions = array())
29 {
30 $htmlOptions = ArrayHelper::defaultValue('name', \CHtml::ID_PREFIX . \CHtml::$count++, $htmlOptions);
31 Html::clientChange('click', $htmlOptions);
32 return static::btn('button', $label, $htmlOptions);
33 }
34
35 36 37 38 39 40
41 public static function link($label = 'submit', $htmlOptions = array())
42 {
43 ArrayHelper::addValue('class', 'button', $htmlOptions);
44 return static::btn('a', $label, $htmlOptions);
45 }
46
47 48 49 50 51 52 53
54 public static function group($buttons, $htmlOptions = array())
55 {
56 ArrayHelper::addValue('class', 'button-group', $htmlOptions);
57
58 ob_start();
59 echo \CHtml::openTag('ul', $htmlOptions);
60 foreach ($buttons as $button) {
61 echo $button;
62 }
63 echo \CHtml::closeTag('ul');
64
65 return ob_get_clean();
66 }
67
68 69 70 71 72 73
74 public static function bar($groups, $htmlOptions = array())
75 {
76 ArrayHelper::addValue('class', 'button-bar', $htmlOptions);
77
78 ob_start();
79 echo \CHtml::openTag('div', $htmlOptions);
80 foreach ($groups as $group) {
81 echo $group;
82 }
83 echo \CHtml::closeTag('div');
84
85 return ob_get_clean();
86 }
87
88 89 90 91 92 93 94
95 public static function btn($tag, $label, $htmlOptions = array())
96 {
97 ArrayHelper::addValue('class', 'button', $htmlOptions);
98
99 $icon = ArrayHelper::removeValue($htmlOptions, 'icon');
100 if (isset($icon))
101 $label = Icon::icon($icon) . ' ' . $label;
102
103 return \CHtml::tag($tag, $htmlOptions, $label);
104 }
105
106 107 108 109 110 111 112 113 114 115
116 public static function dropdown($label, $list, $htmlOptions = array())
117 {
118 $id = Enum::ID_PREFIX . '-' . Html::$count++;
119
120 ArrayHelper::addValue('data-dropdown', $id, $htmlOptions);
121 ArrayHelper::addValue('class', Enum::DROPDOWN, $htmlOptions);
122
123 $dropHtmlOptions = ArrayHelper::removeValue($htmlOptions, 'dropHtmlOptions', array());
124 $dropHtmlOptions['id'] = $id;
125 $dropHtmlOptions['data-dropdown-content'] = '';
126
127 ArrayHelper::addValue('class', Enum::DROPDOWN_LIST, $dropHtmlOptions);
128
129 ob_start();
130 echo static::link($label, $htmlOptions);
131 echo Dropdown::display(
132 array(
133 'items' => $list,
134 'htmlOptions' => $dropHtmlOptions
135 )
136 );
137 return ob_get_clean();
138 }
139
140 141 142 143 144 145 146 147 148 149
150 public static function split($label, $list, $htmlOptions = array())
151 {
152 $id = Enum::ID_PREFIX . '-' . ++Html::$count;
153
154 ArrayHelper::addValue('class', Enum::DROPDOWN_SPLIT, $htmlOptions);
155
156 $label .= ' <span data-dropdown="' . $id . '"></span>';
157
158 $dropHtmlOptions = ArrayHelper::removeValue($htmlOptions, 'dropHtmlOptions', array());
159 $dropHtmlOptions['id'] = $id;
160
161 ArrayHelper::addValue('class', Enum::DROPDOWN_LIST, $dropHtmlOptions);
162
163 ob_start();
164 echo '<div style="position:relative">';
165 echo static::link($label, $htmlOptions);
166 echo Dropdown::display(
167 array(
168 'items' => $list,
169 'htmlOptions' => $dropHtmlOptions
170 )
171 );
172 echo '</div>';
173 return ob_get_clean();
174 }
175 }
176