-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuFrameSettingsController.php
More file actions
149 lines (133 loc) · 3.51 KB
/
MenuFrameSettingsController.php
File metadata and controls
149 lines (133 loc) · 3.51 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
<?php
/**
* MenuFrameSettings Controller
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('MenusAppController', 'Menus.Controller');
/**
* MenuFrameSettings Controller
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Menus\Controller
*/
class MenuFrameSettingsController extends MenusAppController {
/**
* layout
*
* @var array
*/
public $layout = 'NetCommons.setting';
/**
* use components
*
* @var array
*/
public $components = array(
'NetCommons.Permission' => array(
'allow' => array(
'edit' => 'page_editable',
),
),
);
/**
* Model name
*
* @var array
*/
public $uses = array(
'Menus.MenuFrameSetting',
'Menus.MenuFramesRoom',
'Pages.Page',
);
/**
* use helpers
*
* @var array
*/
public $helpers = array(
'Menus.Menu',
'Menus.MenuForm'
);
/**
* beforeRender
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
$page = $this->Page->getPageWithFrame('');
$this->set('page', $page);
}
/**
* 前準備
*
* @return void
*/
protected function _prepare() {
//ルームデータ取得
$conditions = $this->Room->getReadableRoomsConditions();
//$conditions['recursive'] = 0;
//$conditions['fields'] = ['Room.id', 'Room.page_id_top'];
$rooms = $this->Room->find('all', $conditions);
if (! $rooms) {
return $this->setAction('throwBadRequest');
}
$setRoom = [];
foreach ($rooms as $r) {
$setRoom[$r['Room']['id']] = $r;
}
$this->set('rooms', $setRoom);
//メニューデータ取得
$menus = $this->MenuFramesPage->getMenuData(array(
'conditions' => array(
$this->Page->alias . '.room_id' => array_keys($this->viewVars['rooms'])
)
));
$this->set('menus', $menus);
}
/**
* edit
*
* @return void
*/
public function edit() {
//フレームなしの場合、
if (! Current::read('Frame.id')) {
return $this->emptyRender();
}
$roomIds = array_keys($this->viewVars['rooms']);
$pages = $this->Page->getPages($roomIds);
$this->set('pages', $pages);
if ($this->request->is(array('post', 'put'))) {
//不要パラメータ除去
unset($this->request->data['save']);
//登録処理
foreach ($this->request->data['MenuRooms'] as $i => $menuRoom) {
$roomId = $menuRoom['MenuFramesRoom']['room_id'] ?? null;
$pageId = $menuRoom['MenuFramesRoom']['page_id_top'] ?? null;
$isHidden =
$this->request->data['Menus'][$roomId][$pageId]['MenuFramesPage']['is_hidden'] ?? null;
$this->request->data['MenuRooms'][$i]['MenuFramesRoom']['is_hidden'] = $isHidden;
}
if ($this->MenuFrameSetting->saveMenuFrameSetting($this->request->data)) {
return $this->redirect(NetCommonsUrl::backToPageUrl());
}
$this->NetCommons->handleValidationError($this->MenuFrameSetting->validationErrors);
}
$this->request->data += $this->MenuFrameSetting->getMenuFrameSetting();
$this->request->data['Frame'] = Current::read('Frame');
$this->request->data['Menus'] = $this->viewVars['menus'];
$this->request->data['MenuRooms'] = $this->MenuFramesRoom->getMenuFrameRooms(array(
'conditions' => array($this->Room->alias . '.id' => $roomIds)
));
//Treeリスト取得
$pageTreeList = $this->Page->generateTreeList(
array('Page.room_id' => $roomIds), null, null, Page::$treeParser);
$this->set('pageTreeList', $pageTreeList);
}
}