-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRoomsAppController.php
More file actions
161 lines (144 loc) · 3.47 KB
/
RoomsAppController.php
File metadata and controls
161 lines (144 loc) · 3.47 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
<?php
/**
* RoomsApp 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('AppController', 'Controller');
App::uses('Space', 'Rooms.Model');
/**
* RoomsApp Controller
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Rooms\Controller
*/
class RoomsAppController extends AppController {
/**
* ウィザード定数(一般設定)
*
* @var string
*/
const WIZARD_ROOMS = 'rooms';
/**
* ウィザード定数(参加者の管理)
*
* @var string
*/
const WIZARD_ROOMS_ROLES_USERS = 'rooms_roles_users';
/**
* ウィザード定数(プラグイン選択)
*
* @var string
*/
const WIZARD_PLUGINS_ROOMS = 'plugins_rooms';
/**
* use model
*
* @var array
*/
public $uses = array(
'Pages.Page',
'Rooms.Room',
'Rooms.Space',
);
/**
* use component
*
* @var array
*/
public $components = array(
'ControlPanel.ControlPanelLayout',
'NetCommons.Permission' => array(
'type' => PermissionComponent::CHECK_TYPE_SYSTEM_PLUGIN,
'allow' => array()
),
'Rooms.Rooms',
'Security',
);
/**
* use helpers
*
* @var array
*/
public $helpers = array(
'Rooms.RoomsForm',
);
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->deny('index', 'view');
//スペースデータチェック
if (isset($this->params['pass'][0])) {
$spaceId = $this->params['pass'][0];
} else {
$spaceId = null;
}
if (! $this->Room->Space->cacheExistsQuery($spaceId)) {
return $this->setAction('throwBadRequest');
}
$this->set('activeSpaceId', $spaceId);
//ルームデータチェック&セット
if ($this->params['action'] !== 'index') {
//ルームデータのセット
$this->_setRoom();
//親ルームデータのセット
$this->_setParentRooms();
}
}
/**
* ルームデータをセットする
*
* @return void
*/
protected function _setRoom() {
if ($this->Session->read('RoomAdd.Room.id')) {
$roomId = $this->Session->read('RoomAdd.Room.parent_id');
} elseif ($this->request->is('post')) {
$roomId = Hash::get($this->data, 'Room.parent_id');
} elseif ($this->request->is('put') || $this->request->is('delete')) {
$roomId = Hash::get($this->data, 'Room.id');
} else {
$roomId = Hash::get($this->params['pass'], '1');
}
$room = $this->Room->findById($roomId);
if (! $room) {
return $this->setAction('throwBadRequest');
}
$this->set('room', $room);
$this->set('activeRoomId', $roomId);
$this->set('activeSpaceId', $room['Space']['id']);
}
/**
* 親ルームデータをセットする
*
* @return void
*/
protected function _setParentRooms() {
$roomId = $this->viewVars['activeRoomId'];
$spaceRoomIds = $this->Space->cacheFindQuery('list', [
'recursive' => -1,
'fields' => ['id', 'room_id_root']
]);
if (! in_array($roomId, $spaceRoomIds, true)) {
$parentRooms = $this->Room->getPath($roomId, null, 1);
//サイト全体のルームIDを削除する
if (Hash::get($parentRooms, '0.Space.id') === Space::WHOLE_SITE_ID) {
unset($parentRooms[0]);
}
//if (in_array(Hash::get($parentRooms, '1.Room.id'), $spaceRoomIds, true)) {
// unset($parentRooms[1]);
//}
$this->set('parentRooms', $parentRooms);
} else {
$this->set('parentRooms', null);
}
}
}