Commit dadbdf90 authored by Ad Schellevis's avatar Ad Schellevis

(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.
parent 7f0a25a1
......@@ -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