oxrequiredfieldsvalidator.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxRequiredFieldsValidator
00008 {
00009 
00015     private $_aRequiredFields = array();
00016 
00022     private $_aInvalidFields = array();
00023 
00029     private $_oFieldValidator = array();
00030 
00036     public function __construct($oFieldValidator = null)
00037     {
00038         if (is_null($oFieldValidator)) {
00039             $oFieldValidator = oxNew('oxRequiredFieldValidator');
00040         }
00041         $this->setFieldValidator($oFieldValidator);
00042     }
00043 
00049     public function getRequiredFields()
00050     {
00051         return $this->_aRequiredFields;
00052     }
00053 
00059     public function setRequiredFields($aFields)
00060     {
00061         $this->_aRequiredFields = $aFields;
00062     }
00063 
00069     public function getFieldValidator()
00070     {
00071         return $this->_oFieldValidator;
00072     }
00073 
00079     public function setFieldValidator($oFieldValidator)
00080     {
00081         $this->_oFieldValidator = $oFieldValidator;
00082     }
00083 
00089     public function getInvalidFields()
00090     {
00091         return $this->_aInvalidFields;
00092     }
00093 
00102     public function validateFields($oObject)
00103     {
00104         $aRequiredFields = $this->getRequiredFields();
00105         $oFieldValidator = $this->getFieldValidator();
00106 
00107         $aInvalidFields = array();
00108         foreach ($aRequiredFields as $sFieldName) {
00109             if (!$oFieldValidator->validateFieldValue($oObject->getFieldData($sFieldName))) {
00110                 $aInvalidFields[] = $sFieldName;
00111             }
00112         }
00113         $this->_setInvalidFields($aInvalidFields);
00114 
00115         return empty($aInvalidFields);
00116     }
00117 
00123     private function _setInvalidFields($aFields)
00124     {
00125         $this->_aInvalidFields = $aFields;
00126     }
00127 }