コード例 #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
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @see Model::save()
  */
 public function beforeValidate($options = array())
 {
     $qIndex = $options['questionIndex'];
     // Questionモデルは繰り返し判定が行われる可能性高いのでvalidateルールは最初に初期化
     // mergeはしません
     $this->validate = array('question_sequence' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.')), 'comparison' => array('rule' => array('comparison', '==', $qIndex), 'message' => __d('registrations', 'question sequence is illegal.'))), 'question_type' => array('inList' => array('rule' => array('inList', RegistrationsComponent::$typesList), 'message' => __d('net_commons', 'Invalid request.'))), 'question_value' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('registrations', 'Please input question text.'))), 'is_require' => array('boolean' => array('rule' => array('boolean'), 'message' => __d('net_commons', 'Invalid request.'))), 'is_choice_random' => array('boolean' => array('rule' => array('boolean'), 'message' => __d('net_commons', 'Invalid request.'))), 'is_skip' => array('boolean' => array('rule' => array('boolean'), 'message' => __d('net_commons', 'Invalid request.'))), 'is_result_display' => array('inList' => array('rule' => array('inList', $this->_getResultDisplayList($this->data['RegistrationQuestion']['question_type'])), 'message' => __d('net_commons', 'Invalid request.'))), 'result_display_type' => array('inList' => array('rule' => array('inList', RegistrationsComponent::$resultDispTypesList), 'message' => __d('net_commons', 'Invalid request.'))), 'is_range' => array('boolean' => array('rule' => array('boolean'), 'message' => __d('net_commons', 'Invalid request.'))));
     // 範囲制限設定された項目の場合
     if ($this->data['RegistrationQuestion']['is_range'] == true) {
         $this->validate = Hash::merge($this->validate, array('min' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('registrations', 'Please enter both the maximum and minimum values.')), 'comparison' => array('rule' => array('comparison', '<', $this->data['RegistrationQuestion']['max']), 'message' => __d('registrations', 'Please enter smaller value than max.'))), 'max' => array('notBlank' => array('rule' => array('notBlank'), 'message' => __d('registrations', 'Please enter both the maximum and minimum values.')), 'comparison' => array('rule' => array('comparison', '>', $this->data['RegistrationQuestion']['min']), 'message' => __d('registrations', 'Please enter bigger value than min.')))));
     }
     // validates時にはまだregistration_page_idの設定ができないのでチェックしないことにする
     // registration_page_idの設定は上位のRegistrationPageクラスで責任を持って行われるものとする
     parent::beforeValidate($options);
     $isSkip = $this->data['RegistrationQuestion']['is_skip'];
     // 付属の選択肢以下のvalidate
     if ($this->_checkChoiceExists() && isset($this->data['RegistrationChoice'])) {
         // この項目種別に必要な選択肢データがちゃんとあるなら選択肢をバリデート
         $validationErrors = array();
         foreach ($this->data['RegistrationChoice'] as $cIndex => $choice) {
             // 項目データバリデータ
             $this->RegistrationChoice->create();
             $this->RegistrationChoice->set($choice);
             $options['choiceIndex'] = $cIndex;
             $options['isSkip'] = $isSkip;
             if (!$this->RegistrationChoice->validates($options)) {
                 $validationErrors['RegistrationChoice'][$cIndex] = $this->RegistrationChoice->validationErrors;
             }
         }
         $this->validationErrors += $validationErrors;
     }
     return true;
 }
