-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCabinetsAppController.php
More file actions
223 lines (200 loc) · 4.79 KB
/
CabinetsAppController.php
File metadata and controls
223 lines (200 loc) · 4.79 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
* CabinetsApp
*/
App::uses('AppController', 'Controller');
/**
* Class CabinetsAppController
*
* @property CabinetFrameSetting $CabinetFrameSetting
*/
class CabinetsAppController extends AppController {
/**
* @var array キャビネット名
*/
protected $_cabinetTitle;
/**
* @var array キャビネット設定
*/
protected $_cabinetSetting;
/**
* @var array フレーム設定
*/
protected $_frameSetting;
/**
* use components
*
* @var array
*/
public $components = array(
//'NetCommons.NetCommonsBlock',
//'NetCommons.NetCommonsFrame',
'Pages.PageLayout',
'Security',
);
/**
* @var array helpers
*/
public $helpers = array(
//'Cabinets.CabinetsFormat',
);
/**
* @var array use model
*/
public $uses = array(
'Cabinets.Cabinet',
'Cabinets.CabinetSetting',
'Cabinets.CabinetFrameSetting'
);
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
}
/**
* 現在時刻を返す。テストしやすくするためにメソッドに切り出した。
*
* @return int
*/
protected function _getNow() {
return time();
}
/**
* 現在の日時を返す
*
* @return string datetime
*/
protected function _getCurrentDateTime() {
return date('Y-m-d H:i:s', $this->_getNow());
}
/**
* ブロック名をキャビネットタイトルとしてセットする
*
* @return void
*/
protected function _setupCabinetTitle() {
$this->loadModel('Blocks.Block');
$block = $this->Block->find('first', array(
'recursive' => 0,
'conditions' => array(
'Block.id' => Current::read('Block.id')
)
));
$this->_cabinetTitle = $block['BlocksLanguage']['name'];
}
/**
* フレーム設定を読みこむ
*
* @return void
*/
protected function _loadFrameSetting() {
$this->_frameSetting = $this->CabinetFrameSetting->getCabinetFrameSetting(true);
}
/**
* 設定等の呼び出し
*
* @return void
*/
protected function _prepare() {
$this->_setupCabinetTitle();
$this->initCabinet(['cabinetSetting']);
$this->_loadFrameSetting();
}
/**
* initTabs
*
* @param string $mainActiveTab Main active tab
* @param string $blockActiveTab Block active tab
* @return void
*/
public function initTabs($mainActiveTab, $blockActiveTab) {
//タブの設定
$settingTabs = array(
'tabs' => array(
'block_index' => array(
'url' => array(
'plugin' => $this->params['plugin'],
'controller' => 'cabinet_blocks',
'action' => 'index',
Current::read('Frame.id'),
)
),
'frame_settings' => array(
'url' => array(
'plugin' => $this->params['plugin'],
'controller' => 'cabinet_frame_settings',
'action' => 'edit',
Current::read('Frame.id'),
),
),
),
'active' => $mainActiveTab
);
$this->set('settingTabs', $settingTabs);
$blockSettingTabs = array(
'tabs' => array(
'block_settings' => array(
'url' => array(
'plugin' => $this->params['plugin'],
'controller' => 'cabinet_blocks',
'action' => $this->params['action'],
Current::read('Frame.id'),
Current::read('Block.id')
)
),
'role_permissions' => array(
'url' => array(
'plugin' => $this->params['plugin'],
'controller' => 'cabinet_block_role_permissions',
'action' => 'edit',
Current::read('Frame.id'),
Current::read('Block.id')
)
),
),
'active' => $blockActiveTab
);
$this->set('blockSettingTabs', $blockSettingTabs);
}
/**
* initCabinet
*
* @param array $contains Optional result sets
* @return bool True on success, False on failure
*/
public function initCabinet($contains = []) {
if (!$cabinet = $this->Cabinet->getCabinet(
Current::read('Block.id'),
Current::read('Room.id')
)
) {
$this->throwBadRequest();
return false;
}
$cabinet = $this->camelizeKeyRecursive($cabinet);
$this->_cabinetTitle = $cabinet['cabinet']['name'];
$this->set($cabinet);
if (!$cabinetSetting = $this->CabinetSetting->getCabinetSetting()) {
$cabinetSetting = $this->CabinetSetting->createBlockSetting();
}
$this->_cabinetSetting = $cabinetSetting;
//$cabinetSetting = $this->camelizeKeyRecursive($cabinetSetting);
$this->set('cabinetSetting', $cabinetSetting['CabinetSetting']);
//$this->set($cabinetSetting);
// Cabinetでは_loadFrameSettingでやってる。
//if (in_array('cabinetFrameSetting', $contains, true)) {
// if (! $cabinetFrameSetting = $this->CabinetFrameSetting->getCabinetFrameSetting($this->viewVars['frameKey'])) {
// $cabinetFrameSetting = $this->CabinetFrameSetting->create(array(
// 'frame_key' => $this->viewVars['frameKey']
// ));
// }
// $cabinetFrameSetting = $this->camelizeKeyRecursive($cabinetFrameSetting);
// $this->set($cabinetFrameSetting);
//}
$this->set('userId', (int)$this->Auth->user('id'));
return true;
}
}