public function div_box()
{
return _class('html')->div_box('input_name', ['k1' => 'key1', 'k2' => 'key2']);
}
public function div_box($name, $values = [], $selected = '', $extra = [])
{
if (is_array($name)) {
$extra = (array) $extra + $name;
$name = $extra['name'];
}
$desc = $extra['desc'] ? $extra['desc'] : ucfirst(str_replace('_', '', $name));
$values = isset($extra['values']) ? $extra['values'] : (array) $values; // Required
$translate = isset($extra['translate']) ? $extra['translate'] : 0;
if ($extra['no_translate']) {
$translate = 0;
}
$selected = $extra['selected'] ?: $selected;
$extra['id'] = $extra['id'] ?: __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__];
if ( ! $values) {
return false;
}
$selected = (string) $selected;
$items = [];
$selected_val = '';
foreach ((array) $values as $key => $cur_value) {
$_what_compare = (string) ($type == 1 ? $cur_value : $key);
$is_selected = $_what_compare == $selected;
$val = ($translate ? t($cur_value) : $cur_value);
$items[] = '<li class="dropdown' . ($is_selected ? ' active' : '') . '"><a data-value="' . $key . '"' . ($is_selected ? ' data-selected="selected"' : '') . '>' . $val . '</a></li>';
if ($is_selected) {
$selected_val = $val;
}
}
$body = [];
$body[] = '<li class="dropdown" style="list-style-type:none;" id="' . $extra['id'] . '">';
$body[] = '<a class="dropdown-toggle" data-toggle="dropdown">' . ($selected_val ?: $desc) . ' <span class="caret"></span></a>';
$body[] = '<ul class="dropdown-menu">';
foreach ($items as $v) {
$body[] = $v;
}
$body[] = '</ul>';
$body[] = '</li>';
return implode(PHP_EOL, $body);
}