コード例 #1
0
ファイル: Number.php プロジェクト: shubnikofff/mobiles
 /**
  * @return array
  */
 public function rules()
 {
     return [[['number', 'operatorId'], 'required'], ['number', 'match', 'pattern' => '/^9[0-9]{9}$/'], ['number', 'unique'], ['ownerId', 'filter', 'filter' => function ($value) {
         return empty($value) ? null : (int) $value;
     }], ['ownerId', 'exist', 'targetClass' => Employee::className(), 'targetAttribute' => 'id'], ['limit', 'integer', 'min' => 0], ['limit', function ($attribute) {
         if ($this->accounting && empty($this->{$attribute})) {
             $this->addError($attribute, "При выбранной опции «Учитывать перерасход» лимит должен быть указан");
         }
     }, 'skipOnEmpty' => false], ['operatorId', MongoIdValidator::className(), 'forceFormat' => 'object'], ['operatorId', 'exist', 'targetClass' => Operator::className(), 'targetAttribute' => '_id'], ['destination', 'in', 'range' => [self::DESTINATION_MODEM, self::DESTINATION_PHONE]], ['options', function ($attribute) {
         $range = array_keys(Number::optionItems());
         foreach ($this->{$attribute} as $item) {
             if (!in_array($item, $range)) {
                 $this->addError('options', "Опция «{$item}» не существует.");
             }
         }
     }], ['comment', 'safe']];
 }
コード例 #2
0
ファイル: Billing.php プロジェクト: shubnikofff/mobiles
 public function rules()
 {
     return [[['periodInput', 'items', 'operatorId'], 'required'], ['periodInput', 'filter', 'filter' => function ($value) {
         $period = explode(self::PERIOD_DELIMITER, $value);
         $this->_period = ['month' => $period[0], 'year' => $period[1]];
         return $value;
     }], ['operatorId', MongoIdValidator::className(), 'forceFormat' => 'object'], ['operatorId', 'exist', 'targetClass' => Operator::className(), 'targetAttribute' => '_id'], ['items', 'filter', 'filter' => function ($value) {
         foreach ($value as $item) {
             if (is_numeric($item)) {
                 $this->_numbers[] = $item;
             } else {
                 $this->_employees[] = $item;
             }
             $res[$item] = $item;
         }
         return $value;
     }]];
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [['companyId', MongoIdValidator::className(), 'forceFormat' => 'object'], [['name', 'shortName', 'ipAddress', 'note'], 'safe']];
 }
コード例 #4
0
ファイル: Request.php プロジェクト: shubnikofff/teleport
 public function checkParticipantsIdFormat($attribute)
 {
     $participants = $this->{$attribute};
     $errorMessage = "{attribute} имеет неверный формат.";
     $participantsValue = [];
     if (is_array($participants)) {
         $mongoIdValidator = new MongoIdValidator();
         foreach ($participants as $participant) {
             if ($mongoIdValidator->validate($participant)) {
                 $participantsValue[] = new \MongoId($participant);
             } else {
                 $this->addError($attribute, $errorMessage);
                 return;
             }
         }
         $this->{$attribute} = $participantsValue;
         return;
     }
     $this->addError($attribute, $errorMessage);
 }
コード例 #5
0
ファイル: NumberSearch.php プロジェクト: shubnikofff/mobiles
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['searchText', 'comment'], 'trim'], ['operatorId', MongoIdValidator::className(), 'forceFormat' => 'object'], ['destination', 'safe']];
 }
コード例 #6
0
ファイル: Participant.php プロジェクト: shubnikofff/teleport
 /**
  * @return array
  */
 public function rules()
 {
     return [[['name', 'shortName'], 'required'], ['companyId', 'exist', 'targetClass' => Company::className(), 'targetAttribute' => '_id'], ['ahuConfirmation', 'boolean'], ['ahuConfirmation', 'filter', 'filter' => function ($value) {
         return boolval($value);
     }], ['confirmPersonId', 'exist', 'targetClass' => User::className(), 'targetAttribute' => '_id'], ['supportEmailsInput', function ($attribute) {
         if ($this->{$attribute} === "") {
             $this->supportEmails = [];
             return;
         }
         $value = explode(';', trim($this->{$attribute}, ';'));
         $validator = new EachValidator(['rule' => ['email']]);
         if ($validator->validate($value)) {
             $this->supportEmails = $value;
         } else {
             $this->addError($attribute, "Неверный формат");
         }
     }, 'skipOnEmpty' => false], ['ipAddress', 'match', 'pattern' => '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'], [['phone', 'contact', 'model', 'gatekeeperNumber', 'note'], 'safe'], [['companyId', 'confirmPersonId'], MongoIdValidator::className(), 'forceFormat' => 'object']];
 }