public function check() { if (!parent::check()) { return FALSE; } if (count($this->_transactions['incomes']) == 0 and count($this->_transactions['transfers']) == 0 and count($this->_transactions['expenses']) == 0) { $this->_validate->error('balance', 'No transactions'); return FALSE; } $balance = 0; foreach ($this->_transactions as $type => $transactions) { switch ($type) { case 'incomes': foreach ($transactions as $transaction) { $balance += $transaction->amount; } break; default: foreach ($transactions as $transaction) { $balance -= $transaction->amount; } } } if ($balance != 0) { $this->_validate->error('balance', 'Not zero'); return FALSE; } return TRUE; }
/** * Validates and optionally * * @param array values to check * @param boolean save the record when validation succeeds * @return boolean */ public function validate() { $this->_filters += array(TRUE => array('trim' => array())); #array($this, 'email_available')=>array() $this->_rules += array('email' => array('min_length' => array(4), 'max_length' => array(255), 'email' => array())); # array($this, 'user_name_available') $this->_rules += array('user_name' => array('min_length' => array(4), 'max_length' => array(255), 'alpha_dash' => array())); return parent::check(); }
public function validate() { $this->_filters += array(TRUE => array('trim' => array())); $this->_rules = array('password' => array('min_length' => array(6))); if (isset($this->password_confirm)) { $this->_rules += array('password_confirm' => array('matches' => array('password'))); } return parent::check(); }
public function check() { if (!isset($this->_validate)) { // Initialize the validation object $this->_validate(); } // add custom rules to $this->_validate(); event::run('yuriko_core.model.validate.site_settings', $this->_validate); return parent::check(); }
/** * @return bool */ public function populate() { if (!$this->allowed('write')) { return FALSE; } $hash = $this->_hash_input_name; // nothing or the other form has been submitted if (!isset($_POST[$hash])) { return FALSE; } $values = array(); foreach ($this as $name => $field) { if ($field->allowed('write')) { if (!is_null($value = Arr::get($_POST, $name))) { $values[$name] = $field->prepare_to_populate($value); } } } $this->_object->values($values); foreach ($this as $name => $field) { $field->set_value($this->_object->{$name}); } $valid = $this->_object->check(); foreach ($this as $name => $field) { $valid = ($valid and $field->validate($this->_object->validate(), $name)); } if ($valid) { return TRUE; } $errors = $this->_object->validate()->errors($this->_messages_file); foreach ($errors as $name => $error) { if (isset($this[$name])) { $this[$name]->set_error($error); } } return FALSE; }
/** * Check user throttle status. * * @param \Validation $extra_validation * @return bool * @throws \Cartalyst\Sentry\Throttling\UserBannedException * @throws \Cartalyst\Sentry\Throttling\UserSuspendedException */ public function check(\Validation $extra_validation = NULL) { if ($this->isBanned()) { throw new UserBannedException(sprintf('User [%s] has been banned.', $this->getUser()->getLogin())); } else { if ($this->isSuspended()) { throw new UserSuspendedException(sprintf('User [%s] has been suspended.', $this->getUser()->getLogin())); } } return parent::check($extra_validation); }
/** * Sync field values with * @param Validation $extra_validation * @todo Clean this up and enable error passing directly to fields */ public function check(Validation $extra_validation = NULL) { $ex = NULL; $errors = array(); // Reapply filters by setting objects again foreach ($this->table_columns() as $column => $definition) { if ($column == $this->primary_key()) { continue; } $this->{$column} = $this->{$column}; } try { parent::check($extra_validation); } catch (ORM_Validation_Exception $ex) { $errors = $ex->errors('models', TRUE); } // After applying filters, set field values back. foreach ($this->_z_fields as $column => $field) { $field->value = $this->{$column}; $field->error = Arr::get($errors, $column); } // Rethrow exception if ($ex instanceof ORM_Validation_Exception) { throw $ex; } }