Commit 907937c1 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(mvc) add simpler model validation method

just a pattern that returns from time to time, encapsulated into a new method so we can remove some code.

(cherry picked from commit dadbdf90)
parent 5343bf7f
......@@ -322,6 +322,29 @@ abstract class BaseModel
return $messages;
}
/**
* perform a validation on changed model fields, using the (renamed) internal reference as a source pointer
* for the requestor to identify its origin
* @param null|string $sourceref source reference, for example model.section
* @param null|string $targetref target reference, for example section
* @return array list of validation errors, indexed by field reference
*/
public function validate($sourceref = null, $targetref = null)
{
$result = array();
$valMsgs = $this->performValidation();
foreach ($valMsgs as $field => $msg) {
// replace absolute path to attribute for relative one at uuid.
if ($sourceref != null) {
$fieldnm = str_replace($sourceref, $targetref, $msg->getField());
$result[$fieldnm] = $msg->getMessage();
} else {
$result[$msg->getField()] = $msg->getMessage();
}
}
return $result;
}
/**
* render xml document from model including all parent nodes.
* (parent nodes are included to ease testing)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment