2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
* Read-only complement of {@link DropdownField}.
|
|
|
|
* Shows the "human value" of the dropdown field for the currently selected value.
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class LookupField extends DropdownField {
|
2007-09-15 23:39:23 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a readonly span containing the correct value.
|
|
|
|
*/
|
|
|
|
function Field() {
|
|
|
|
if(trim($this->value)) {
|
|
|
|
$this->value = trim($this->value);
|
2007-11-11 22:10:59 +01:00
|
|
|
if(is_array($this->source)) {
|
|
|
|
$mappedValue = isset($this->source[$this->value]) ? $this->source[$this->value] : null;
|
|
|
|
} else {
|
|
|
|
$mappedValue = $this->source->getItem($this->value);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-11-11 22:10:59 +01:00
|
|
|
if(!isset($mappedValue)) {
|
2007-09-15 23:39:23 +02:00
|
|
|
$mappedValue = "<i>(none)</i>";
|
2007-11-11 22:10:59 +01:00
|
|
|
}
|
2007-09-15 23:39:23 +02:00
|
|
|
|
|
|
|
if($this->value) {
|
|
|
|
$val = $this->dontEscape
|
|
|
|
? ($this->reserveNL?Convert::raw2xml($this->value):$this->value)
|
|
|
|
: Convert::raw2xml($this->value);
|
|
|
|
} else {
|
|
|
|
$val = '<i>(none)</i>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$valforInput = $this->value
|
|
|
|
? Convert::raw2att($val)
|
|
|
|
: "";
|
|
|
|
|
|
|
|
return "<span class=\"readonly\" id=\"" . $this->id() .
|
|
|
|
"\">$mappedValue</span><input type=\"hidden\" name=\"" . $this->name .
|
|
|
|
"\" value=\"" . $valforInput . "\" />";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
function performReadonlyTransformation() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
function Type() {
|
|
|
|
return "lookup readonly";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-11 22:10:59 +01:00
|
|
|
?>
|