/** * Performs the validation. * * This method executes the validation rules as declared in {@link rules}. * Only the rules applicable to the current {@link scenario} will be executed. * A rule is considered applicable to a scenario if its 'on' option is not set * or contains the scenario. * * Errors found during the validation can be retrieved via {@link getErrors}. * * @param array $attributes list of attributes that should be validated. Defaults to null, * meaning any attribute listed in the applicable validation rules should be * validated. If this parameter is given as a list of attributes, only * the listed attributes will be validated. * @param boolean $clearErrors whether to call {@link clearErrors} before performing validation * * @return boolean whether the validation is successful without any error. * @see beforeValidate * @see afterValidate */ public function validate($attributes = null, $clearErrors = true) { if ($clearErrors) { $this->clearErrors(); } if ($this->beforeValidate()) { foreach ($this->rules() as $item) { var_echo($item); } foreach ($this->getValidators() as $validator) { $validator->validate($this, $attributes); } $this->afterValidate(); return !$this->hasErrors(); } else { return false; } }
/** * Prepares the SQL statement to be executed. * For complex SQL statement that is to be executed multiple times, * this may improve performance. * For SQL statement with binding parameters, this method is invoked * automatically. * @throws Exception if \Database\Command failed to prepare the SQL statement */ public function prepare() { if ($this->_statement == null) { try { $this->_statement = $this->getConnection()->getPdoInstance()->prepare($this->getText()); $this->_paramLog = []; } catch (Exception $e) { var_echo('Error in preparing SQL: ' . $this->getText(), 'system.db.CDbCommand'); $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; throw new Exception('CDbCommand failed to prepare the SQL statement: {' . $e->getMessage() . '}', (int) $e->getCode(), $errorInfo); } } }
/** * Checks if a property value is null. * This method overrides the parent implementation by checking * if the named attribute is null or not. * @param string $name the property name or the event name * @throws Exception * @return boolean whether the property value is null */ public function __isset($name) { if (isset($this->_attributes[$name])) { return true; } elseif (isset($this->getMetaData()->columns[$name])) { return false; } elseif (isset($this->_related[$name])) { return true; } elseif (isset($this->getMetaData()->relations[$name])) { return $this->getRelated($name) !== null; } else { var_echo($name); } //throw new DBException('FAIL!!!!'); //return parent::__isset($name); }
/** * This method is internally called. * @param \Database\schema\Criteria $criteria the query criteria * @return string */ public function count($criteria) { var_echo(get_class($this->_joinTree->model) . '.count() eagerly', 'Database_ActiveRecord_Record'); $this->joinAll = $criteria->together !== true; $alias = $criteria->alias === null ? 't' : $criteria->alias; $this->_joinTree->tableAlias = $alias; $this->_joinTree->rawTableAlias = $this->_builder->getSchema()->quoteTableName($alias); $n = $this->_joinTree->count($criteria); $this->destroyJoinTree(); return $n; }