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() {
|
2011-09-14 10:58:17 +02:00
|
|
|
$source = $this->getSource();
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2011-09-14 10:58:17 +02:00
|
|
|
// Normalize value to array to simplify further processing
|
|
|
|
$values = (is_array($this->value)) ? $this->value : array(trim($this->value));
|
2007-09-15 23:39:23 +02:00
|
|
|
|
2011-09-14 10:58:17 +02:00
|
|
|
$mapped = array();
|
|
|
|
if($source instanceof SQLMap) {
|
|
|
|
foreach($values as $value) $mapped[] = $source->getItem($value);
|
|
|
|
} elseif(is_array($source)) {
|
|
|
|
$mapped = array_intersect_key($source, array_combine($values, $values));
|
2007-09-15 23:39:23 +02:00
|
|
|
} else {
|
2011-09-14 10:58:17 +02:00
|
|
|
$mapped = array();
|
2007-09-15 23:39:23 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 10:58:17 +02:00
|
|
|
// Don't check if string arguments are matching against the source,
|
|
|
|
// as they might be generated HTML diff views instead of the actual values
|
|
|
|
if($this->value && !$mapped) {
|
|
|
|
$mapped = array(trim($this->value));
|
|
|
|
$values = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if($mapped) {
|
|
|
|
$attrValue = implode(', ', array_values($mapped));
|
|
|
|
if(!$this->dontEscape) $attrValue = Convert::raw2xml($attrValue);
|
|
|
|
$inputValue = implode(', ', array_values($values));
|
|
|
|
} else {
|
|
|
|
$attrValue = "<i>(none)</i>";
|
|
|
|
$inputValue = '';
|
|
|
|
}
|
2007-09-15 23:39:23 +02:00
|
|
|
|
|
|
|
return "<span class=\"readonly\" id=\"" . $this->id() .
|
2011-09-14 10:58:17 +02:00
|
|
|
"\">$attrValue</span><input type=\"hidden\" name=\"" . $this->name .
|
|
|
|
"\" value=\"" . $inputValue . "\" />";
|
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
|
|
|
?>
|