diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eb2068b..6da4321 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,12 +3,10 @@ on: branches: - main - master - - availability pull_request: branches: - main - master - - availability name: tests diff --git a/Controller/RegistrationAnswersController.php b/Controller/RegistrationAnswersController.php index 01ded77..7bdb316 100644 --- a/Controller/RegistrationAnswersController.php +++ b/Controller/RegistrationAnswersController.php @@ -19,7 +19,7 @@ * @property RegistrationAnswer $RegistrationAnswer * @property RegistrationsOwnAnswerComponent $RegistrationOwnAnswer * @property RegistrationAnswerSummary $RegistrationAnswerSummary - * + * * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class RegistrationAnswersController extends RegistrationsAppController { @@ -103,6 +103,9 @@ public function beforeFilter() { // 親クラスのbeforeFilterを済ませる parent::beforeFilter(); + // CDNキャッシュを作成しない + $this->response->header('Pragma', 'no-cache'); + // NetCommonsお約束:編集画面へのURLに編集対象のコンテンツキーが含まれている // まずは、そのキーを取り出す // 登録フォームキー @@ -220,11 +223,6 @@ protected function _viewGuard() { !isset($this->request->data['RegistrationPage']['page_sequence'])) { // 認証キーコンポーネントお約束: if ($quest['is_key_pass_use'] == RegistrationsComponent::USES_USE) { - $this->AuthorizationKey->contentId = $quest['id']; - $this->AuthorizationKey->guard( - AuthorizationKeyComponent::OPERATION_EMBEDDING, - 'Registration', - $this->__registration); $this->setAction('key_auth'); return; } @@ -247,6 +245,15 @@ protected function _viewGuard() { * @return void */ public function key_auth() { + $this->AuthorizationKey->contentId = $this->__registration['Registration']['id']; + $this->AuthorizationKey->guard( + AuthorizationKeyComponent::OPERATION_EMBEDDING, + 'Registration', + $this->__registration); + if ($this->request->is('ajax')) { + return; + } + $isKeyPassUse = $this->__registration['Registration']['is_key_pass_use']; if ($isKeyPassUse != RegistrationsComponent::USES_USE) { $this->_redirectAnswerPage(); @@ -383,11 +390,15 @@ public function view() { } } if (! ($this->request->is('post') && $nextPageSeq == $postPageSeq)) { - $summary = $this->RegistrationsOwnAnswer->getProgressiveSummaryOfThisUser( - $registrationKey); - $setAnswers = $this->RegistrationAnswer->getProgressiveAnswerOfThisSummary( - $registration, - $summary); + if (empty($this->request->params['requested'])) { + $summary = $this->RegistrationsOwnAnswer->getProgressiveSummaryOfThisUser( + $registrationKey); + $setAnswers = $this->RegistrationAnswer->getProgressiveAnswerOfThisSummary( + $registration, + $summary); + } else { + $setAnswers = []; + } $this->set('answers', $setAnswers); $this->request->data['RegistrationAnswer'] = $setAnswers; @@ -395,15 +406,16 @@ public function view() { // 誠にCake流儀でなくて申し訳ないのですが、様々な種別のAnswerデータを // 特殊な文字列加工して統一化した形状でDBに入れている都合上、このような仕儀になっています } else { - $this->set('answers', $this->request->data['RegistrationAnswer']); + $this->set('answers', $this->request->data['RegistrationAnswer'] ?? null); } + $nextPageSeq = (int)$nextPageSeq; // 項目情報をView変数にセット $this->request->data['Frame'] = Current::read('Frame'); $this->request->data['Block'] = Current::read('Block'); $this->request->data['RegistrationPage'] = $registration['RegistrationPage'][$nextPageSeq]; $this->set('registration', $registration); - $this->set('questionPage', $registration['RegistrationPage'][$nextPageSeq]); + $this->set('questionPage', $registration['RegistrationPage'][$nextPageSeq] ?? null); $this->set('displayType', $this->__displayType); $this->NetCommons->handleValidationError($this->RegistrationAnswer->validationErrors); diff --git a/Model/RegistrationAnswer.php b/Model/RegistrationAnswer.php index a7df869..cf415a3 100644 --- a/Model/RegistrationAnswer.php +++ b/Model/RegistrationAnswer.php @@ -284,6 +284,13 @@ public function saveAnswer($data, $registration, $summary) { if (! $targetQuestion) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } + + //HACK: 作りが悪いため、DELETE->INSERTで既存データを初期化してから登録する + $this->deleteAll([ + $this->alias . '.registration_answer_summary_id' => $summaryId, + $this->alias . '.registration_question_key' => $targetQuestionKey, + ], false); + // データ保存 // Matrixタイプの場合はanswerが配列になっているがsaveでかまわない // saveMany中で1回しかValidateしなくてよい関数のためのフラグ diff --git a/View/RegistrationAnswers/key_auth.ctp b/View/RegistrationAnswers/key_auth.ctp index 37e718c..843ae6e 100644 --- a/View/RegistrationAnswers/key_auth.ctp +++ b/View/RegistrationAnswers/key_auth.ctp @@ -8,16 +8,19 @@ * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ +echo $this->NetCommonsHtml->script(array( + '/authorization_keys/js/key_auth_init.js' +)); echo $this->NetCommonsHtml->css('/registrations/css/registration.css'); ?> -
+
element('Registrations.Answers/answer_header'); ?> element('Registrations.Answers/answer_test_mode_header'); ?> NetCommonsForm->create(null, array('type' => 'post', 'url' => $postUrl)); + echo $this->NetCommonsForm->create('AuthorizationKeys' . CurrentLib::read('Frame.id'), array('type' => 'post', 'url' => $postUrl)); echo $this->NetCommonsForm->hidden('Frame.id'); echo $this->NetCommonsForm->hidden('Block.id'); @@ -34,4 +37,4 @@ echo $this->NetCommonsHtml->css('/registrations/css/registration.css'); NetCommonsForm->end(); ?> -
\ No newline at end of file +