コード例 #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()
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function beforeValidate($options = array())
 {
     // ウィザード画面中はstatusチェックをしないでほしいので
     // ここに来る前にWorkflowBehaviorでつけられたstatus-validateを削除しておく
     if (Hash::check($options, 'validate') == RegistrationsComponent::REGISTRATION_VALIDATE_TYPE) {
         $this->validate = Hash::remove($this->validate, 'status');
     }
     $this->validate = Hash::merge($this->validate, array('block_id' => array('numeric' => array('rule' => array('numeric'), 'message' => __d('net_commons', 'Invalid request.'), 'on' => 'update')), 'title' => array('rule' => 'notBlank', 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('registrations', 'Title')), 'required' => true, 'allowEmpty' => false), 'answer_timing' => array('publicTypeCheck' => array('rule' => array('inList', array(RegistrationsComponent::USES_USE, RegistrationsComponent::USES_NOT_USE)), 'message' => __d('net_commons', 'Invalid request.')), 'requireOtherFields' => array('rule' => array('requireOtherFields', RegistrationsComponent::USES_USE, array('Registration.answer_start_period', 'Registration.answer_end_period'), 'OR'), 'message' => __d('registrations', 'if you set the period, please set time.'))), 'answer_start_period' => array('checkDateTime' => array('rule' => 'checkDateTime', 'message' => __d('registrations', 'Invalid datetime format.'))), 'answer_end_period' => array('checkDateTime' => array('rule' => 'checkDateTime', 'message' => __d('registrations', 'Invalid datetime format.')), 'checkDateComp' => array('rule' => array('checkDateComp', '>=', 'answer_start_period'), 'message' => __d('registrations', 'start period must be smaller than end period'))), 'is_key_pass_use' => array('boolean' => array('rule' => array('boolean'), 'message' => __d('net_commons', 'Invalid request.')), 'requireOtherFieldsKey' => array('rule' => array('requireOtherFields', RegistrationsComponent::USES_USE, array('AuthorizationKey.authorization_key'), 'AND'), 'message' => __d('registrations', 'if you set the use key phrase period, please set key phrase text.')), 'authentication' => array('rule' => array('requireOtherFields', RegistrationsComponent::USES_USE, array('Registration.is_image_authentication'), 'XOR'), 'message' => __d('registrations', 'Authentication key setting , image authentication , either only one can not be selected.'))), 'is_image_authentication' => array('boolean' => array('rule' => array('boolean'), 'message' => __d('net_commons', 'Invalid request.')), 'authentication' => array('rule' => array('requireOtherFields', RegistrationsComponent::USES_USE, array('Registration.is_key_pass_use'), 'XOR'), 'message' => __d('registrations', 'Authentication key setting , image authentication , either only one can not be selected.'))), 'is_answer_mail_send' => array('boolean' => array('rule' => array('boolean'), 'message' => __d('net_commons', 'Invalid request.'))), 'is_regist_user_send' => array('boolean' => array('rule' => array('boolean'), 'message' => __d('net_commons', 'Invalid request.'))), 'reply_to' => array('email' => array('rule' => array('email', false, null), 'message' => sprintf(__d('mails', '%s, please enter by e-mail format'), __d('mails', 'E-mail address to receive a reply')), 'allowEmpty' => true))));
     parent::beforeValidate($options);
     // 最低でも1ページは存在しないとエラー
     if (!isset($this->data['RegistrationPage'][0])) {
         $this->validationErrors['pickup_error'] = __d('registrations', 'please set at least one page.');
     } else {
         // ページデータが存在する場合
         // 配下のページについてバリデート
         $validationErrors = array();
         $maxPageIndex = count($this->data['RegistrationPage']);
         $options['maxPageIndex'] = $maxPageIndex;
         foreach ($this->data['RegistrationPage'] as $pageIndex => $page) {
             // それぞれのページのフィールド確認
             $this->RegistrationPage->create();
             $this->RegistrationPage->set($page);
             // ページシーケンス番号の正当性を確認するため、現在の配列インデックスを渡す
             $options['pageIndex'] = $pageIndex;
             if (!$this->RegistrationPage->validates($options)) {
                 $validationErrors['RegistrationPage'][$pageIndex] = $this->RegistrationPage->validationErrors;
             }
         }
         $this->validationErrors += $validationErrors;
     }
     // 引き続き登録フォーム本体のバリデートを実施してもらうためtrueを返す
     return true;
 }
