Exemple #1
0
 /**
  * Checks config
  * This is the 'checkConfig' validator as declared in rules().
  */
 public function checkConfig($attribute, $params)
 {
     //if owner_name class exists in configuration
     if (count($this->config) === 0) {
         if ($attribute === 'owner_name') {
             $this->addError($attribute, Yii::t('CommentsModule.msg', 'This item cann\'t be commentable'));
         }
         return;
     }
     //if only registered users can post comments
     if ($attribute === 'creator_id' && ($this->config['registeredOnly'] === true || Yii::app()->user->isGuest === false)) {
         unset($this->user_email, $this->user_name);
         $numberValidator = new CNumberValidator();
         $numberValidator->allowEmpty = false;
         $numberValidator->integerOnly = true;
         $numberValidator->attributes = array('creator_id');
         $numberValidator->validate($this);
     }
     //if se captcha validation on posting
     if ($attribute === 'verifyCode' && $this->config['useCaptcha'] === true) {
         $captchaValidator = new CCaptchaValidator();
         $captchaValidator->caseSensitive = false;
         $captchaValidator->captchaAction = Yii::app()->urlManager->createUrl(CommentsModule::CAPTCHA_ACTION_ROUTE);
         $captchaValidator->allowEmpty = !CCaptcha::checkRequirements();
         $captchaValidator->attributes = array('verifyCode');
         $captchaValidator->validate($this);
     }
     //if not only registered users can post comments and current user is guest
     if (($attribute === 'user_name' || $attribute === 'user_email') && ($this->config['registeredOnly'] === false && Yii::app()->user->isGuest === true)) {
         unset($this->creator_id);
         $requiredValidator = new CRequiredValidator();
         $requiredValidator->attributes = array($attribute);
         $requiredValidator->validate($this);
         $stringValidator = new CStringValidator();
         $stringValidator->max = 128;
         $stringValidator->attributes = array($attribute);
         $stringValidator->validate($this);
         if ($attribute === 'user_email') {
             $emailValidator = new CEmailValidator();
             $emailValidator->attributes = array('user_email');
             $emailValidator->validate($this);
         }
     }
 }