/**
  * Validate readings.
  */
 protected function afterValidate()
 {
     foreach (array('right', 'left') as $side) {
         foreach ($this->{$side . '_readings'} as $i => $reading) {
             if (!$reading->validate()) {
                 foreach ($reading->getErrors() as $fld => $err) {
                     $this->addError($side . '_reading', ucfirst($side) . ' reading (' . ($i + 1) . '): ' . implode(', ', $err));
                 }
             }
         }
     }
     return parent::afterValidate();
 }
 public function afterValidate()
 {
     if ($this->scenario == 'formHasNoChildren') {
         $values = false;
         if ($this->hasLeft()) {
             if ($this->left_rapd || $this->left_comments) {
                 $values = true;
             }
         }
         if (!$values && $this->hasRight()) {
             if ($this->right_rapd || $this->right_comments) {
                 $values = true;
             }
         }
         if (!$values) {
             $this->addError(null, "Visual Function requires data");
         }
     }
     parent::afterValidate();
 }
 /**
  * Perform dependent validation for readings and flags.
  */
 protected function afterValidate()
 {
     $contra_flags = array('_unable_to_assess', '_eye_missing');
     foreach (array('left', 'right') as $side) {
         $check = 'has' . ucfirst($side);
         if ($this->{$check}()) {
             if ($this->{$side . '_readings'}) {
                 foreach ($this->{$side . '_readings'} as $i => $reading) {
                     if (!$reading->validate()) {
                         foreach ($reading->getErrors() as $fld => $err) {
                             $this->addError($side . '_readings', ucfirst($side) . ' reading(' . ($i + 1) . '): ' . implode(', ', $err));
                         }
                     }
                 }
                 foreach ($contra_flags as $f) {
                     if ($this->{$side . $f}) {
                         $this->addError($side . $f, 'Cannot be ' . $this->getAttributeLabel($side . $f) . ' with VA readings.');
                     }
                 }
             } else {
                 $valid = false;
                 foreach ($contra_flags as $f) {
                     if ($this->{$side . $f}) {
                         $valid = true;
                     }
                 }
                 if (!$valid) {
                     $this->addError($side, ucfirst($side) . ' side has no data.');
                 }
             }
         }
     }
     parent::afterValidate();
 }