Exemple #1
0
 /**
  * Called during validation operations, before validation. Please note that custom
  * validation rules can be defined in $validate.
  *
  * @param array $options Options passed from Model::save().
  * @return bool True if validate operation should continue, false to abort
  * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate
  * @see Model::save()
  */
 public function beforeValidate($options = array())
 {
     $this->loadModels(['User' => 'Users.User']);
     // ユーザ選択チェック
     if (!isset($this->data['GroupsUser']) || count($this->data['GroupsUser']) === 0) {
         $this->validationErrors['user_id'][] = __d('groups', 'Select user');
         return false;
     }
     // ユーザ存在チェック
     $userIdArr = Hash::extract($this->data['GroupsUser'], '{n}.user_id');
     if (!$this->User->existsUser($userIdArr)) {
         $this->validationErrors['user_id'][] = sprintf(__d('net_commons', 'Failed on validation errors. Please check the input data.'));
         return false;
     }
     // ユーザ選択上限チェック
     if (count($this->data['GroupsUser']) > GroupsUser::LIMIT_ENTRY_NUM) {
         $this->validationErrors['user_id'][] = sprintf(__d('groups', 'Can be registered upper limit is %s'), GroupsUser::LIMIT_ENTRY_NUM);
         return false;
     }
     return parent::beforeValidate($options);
 }
Exemple #2
0
 /**
  * Called during validation operations, before validation. Please note that custom
  * validation rules can be defined in $validate.
  *
  * @param array $options Options passed from Model::save().
  * @return bool True if validate operation should continue, false to abort
  * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate
  * @see Model::save()
  */
 public function beforeValidate($options = array())
 {
     $this->validate = array('name' => array('notBlank' => array('rule' => array('notBlank'), 'required' => true, 'allowEmpty' => false, 'message' => __d('groups', 'Please enter group name')), 'maxLength' => array('rule' => array('maxLength', Group::GROUP_NAME_MAX_LENGTH), 'message' => sprintf(__d('groups', 'Please enter group name no more than %s characters'), Group::GROUP_NAME_MAX_LENGTH))));
     return parent::beforeValidate($options);
 }