/** * Method for validation of status change flow * * @param AppModel $Model * @param array $data * @return boolean * @access public */ public function validateStatus($Model, $data) { if ($Model->exists() && ($current = $Model->field('status'))) { return in_array($data['status'], $this->settings[$Model->alias]['status'][$current]); } return false; }
/** * beforeSave callback, initializes created_by or modified_by field values * * @param AppModel $Model * @return boolean * @access public */ public function beforeSave($Model) { $field = $Model->exists() ? 'modified_by' : 'created_by'; if ($Model->hasField($field)) { $Model->set($field, $this->_getUserId()); $this->_addToWhitelist($Model, $field); } return true; }
/** * beforeSave callback, initializes unique code fields * * @param AppModel $Model * @return boolean * @access public */ public function beforeSave($Model) { extract($this->settings[$Model->alias]); if ($field && !$Model->exists()) { do { $token = $this->generateToken($Model, $length, $possible, $notStartWith); } while ((bool) $Model->find('count', array('conditions' => array($field => $token)))); $Model->set($field, $token); $this->_addToWhitelist($Model, $field); } return true; }
/** * Returns true if there is any row in this table matching the specified * conditions. * * @param array $conditions list of conditions to pass to the query * @return bool */ public function exists($conditions = null) { if (!is_array($conditions)) { return parent::exists($conditions); } return (bool) $this->find('count', ['conditions' => $conditions, 'recursive' => -1, 'callbacks' => false]); }