Index: trunk/core/kernel/db/dbitem.php =================================================================== diff -u -N -r8719 -r8842 --- trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8719) +++ trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8842) @@ -172,16 +172,25 @@ * @param string $pseudo * @param string $error_label */ - function SetError($field, $pseudo, $error_label = '') + function SetError($field, $pseudo, $error_label = null, $error_params = null) { $error_field = isset($this->Fields[$field]['error_field']) ? $this->Fields[$field]['error_field'] : $field; + if (isset($this->FieldErrors[$error_field]['pseudo'])) { + // don't set more then one error on field + return ; + } + $this->FieldErrors[$error_field]['pseudo'] = $pseudo; - $error_msg = $error_label ? $this->Application->Phrase($error_label) : ''; - if ($error_label && !getArrayValue($this->ErrorMsgs, $pseudo)) - { - $this->ErrorMsgs[$pseudo] = $error_msg; + if (isset($error_params)) { + // additional params, that helps to determine error sources + $this->FieldErrors[$error_field]['params'] = $error_params; } + + if (isset($error_label) && !isset($this->ErrorMsgs[$pseudo])) { + // label for error (only when not already set) + $this->ErrorMsgs[$pseudo] = (substr($error_label, 1, 1) == '+') ? substr($error_label, 1) : '!'.$error_label.'!'; + } } /** @@ -509,22 +518,18 @@ { $res = true; $val = $this->FieldValues[$field]; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; if ( $val != '' && isset($params['type']) && preg_match("#int|integer|double|float|real|numeric|string#", $params['type']) ) { $res = is_numeric($val); - if($params['type']=='string' || $res) - { + if ($params['type']=='string' || $res) { $f = 'is_'.$params['type']; settype($val, $params['type']); - $res = $f($val) && ($val==$this->FieldValues[$field]); + $res = $f($val) && ($val == $this->FieldValues[$field]); } - if (!$res) - { - $this->FieldErrors[$error_field]['pseudo'] = 'bad_type'; - $this->FieldErrors[$error_field]['params'] = $params['type']; + if (!$res) { + $this->SetError($field, 'bad_type', null, $params['type']); } } return $res; @@ -541,13 +546,14 @@ function ValidateRequired($field, $params) { $res = true; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; - if ( getArrayValue($params,'required') ) - { - $res = ( (string) $this->FieldValues[$field] != ''); + if (isset($params['required']) && $params['required']) { + $res = ((string)$this->FieldValues[$field] != ''); } + $options = $this->GetFieldOptions($field); - if (!$res && getArrayValue($options, 'formatter') != 'kUploadFormatter') $this->FieldErrors[$error_field]['pseudo'] = 'required'; + if (!$res && getArrayValue($options, 'formatter') != 'kUploadFormatter') { + $this->SetError($field, 'required'); + } return $res; } @@ -562,7 +568,6 @@ function ValidateUnique($field, $params) { $res = true; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; $unique_fields = getArrayValue($params,'unique'); if($unique_fields !== false) { @@ -588,7 +593,9 @@ $res = ($res_temp == 0) && ($res_live == 0); - if(!$res) $this->FieldErrors[$error_field]['pseudo'] = 'unique'; + if (!$res) { + $this->SetError($field, 'unique'); + } } return $res; } @@ -605,7 +612,6 @@ { $res = true; $val = $this->FieldValues[$field]; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; if ( isset($params['type']) && preg_match("#int|integer|double|float|real#", $params['type']) && strlen($val) > 0 ) { if ( isset($params['max_value_inc'])) { @@ -626,12 +632,10 @@ } } if (!$res) { - $this->FieldErrors[$error_field]['pseudo'] = 'value_out_of_range'; - if ( !isset($min_val) ) $min_val = '-∞'; if ( !isset($max_val) ) $max_val = '∞'; - $this->FieldErrors[$error_field]['params'] = Array( $min_val, $max_val ); + $this->SetError($field, 'value_out_of_range', null, Array ($min_val, $max_val)); return $res; } if ( isset($params['max_len'])) { @@ -641,8 +645,8 @@ $res = $res && strlen($val) >= $params['min_len']; } if (!$res) { - $this->FieldErrors[$error_field]['pseudo'] = 'length_out_of_range'; - $this->FieldErrors[$error_field]['params'] = Array( getArrayValue($params,'min_len'), getArrayValue($params,'max_len') ); + $error_params = Array (getArrayValue($params, 'min_len'), getArrayValue($params, 'max_len')); + $this->SetError($field, 'length_out_of_range', null, $error_params); return $res; } return $res; @@ -776,7 +780,11 @@ $this->setModifiedFlag(); - $this->raiseEvent('OnAfterItemDelete'); + if ($this->Conn->getAffectedRows() > 0) { + // something was actually deleted + $this->raiseEvent('OnAfterItemDelete'); + } + if ($this->mode != 't') { $this->Application->resetCounters($this->TableName); }