-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQuestionnaireAddController.php
More file actions
138 lines (126 loc) · 3.92 KB
/
QuestionnaireAddController.php
File metadata and controls
138 lines (126 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* QuestionnairesAdd Controller
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Allcreator <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('QuestionnairesAppController', 'Questionnaires.Controller');
/**
* QuestionnairesAddController
*
* @author Allcreator <info@allcreator.net>
* @package NetCommons\Questionnaires\Controller
*/
class QuestionnaireAddController extends QuestionnairesAppController {
/**
* use model
*
* @var array
*/
public $uses = array(
'PluginManager.Plugin',
);
/**
* use components
*
* @var array
*/
public $components = array(
'Files.FileUpload', // FileUpload
'NetCommons.Permission' => array(
//アクセスの権限
'allow' => array(
'add' => 'content_creatable',
),
),
'Questionnaires.Questionnaires',
);
/**
* use helpers
*
* @var array
*/
public $helpers = array(
'Questionnaires.QuestionnaireStatusLabel',
'Questionnaires.QuestionnaireUtil'
);
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
// ここへは設定画面の一覧から来たのか、一般画面の一覧から来たのか
$this->_decideSettingLayout();
}
/**
* add questionnaire display method
*
* @return void
*/
public function add() {
// NetCommonsお約束:投稿権限のある人物しかこのアクションにアクセスできない
// それは$componentsの組み込みでallow => add => content_creatableで担保される
// アクション処理内でチェックする必要はない
// POSTされたデータを読み取り
if ($this->request->is('post')) {
// Postデータをもとにした新アンケートデータの取得をModelに依頼する
$actionModel = ClassRegistry::init('Questionnaires.ActionQuestionnaireAdd', 'true');
if ($questionnaire = $actionModel->createQuestionnaire($this->request->data)) {
$tm = $this->_getQuestionnaireEditSessionIndex();
// 作成中アンケートデータをセッションキャッシュに書く
$this->Session->write('Questionnaires.questionnaireEdit.' . $tm, $questionnaire);
// 次の画面へリダイレクト
$urlArray = array(
'controller' => 'questionnaire_edit',
'action' => 'edit_question',
Current::read('Block.id'),
'frame_id' => Current::read('Frame.id'),
's_id' => $tm,
);
if ($this->layout == 'NetCommons.setting') {
$urlArray['q_mode'] = 'setting';
}
$this->redirect(NetCommonsUrl::actionUrl($urlArray));
return;
} else {
// データに不備があった場合
$this->NetCommons->handleValidationError($actionModel->validationErrors);
}
}
// 過去データ 取り出し
$pastQuestionnaires = $this->Questionnaire->find('all',
array(
'fields' => array(
'id', 'title', 'status', 'answer_timing', 'answer_start_period', 'answer_end_period',
),
'conditions' => $this->Questionnaire->getBaseCondition(),
'offset' => 0,
'limit' => 1000,
'recursive' => -1,
'order' => array('Questionnaire.modified DESC'),
));
$this->set('pastQuestionnaires', $pastQuestionnaires);
if ($this->layout == 'NetCommons.setting') {
$this->set('cancelUrl', NetCommonsUrl::backToIndexUrl('default_setting_action'));
} else {
$this->set('cancelUrl', NetCommonsUrl::backToPageUrl());
}
//
// NetCommonsお約束:投稿のデータはrequest dataに設定する
//
$this->request->data['Frame'] = Current::read('Frame');
$this->request->data['Block'] = Current::read('Block');
// create_optionが未設定のときは初期値として「NEW」を設定する
if (! $this->request->data('ActionQuestionnaireAdd.create_option')) {
$this->request->data(
'ActionQuestionnaireAdd.create_option',
QuestionnairesComponent::QUESTIONNAIRE_CREATE_OPT_NEW);
}
}
}