(mvc) add ChangeCase to base field type, enforces case on change event

This commit is contained in:
Ad Schellevis 2016-02-08 09:32:55 +01:00
parent 89d73c568f
commit c3358d74f8

View File

@ -102,6 +102,11 @@ abstract class BaseField
*/
protected $internalAttributes = array();
/**
* @var string $internalToLower
*/
private $internalChangeCase = null;
/**
* generate a new UUID v4 number
* @return string uuid v4 number
@ -274,6 +279,11 @@ abstract class BaseField
$this->internalInitialValue = $value;
}
$this->internalValue = $value;
// apply filters, may be extended later.
$filters = array('applyFilterChangeCase');
foreach ($filters as $filter) {
$this->$filter();
}
}
/**
@ -539,6 +549,35 @@ abstract class BaseField
}
}
/**
* change character case on save
* @param string $value set case type, upper, lower, null (don't change)
*/
public function setChangeCase($value)
{
if (strtoupper(trim($value)) == 'UPPER') {
$this->internalChangeCase = 'UPPER';
} elseif (strtoupper(trim($value)) == 'LOWER') {
$this->internalChangeCase = 'LOWER';
} else {
$this->internalChangeCase = null;
}
}
/**
* apply change case to this node, called by setValue
*/
private function applyFilterChangeCase()
{
if (!empty($this->internalValue)) {
if ($this->internalChangeCase == 'UPPER') {
$this->internalValue = strtoupper($this->internalValue);
} elseif ($this->internalChangeCase == 'LOWER') {
$this->internalValue = strtolower($this->internalValue);
}
}
}
/**
* return object type as string
* @return string