コード例 #3
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()
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function beforeValidate($options = array())
 {
     // option情報取り出し
     $summaryId = $options['registration_answer_summary_id'];
     $this->data['RegistrationAnswer']['registration_answer_summary_id'] = $summaryId;
     $question = $options['question'];
     $allAnswers = $options['allAnswers'];
     // Answerモデルは繰り返し判定が行われる可能性高いのでvalidateルールは最初に初期化
     // mergeはしません
     $this->validate = array('registration_answer_summary_id' => array('numeric' => array('rule' => array('numeric'), 'allowEmpty' => true)), 'registration_question_key' => array('notBlank' => array('rule' => array('notBlank'), 'allowEmpty' => false, 'required' => true)), 'answer_value' => array('answerRequire' => array('rule' => array('answerRequire', $question), 'message' => __d('registrations', 'Input required')), 'answerMaxLength' => array('rule' => array('answerMaxLength', $question, RegistrationsComponent::REGISTRATION_MAX_ANSWER_LENGTH), 'message' => sprintf(__d('registrations', 'the answer is too long. Please enter under %d letters.', RegistrationsComponent::REGISTRATION_MAX_ANSWER_LENGTH))), 'answerChoiceValidation' => array('rule' => array('answerChoiceValidation', $question, $allAnswers), 'last' => true, 'message' => ''), 'answerTextValidation' => array('rule' => array('answerTextValidation', $question, $allAnswers), 'last' => true, 'message' => ''), 'answerDatetimeValidation' => array('rule' => array('answerDatetimeValidation', $question, $allAnswers), 'last' => true, 'message' => ''), 'answerMatrixValidation' => array('rule' => array('answerMatrixValidation', $question, $allAnswers), 'last' => true, 'message' => ''), 'answerEmailValidation' => array('rule' => array('answerEmailValidation', $question, $allAnswers), 'last' => true, 'message' => __d('mails', '%s, please enter by e-mail format', $question['question_value'])), 'answerEmailConfirmValidation' => array('rule' => array('answerEmailConfirmValidation', $question, $allAnswers), 'last' => true, 'message' => __d('net_commons', 'The input data does not match. Please try again.'))));
     parent::beforeValidate($options);
     return true;
 }
コード例 #4
0
 /**
  * Constructor. Binds the model's database table to the object.
  *
  * @param bool|int|string|array $id Set this ID for this model on startup,
  * can also be an array of options, see above.
  * @param string $table Name of database table to use.
  * @param string $ds DataSource connection name.
  * @see Model::__construct()
  * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
  */
 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     $this->loadModels(['Registration' => 'Registrations.Registration', 'RegistrationAnswer' => 'Registrations.RegistrationAnswer']);
 }
コード例 #5
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()
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function beforeValidate($options = array())
 {
     $pageIndex = $options['pageIndex'];
     // Pageモデルは繰り返し判定が行われる可能性高いのでvalidateルールは最初に初期化
     // mergeはしません
     $this->validate = array('page_sequence' => array('numeric' => array('rule' => array('numeric')), 'comparison' => array('rule' => array('comparison', '==', $pageIndex), 'message' => __d('registrations', 'page sequence is illegal.'))), 'route_number' => array('numeric' => array('rule' => array('numeric'))));
     // validates時にはまだregistration_idの設定ができないのでチェックしないことにする
     // registration_idの設定は上位のRegistrationクラスで責任を持って行われるものとする
     parent::beforeValidate($options);
     // 付属の項目以下のvalidate
     if (!isset($this->data['RegistrationQuestion'][0])) {
         $this->validationErrors['page_sequence'][] = __d('registrations', 'please set at least one question.');
     } else {
         $validationErrors = array();
         foreach ($this->data['RegistrationQuestion'] as $qIndex => $question) {
             // 項目データバリデータ
             $this->RegistrationQuestion->create();
             $this->RegistrationQuestion->set($question);
             $options['questionIndex'] = $qIndex;
             if (!$this->RegistrationQuestion->validates($options)) {
                 $validationErrors['RegistrationQuestion'][$qIndex] = $this->RegistrationQuestion->validationErrors;
             }
         }
         $this->validationErrors += $validationErrors;
     }
     return true;
 }
コード例 #6
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()
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function beforeValidate($options = array())
 {
     $this->validate = Hash::merge($this->validate, array('create_option' => array('rule' => array('inList', array(RegistrationsComponent::REGISTRATION_CREATE_OPT_NEW, RegistrationsComponent::REGISTRATION_CREATE_OPT_REUSE, RegistrationsComponent::REGISTRATION_CREATE_OPT_TEMPLATE)), 'message' => __d('registrations', 'Please choose create option.'), 'required' => true), 'title' => array('rule' => array('requireWhen', 'create_option', RegistrationsComponent::REGISTRATION_CREATE_OPT_NEW), 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('registrations', 'Title')), 'required' => false), 'past_registration_id' => array('requireWhen' => array('rule' => array('requireWhen', 'create_option', RegistrationsComponent::REGISTRATION_CREATE_OPT_REUSE), 'message' => __d('registrations', 'Please select past registration.')), 'checkPastRegistration' => array('rule' => array('checkPastRegistration'), 'message' => __d('registrations', 'Please select past registration.')))));
     return parent::beforeValidate($options);
 }