Advertisement
Guest User

unzend.com_340

a guest
Oct 24th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.54 KB | None | 0 0
  1. <?php
  2. // Ioncube Decoder Unzend.Com Email unzend@gmail.com
  3. // http://www.unzend.com
  4. /**
  5.  * CRangeValidator class file.
  6.  *
  7.  * @author Qiang Xue <qiang.xue@gmail.com>
  8.  * @link http://www.yiiframework.com/
  9.  * @copyright 2008-2013 Yii Software LLC
  10.  * @license http://www.yiiframework.com/license/
  11.  */
  12.  
  13. /**
  14.  * CRangeValidator validates that the attribute value is among the list (specified via {@link range}).
  15.  * You may invert the validation logic with help of the {@link not} property (available since 1.1.5).
  16.  *
  17.  * @author Qiang Xue <qiang.xue@gmail.com>
  18.  * @package system.validators
  19.  * @since 1.0
  20.  */
  21. class CRangeValidator extends CValidator
  22. {
  23.     /**
  24.      * @var array list of valid values that the attribute value should be among
  25.      */
  26.     public $range;
  27.     /**
  28.      * @var boolean whether the comparison is strict (both type and value must be the same)
  29.      */
  30.     public $strict=false;
  31.     /**
  32.      * @var boolean whether the attribute value can be null or empty. Defaults to true,
  33.      * meaning that if the attribute is empty, it is considered valid.
  34.      */
  35.     public $allowEmpty=true;
  36.     /**
  37.      * @var boolean whether to invert the validation logic. Defaults to false. If set to true,
  38.      * the attribute value should NOT be among the list of values defined via {@link range}.
  39.      * @since 1.1.5
  40.      **/
  41.     public $not=false;
  42.  
  43.     /**
  44.      * Validates the attribute of the object.
  45.      * If there is any error, the error message is added to the object.
  46.      * @param CModel $object the object being validated
  47.      * @param string $attribute the attribute being validated
  48.      * @throws CException if given {@link range} is not an array
  49.      */
  50.     protected function validateAttribute($object,$attribute)
  51.     {
  52.         $value=$object->$attribute;
  53.         if($this->allowEmpty && $this->isEmpty($value))
  54.             return;
  55.         if(!is_array($this->range))
  56.             throw new CException(Yii::t('yii','The "range" property must be specified with a list of values.'));
  57.         $result = false;
  58.         if($this->strict)
  59.             $result=in_array($value,$this->range,true);
  60.         else
  61.         {
  62.             foreach($this->range as $r)
  63.             {
  64.                 $result=(strcmp($r,$value)===0);
  65.                 if($result)
  66.                     break;
  67.             }
  68.         }
  69.         if(!$this->not && !$result)
  70.         {
  71.             $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} is not in the list.');
  72.             $this->addError($object,$attribute,$message);
  73.         }
  74.         elseif($this->not && $result)
  75.         {
  76.             $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} is in the list.');
  77.             $this->addError($object,$attribute,$message);
  78.         }
  79.     }
  80.  
  81.     /**
  82.      * Returns the JavaScript needed for performing client-side validation.
  83.      * @param CModel $object the data object being validated
  84.      * @param string $attribute the name of the attribute to be validated.
  85.      * @throws CException if given {@link range} is not an array
  86.      * @return string the client-side validation script.
  87.      * @see CActiveForm::enableClientValidation
  88.      * @since 1.1.7
  89.      */
  90.     public function clientValidateAttribute($object,$attribute)
  91.     {
  92.         if(!is_array($this->range))
  93.             throw new CException(Yii::t('yii','The "range" property must be specified with a list of values.'));
  94.  
  95.         if(($message=$this->message)===null)
  96.             $message=$this->not ? Yii::t('yii','{attribute} is in the list.') : Yii::t('yii','{attribute} is not in the list.');
  97.         $message=strtr($message,array(
  98.             '{attribute}'=>$object->getAttributeLabel($attribute),
  99.         ));
  100.  
  101.         $range=array();
  102.         foreach($this->range as $value)
  103.             $range[]=(string)$value;
  104.         $range=CJSON::encode($range);
  105.  
  106.         return "
  107. if(".($this->allowEmpty ? "jQuery.trim(value)!='' && " : '').($this->not ? "jQuery.inArray(value, $range)>=0" : "jQuery.inArray(value, $range)<0").") {
  108.     messages.push(".CJSON::encode($message).");
  109. }
  110. ";
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement