_getInfo($name, $value, $attribs);
extract($info); // name, value, attribs, options, listsep, disable
if (array_key_exists('multiOptions', $attribs)) {
$multiOptions = $attribs['multiOptions'];
unset($attribs['multiOptions']);
$validOptions = $this->flattenOptions($multiOptions);
} else {
$multiOptions = null;
}
if (array_key_exists('sorted', $attribs)) {
$sorted = (bool) $attribs['sorted'];
unset($attribs['sorted']);
} else {
$sorted = false;
}
$disableStr = ' disabled="disabled"';
// build the element
$disabled = '';
if ($disable) {
// disabled
$disabled = $disableStr;
}
$elements = array();
$v = $this->view;
$name = $v->escape($name);
$id = $v->escape($id);
if ($value instanceof ExtensibleSet) {
$value = $value->toPlainObject();
}
if (is_array($value)) {
$value = array_filter($value, 'strlen');
}
$cnt = 0;
$total = 0;
if (is_array($value)) {
$total = count($value);
foreach ($value as $val) {
if ($multiOptions !== null) {
if (in_array($val, $validOptions)) {
$multiOptions = $this->removeOption($multiOptions, $val);
} else {
continue; // Value no longer valid
}
}
$suff = $this->suffix($cnt);
$htm = '
';
if ($sorted) {
$htm .= $this->renderDownButton($name, $cnt, ($cnt === $total - 1 ? $disableStr : $disabled))
. $this->renderUpButton($name, $cnt, ($cnt === 0 ? $disableStr : $disabled));
}
$htm .= $this->renderDeleteButton($name, $cnt, $disabled)
. ''
. '_htmlAttribs($attribs)
. ' />'
. '';
$elements[] = $htm;
$cnt++;
}
}
$suff = $this->suffix($cnt);
if ($multiOptions) {
if (count($multiOptions) > 1 || strlen(key($multiOptions))) {
$htm = ''
. ''
. $this->renderAddButton($name, $disabled)
. ''
. $v->formSelect(
$name . '[]',
null,
array(
'class' => 'autosubmit' . ($cnt === 0 ? '' : ' extend-set'),
'multiple' => false,
'id' => $id . $suff
),
$multiOptions
);
$elements[] = $htm;
}
} else {
$elements[] = '_htmlAttribs($attribs)
. $this->getClosingBracket()
. ''
. $this->renderAddButton($name, $disabled)
. ''
. '';
}
return '' . "\n "
. implode("\n ", $elements)
. "
\n";
}
private function flattenOptions($options)
{
$flat = array();
foreach ($options as $key => $option) {
if (is_array($option)) {
foreach ($option as $k => $o) {
$flat[] = $k;
}
} else {
$flat[] = $key;
}
}
return $flat;
}
private function removeOption($options, $option)
{
$unset = array();
foreach ($options as $key => & $value) {
if (is_array($value)) {
$value = $this->removeOption($value, $option);
if (empty($value)) {
$unset[] = $key;
}
} elseif ($key === $option) {
$unset[] = $key;
}
}
foreach ($unset as $key) {
unset($options[$key]);
}
return $options;
}
private function suffix($cnt)
{
if ($cnt === 0) {
return '';
} else {
return '_' . $cnt;
}
}
private function renderText($name, $id, $suff, $attribs, $disabled)
{
$v = $this->view;
return '_htmlAttribs($attribs)
. ' />';
}
private function renderAddButton($name, $disabled)
{
$v = $this->view;
return '';
}
private function renderDeleteButton($name, $cnt, $disabled)
{
$v = $this->view;
return '';
}
private function renderUpButton($name, $cnt, $disabled)
{
$v = $this->view;
return '';
}
private function renderDownButton($name, $cnt, $disabled)
{
$v = $this->view;
return '';
}
}