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
|
|
|
|
2008-08-12 04:58:48 +02:00
|
|
|
protected $readonly = true;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a readonly span containing the correct value.
|
|
|
|
*/
|
|
|
|
function Field() {
|
2008-09-15 06:32:53 +02:00
|
|
|
if(trim($this->value) || $this->value === '0') {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->value = trim($this->value);
|
2008-10-15 14:39:09 +02:00
|
|
|
$source = $this->getSource();
|
|
|
|
if(is_array($source)) {
|
|
|
|
$mappedValue = isset($source[$this->value]) ? $source[$this->value] : null;
|
|
|
|
} elseif($source instanceof SQLMap) {
|
|
|
|
$mappedValue = $source->getItem($this->value);
|
2007-11-11 22:10:59 +01:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:33:57 +02:00
|
|
|
if(!isset($mappedValue)) $mappedValue = $this->value ? $this->value : "<i>(none)</i>";
|
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>';
|
|
|
|
}
|
|
|
|
|
2008-10-15 14:39:09 +02:00
|
|
|
$valforInput = $this->value ? Convert::raw2att($val) : "";
|
2007-09-15 23:39:23 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2008-08-12 04:58:48 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function performReadonlyTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
$clone = clone $this;
|
|
|
|
return $clone;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-12 04:58:48 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function Type() {
|
|
|
|
return "lookup readonly";
|
|
|
|
}
|
2008-10-15 14:39:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Override parent behaviour by not merging arrays.
|
|
|
|
*/
|
|
|
|
function getSource() {
|
|
|
|
return $this->source;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
?>
|