DirectorObjectForm: remodel boolean helpers

This commit is contained in:
Thomas Gelf 2015-08-02 15:06:52 +02:00
parent 1e5deb2441
commit 44013eec42

View File

@ -323,19 +323,40 @@ abstract class DirectorObjectForm extends QuickForm
$this->redirectOnSuccess($msg); $this->redirectOnSuccess($msg);
} }
protected function addBoolean($key, $options, $default = null)
{
$map = array(
false => 'n',
true => 'y',
'n' => 'n',
'y' => 'y',
);
if ($default !== null) {
$options['multiOptions'] = $this->enumBoolean();
} else {
$options['multiOptions'] = $this->optionalEnum($this->enumBoolean());
}
$res = $this->addElement('select', $key, $options);
if ($default !== null) {
$this->getElement($key)->setValue($map[$default]);
}
return $res;
}
protected function optionalBoolean($key, $label, $description) protected function optionalBoolean($key, $label, $description)
{ {
return $this->addElement('select', $key, array( return $this->addBoolean($key, array(
'label' => $label, 'label' => $label,
'description' => $description, 'description' => $description
'multiOptions' => $this->selectBoolean()
)); ));
} }
protected function selectBoolean() protected function enumBoolean()
{ {
return array( return array(
null => $this->translate('- not set -'),
'y' => $this->translate('Yes'), 'y' => $this->translate('Yes'),
'n' => $this->translate('No'), 'n' => $this->translate('No'),
); );