Esempio n. 1
0
 public function validateValue($value, $primary, $row, Result $result)
 {
     $validators = $this->getValidators();
     foreach ($validators as $validator) {
         if (is_object($validator)) {
             $vResult = $validator->validate($value, $primary, $row, $this);
         } else {
             $vResult = call_user_func_array($validator, array($value, $primary, $row, $this));
         }
         if ($vResult !== true) {
             $result->addError(new FieldError($this, $vResult, FieldError::INVALID_VALUE));
             break;
         }
     }
 }
Esempio n. 2
0
 /**
  * Checks the data fields before saving to DB. Result stores in the $result object
  *
  * @param Result $result
  * @param mixed $primary
  * @param array $data
  * @throws Main\ArgumentException
  */
 public static function checkFields(Result $result, $primary, array $data)
 {
     //checks required fields
     foreach (static::getEntity()->getFields() as $field) {
         if ($field instanceof ScalarField && $field->isRequired()) {
             $fieldName = $field->getName();
             if (empty($primary) && (!isset($data[$fieldName]) || $field->isValueEmpty($data[$fieldName])) || !empty($primary) && isset($data[$fieldName]) && $field->isValueEmpty($data[$fieldName])) {
                 $result->addError(new FieldError($field, Loc::getMessage("MAIN_ENTITY_FIELD_REQUIRED", array("#FIELD#" => $field->getTitle())), FieldError::EMPTY_REQUIRED));
             }
         }
     }
     // checks data - fieldname & type & strlen etc.
     foreach ($data as $k => $v) {
         if (static::getEntity()->hasField($k) && static::getEntity()->getField($k) instanceof ScalarField) {
             $field = static::getEntity()->getField($k);
         } elseif (static::getEntity()->hasUField($k)) {
             // should be continue
             // checking is inside uf manager
             $field = static::getEntity()->getUField($k);
         } else {
             throw new Main\ArgumentException(sprintf('Field `%s` not found in entity when trying to query %s row.', $k, static::getEntity()->getName()));
         }
         $field->validateValue($v, $primary, $data, $result);
     }
 }
Esempio n. 3
0
 public function __construct()
 {
     parent::__construct();
 }