NEED TO CONFIGURING MULTIPLE VALIDATOR SEVICE

1 view
Skip to first unread message

rhossis

unread,
Feb 19, 2012, 6:27:11 AM2/19/12
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;
}

Rocky Swen

unread,
Feb 20, 2012, 1:03:02 PM2/20/12
to openbi...@googlegroups.com
Can you override the methods below in order implement your own logic?
BizDataObj::validateInput() or
EasyForm::validateForm()

rhossis

unread,
Feb 22, 2012, 4:15:05 AM2/22/12
to Openbiz Cubi
Ok. It is a more logical solution. Thanks.
Reply all
Reply to author
Forward
0 new messages