-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRegistrationAddController.php
More file actions
151 lines (137 loc) · 4.48 KB
/
RegistrationAddController.php
File metadata and controls
151 lines (137 loc) · 4.48 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
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* RegistrationsAdd 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('AppController', 'Controller');
/**
* RegistrationsAddController
*
* @author Allcreator <info@allcreator.net>
* @package NetCommons\Registrations\Controller
*/
class RegistrationAddController extends RegistrationsAppController {
/**
* 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',
),
),
'Registrations.Registrations',
'Registrations.RegistrationBlockTabs',
);
/**
* use helpers
*
* @var array
*/
public $helpers = array(
'Registrations.RegistrationStatusLabel',
'Registrations.RegistrationUtil'
);
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
// ここへは設定画面の一覧から来たのか、一般画面の一覧から来たのか
$this->_decideSettingLayout();
}
/**
* add registration display method
*
* @return void
*/
public function add() {
// NetCommonsお約束:投稿権限のある人物しかこのアクションにアクセスできない
// それは$componentsの組み込みでallow => add => content_creatableで担保される
// アクション処理内でチェックする必要はない
unset($this->helpers['Blocks.BlockTabs']['blockTabs']['role_permissions']);
unset($this->helpers['Blocks.BlockTabs']['blockTabs']['mail_settings']);
unset($this->helpers['Blocks.BlockTabs']['blockTabs']['answer_list']);
// POSTされたデータを読み取り
if ($this->request->is('post')) {
// Postデータをもとにした新登録フォームデータの取得をModelに依頼する
$actionModel = ClassRegistry::init('Registrations.ActionRegistrationAdd', 'true');
if ($registration = $actionModel->createRegistration($this->request->data)) {
$tm = $this->_getRegistrationEditSessionIndex();
// 作成中登録フォームデータをセッションキャッシュに書く
$this->Session->write('Registrations.registrationEdit.' . $tm, $registration);
// 次の画面へリダイレクト
$urlArray = array(
'controller' => 'registration_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);
}
} else {
// 新規に登録フォームを作成するときは最初にブロックをつくっておく
$frame['Frame'] = Current::read('Frame');
$this->Registration->createBlock($frame);
}
// 過去データ 取り出し
$conditions = Hash::remove($this->Registration->getBaseCondition(), 'block_id');
unset($conditions['Registration.block_id']);
$conditions['Block.room_id'] = Current::read('Room.id');
$pastRegistrations = $this->Registration->find('all',
array(
'fields' => array(
'id', 'title', 'status', 'answer_timing', 'answer_start_period', 'answer_end_period',
),
'conditions' => $conditions,
'offset' => 0,
'limit' => 1000,
'recursive' => 0,
'order' => array('Registration.modified DESC'),
));
$this->set('pastRegistrations', $pastRegistrations);
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('ActionRegistrationAdd.create_option')) {
$this->request->data(
'ActionRegistrationAdd.create_option',
RegistrationsComponent::REGISTRATION_CREATE_OPT_NEW);
}
}
}