Example #1
0
 /**
  * Test value and return boolean
  *
  * @param mixed $value
  *
  * @return bool
  * @throws ValidateFailException
  */
 protected function test($value)
 {
     $user = User::get(array($this->field => $value));
     if ($user->notNull()) {
         throw new ValidateFailException(Translator::sprintf('warder.user.save.message.exists', $this->field, $value));
     }
     return true;
 }
Example #2
0
 /**
  * check
  *
  * @return  static
  */
 public function check()
 {
     $loginName = WarderHelper::getLoginName();
     if (!$this->{$loginName}) {
         throw new \InvalidArgumentException(Translator::translate('warder.user.account.empty'));
     }
     $exists = UserMapper::findOne(array($loginName => $this->{$loginName}));
     if ($exists->notNull() && $this->id != $exists->id) {
         throw new \InvalidArgumentException(Translator::sprintf('warder.user.save.message.exists', $loginName, $this->{$loginName}));
     }
     if ($this->email) {
         $exists = UserMapper::findOne(array('email' => $this->email));
         if ($exists->notNull() && $this->id != $exists->id) {
             throw new \InvalidArgumentException(Translator::sprintf('warder.user.save.message.exists', $loginName, $this->email));
         }
     }
     return $this;
 }
Example #3
0
 /**
  * setTitle
  *
  * @param string $title
  *
  * @return  static
  */
 public function setTitle($title = null)
 {
     $title = $title ?: Translator::sprintf('phoenix.title.grid', Translator::translate($this->langPrefix . $this->getName() . '.title'));
     return parent::setTitle($title);
 }
 /**
  * validate
  *
  * @param   array $data
  * @param   Form  $form
  *
  * @return bool
  * @throws ValidateFailException
  */
 public function validate($data, Form $form = null)
 {
     $form = $form ?: $this->getForm('edit');
     $form->bind($data);
     if ($form->validate()) {
         return true;
     }
     $errors = $form->getErrors();
     $msg = array();
     foreach ($errors as $error) {
         $field = $error->getField();
         if ($error->getResult() == ValidateResult::STATUS_REQUIRED) {
             $msg[ValidateResult::STATUS_REQUIRED][] = Translator::sprintf('phoenix.message.validation.required', $field->getLabel() ?: $field->getName(false));
         } elseif ($error->getResult() == ValidateResult::STATUS_FAILURE) {
             $msg[ValidateResult::STATUS_FAILURE][] = Translator::sprintf('phoenix.message.validation.failure', $field->getLabel() ?: $field->getName(false));
         }
     }
     throw new ValidateFailException($msg);
 }