Created
February 1, 2013 13:10
-
-
Save crisu83/4691215 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Generates a button group. | |
| * @param array $buttons the button configurations. | |
| * @param array $htmlOptions additional HTML options. The following special options are recognized: | |
| * todo: write the options | |
| * @return string the generated button group. | |
| */ | |
| public static function buttonGroup($buttons, $htmlOptions = array()) | |
| { | |
| if (is_array($buttons) && !empty($buttons)) | |
| { | |
| $htmlOptions = self::addClassName('btn-group', $htmlOptions); | |
| $vertical = self::popOption('vertical', $htmlOptions, false); | |
| if ($vertical) | |
| $htmlOptions = self::addClassName('btn-group-vertical', $htmlOptions); | |
| $globalOptions = array( | |
| 'style' => self::popOption('style', $htmlOptions), | |
| 'size' => self::popOption('size', $htmlOptions), | |
| 'disabled' => self::popOption('disabled', $htmlOptions) | |
| ); | |
| ob_start(); | |
| echo parent::openTag('div', $htmlOptions); | |
| foreach ($buttons as $button) | |
| { | |
| $button = self::inheritOptions(array('style', 'size', 'disabled'), $globalOptions, $button); | |
| $buttonLabel = self::popOption('label', $button, ''); | |
| $buttonOptions = self::popOption('htmlOptions', $button, array()); | |
| $buttonOptions = self::moveOptions(array('icon', 'style', 'size', 'disabled'), $button, $buttonOptions); | |
| echo self::button($buttonLabel, $buttonOptions); | |
| } | |
| echo '</div>'; | |
| return ob_get_clean(); | |
| } | |
| return ''; | |
| } | |
| /** | |
| * Generates a button toolbar. | |
| * @param array $groups the button group configurations. | |
| * @param array $htmlOptions additional HTML options. The following special options are recognized: | |
| * todo: write the options | |
| * @return string the generated button toolbar. | |
| */ | |
| public static function buttonToolbar($groups, $htmlOptions = array()) | |
| { | |
| if(is_array($groups) && !empty($groups)) | |
| { | |
| $htmlOptions = self::addClassName('btn-toolbar', $htmlOptions); | |
| $globalOptions = array( | |
| 'style' => self::popOption('style', $htmlOptions), | |
| 'size' => self::popOption('size', $htmlOptions), | |
| 'disabled' => self::popOption('disabled', $htmlOptions) | |
| ); | |
| ob_start(); | |
| echo parent::openTag('div', $htmlOptions); | |
| foreach ($groups as $group) | |
| { | |
| $items = self::getOption('items', $group, array()); | |
| if (empty($items)) | |
| continue; | |
| $group = self::inheritOptions(array('style', 'size', 'disabled'), $globalOptions, $group); | |
| $groupOptions = self::getOption('htmlOptions', $group, array()); | |
| $groupOptions = self::moveOptions(array('style', 'size', 'disabled'), $group, $groupOptions); | |
| echo self::buttonGroup($items, $groupOptions); | |
| } | |
| echo '</div>'; | |
| return ob_get_clean(); | |
| } | |
| return ''; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment