mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-30 22:18:46 +02:00
N°1150 Add value checks in MultipleChoicesField and SelectObjectField
Now current value is checked against list of possible values
This commit is contained in:
@@ -28,6 +28,7 @@ use DBSearch;
|
||||
use FieldExpression;
|
||||
use MetaModel;
|
||||
use ScalarExpression;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Description of SelectObjectField
|
||||
@@ -237,19 +238,40 @@ class SelectObjectField extends Field
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function GetControlType()
|
||||
{
|
||||
public function GetControlType() {
|
||||
return $this->iControlType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetSearchEndpoint()
|
||||
{
|
||||
public function GetSearchEndpoint() {
|
||||
return $this->sSearchEndpoint;
|
||||
}
|
||||
|
||||
public function Validate() {
|
||||
$sCurrentValueForExtKey = $this->currentValue;
|
||||
if (utils::IsNotNullOrEmptyString($sCurrentValueForExtKey) && ($sCurrentValueForExtKey !== 0)) {
|
||||
$oSearchForExistingCurrentValue = $this->oSearch->DeepClone();
|
||||
$oSearchForExistingCurrentValue->AddCondition('id', $sCurrentValueForExtKey, '=');
|
||||
$oCheckIdAgainstCurrentValueExpression = new BinaryExpression(
|
||||
new FieldExpression('id', $oSearchForExistingCurrentValue->GetClassAlias()), '=', new ScalarExpression($sCurrentValueForExtKey)
|
||||
);
|
||||
$oSearchForExistingCurrentValue->AddConditionExpression($oCheckIdAgainstCurrentValueExpression);
|
||||
$oSetForExistingCurrentValue = new DBObjectSet($oSearchForExistingCurrentValue);
|
||||
$iObjectsCount = $oSetForExistingCurrentValue->CountWithLimit(1);
|
||||
|
||||
if ($iObjectsCount === 0) {
|
||||
$this->SetValid(false);
|
||||
$this->AddErrorMessage("Value $sCurrentValueForExtKey does not match the corresponding filter set");
|
||||
|
||||
return $this->GetValid();
|
||||
}
|
||||
}
|
||||
|
||||
return parent::Validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets current value if not among allowed ones.
|
||||
* By default, reset is done ONLY when the field is not read-only.
|
||||
|
||||
Reference in New Issue
Block a user