rhossis
unread,Feb 19, 2012, 6:27:11 AM2/19/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Openbiz Cubi
I have had to extend BizField and overriden the validate() function as
some fields require validation across several domains, which would be
cumbersome to amend in a service class.
This is because the validation types might be common, but required in
different combinations
e.g.
-> for a term contract
1) Check that [from_date] is less than or equal to [to_date]
2) Check that [to_date] - [from_date] >= minimum term specified
in contracts policy table
-> for an accounting transaction
1) Check that [value_date] is less than or equal to
[posting_date]
2) Check that [posting_date] is not on a date where
end_of_period process has been run
The business rules could then be set by calling
Validator="{@service1:func1(x,y)}; {@service2:func2(a,b,c)}"
public function validate()
{
$ret = true;
if ($this->m_Validator) { //check if validator
set
//check if validator has several requirements
if(strpos($this->m_Validator, ";") !== false) {
$validator_list = explode(";", $this->m_Validator);
//evaluate each expression
foreach ($validator_list as $validator)
{
if(!$validator)
continue;
$ret =
Expression::evaluateExpression($validator, $this->getDataObj());
if(!$ret)
return $ret;
}
} else {
$ret = Expression::evaluateExpression($validator,
$this->getDataObj());
}
}
return $ret;
}