protected function ComputeTimeSpent()
{
$iSum = 0;
$oWorkOrderSet = $this->Get('workorders_list');
while($oWorkOrder = $oWorkOrderSet->Fetch())
{
$iSum += $oWorkOrder->Get('time_spent');
}
$this->Set('time_spent', $iSum);
}
protected function OnUpdate()
{
$aChanges = $this->ListChanges();
if (('workorders_list', $aChanges))
{
$this->ComputeTimeSpent();
}
}
public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = ())
{
// Hide the calculated field in object creation form
if (($sAttCode == 'time_spent'))
return(OPT_ATT_HIDDEN | parent::GetInitialStateAttributeFlags($sAttCode,
$aReasons));
return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons);
}
public function GetAttributeFlags($sAttCode, &$aReasons = (), $sTargetState = '')
{
// Force the computed field to be read-only, preventing it to be written
if (($sAttCode == 'time_spent'))
return(OPT_ATT_READONLY | parent::GetAttributeFlags($sAttCode, $aReasons,
$sTargetState));
return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
}