-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRoomsComponent.php
More file actions
174 lines (152 loc) · 5.09 KB
/
RoomsComponent.php
File metadata and controls
174 lines (152 loc) · 5.09 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
<?php
/**
* Rooms Component
*
* @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('Component', 'Controller');
/**
* Rooms Component
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Rooms\Controller\Component
*/
class RoomsComponent extends Component {
/**
* デフォルトロールキー
*
* @var array
*/
public $defaultRoleKeyList = null;
/**
* 一覧表示の参加者リスト件数
*
* @var const
*/
const LIST_LIMIT_ROOMS_USERS = 5;
/**
* Called before the Controller::beforeFilter().
*
* @param Controller $controller Controller with components to initialize
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize
*/
public function initialize(Controller $controller) {
//コンポーネント内でPaginatorを使うため、Paginatorがロードされている必要がある
$controller->Paginator = $controller->Components->load('Paginator');
//Modelの呼び出し
$controller->Room = ClassRegistry::init('Rooms.Room');
$controller->Role = ClassRegistry::init('Roles.Role');
$controller->RolesRoomsUser = ClassRegistry::init('Rooms.RolesRoomsUser');
$this->controller = $controller;
//スペースデータ取得&viewVarsにセット
$spaces = $controller->Room->getSpaces();
$controller->set('spaces', $spaces);
}
/**
* Called after the Controller::beforeFilter() and before the controller action
*
* @param Controller $controller Controller with components to startup
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup
*/
public function startup(Controller $controller) {
$controller->helpers[] = 'Rooms.Rooms';
if ($this->defaultRoleKeyList) {
$conditions = array(
'is_system' => true,
'language_id' => Current::read('Language.id'),
'type' => Role::ROLE_TYPE_ROOM,
'key' => $this->defaultRoleKeyList
);
} else {
$conditions = array(
'is_system' => true,
'language_id' => Current::read('Language.id'),
'type' => Role::ROLE_TYPE_ROOM,
);
}
$defaultRoles = $controller->Role->find('all', array(
'recursive' => -1,
'fields' => array('key', 'name', 'description'),
'conditions' => $conditions,
'order' => array('id' => 'asc')
));
$controller->set('defaultRoles', Hash::combine($defaultRoles, '{n}.{s}.key', '{n}.{s}'));
$controller->set(
'defaultRoleOptions', Hash::combine($defaultRoles, '{n}.{s}.key', '{n}.{s}.name')
);
}
/**
* ルームデータ取得
*
* @param int $spaceId スペースID
* @return void
*/
public function setRoomsForPaginator($spaceId = null) {
$controller = $this->controller;
if (! $spaceId) {
$getSpaces = [Space::PUBLIC_SPACE_ID, Space::COMMUNITY_SPACE_ID];
} else {
$getSpaces = [$spaceId];
}
$spaces = $controller->viewVars['spaces'];
$result = array();
foreach ($getSpaces as $spaceId) {
//ルームデータ取得
$controller->Paginator->settings = $controller->Room->getRoomsConditions(
$spaceId,
array('limit' => 1000, 'maxLimit' => 1000)
);
$rooms = $controller->Paginator->paginate('Room');
$rooms = Hash::combine($rooms, '{n}.Room.id', '{n}');
$roomIds = array_keys($rooms);
//Treeリスト取得
$roomTreeList = $controller->Room->generateTreeList(
array('Room.id' => array_merge(array($spaces[$spaceId]['Room']['id']), $roomIds)),
null,
null,
Room::$treeParser
);
$result[$spaceId]['rooms'] = $rooms;
$result[$spaceId]['roomTreeList'] = $roomTreeList;
}
if (count($getSpaces) > 1) {
$controller->set('rooms', $result);
} else {
$controller->set('rooms', $result[$spaceId]['rooms']);
$controller->set('roomTreeList', $result[$spaceId]['roomTreeList']);
}
}
/**
* ユーザIDが閲覧できるルームデータ取得
*
* @param int $userId ユーザID
* @return void
*/
public function setReadableRooms($userId = null) {
$controller = $this->controller;
//ルームデータ取得
$options = $controller->Room->getReadableRoomsConditions([], $userId);
$result = $controller->Room->find('all', $options);
$controller->set('rooms', Hash::combine($result, '{n}.Room.id', '{n}'));
//ルームのTreeリスト取得
$roomTreeLists[Space::PUBLIC_SPACE_ID] = $controller->Room->generateTreeList(
array('Room.space_id' => Space::PUBLIC_SPACE_ID), null, null, Room::$treeParser);
$roomTreeLists[Space::COMMUNITY_SPACE_ID] = $controller->Room->generateTreeList(
array('Room.space_id' => Space::COMMUNITY_SPACE_ID), null, null, Room::$treeParser);
$controller->set('roomTreeLists', $roomTreeLists);
//** ロールルームユーザデータ取得
$rolesRoomsUsers = $controller->RolesRoomsUser->getRolesRoomsUsers(array(
'RolesRoomsUser.user_id' => $userId,
));
$rolesRoomsUsers = Hash::combine(
$rolesRoomsUsers, '{n}.RolesRoomsUser.room_id', '{n}'
);
$controller->set('rolesRoomsUsers', $rolesRoomsUsers);
}
}