-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRoomsFormHelper.php
More file actions
483 lines (424 loc) · 12.6 KB
/
RoomsFormHelper.php
File metadata and controls
483 lines (424 loc) · 12.6 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<?php
/**
* Rooms Helper
*
* @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('AppHelper', 'View/Helper');
App::uses('Room', 'Rooms.Model');
/**
* ルームFormヘルパー
*
* RoomsFormComponentとセットで使用する
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\UserAttribute\View\Helper
*/
class RoomsFormHelper extends AppHelper {
/**
* 使用するヘルパー
*
* @var array
*/
public $helpers = array(
'NetCommons.LinkButton',
'NetCommons.MessageFlash',
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
'Rooms.Rooms',
);
/**
* Before render callback. beforeRender is called before the view file is rendered.
*
* Overridden in subclasses.
*
* @param string $viewFile The view file that is going to be rendered
* @return void
*/
public function beforeRender($viewFile) {
$this->NetCommonsHtml->css('/rooms/css/style.css');
parent::beforeRender($viewFile);
}
/**
* Roomに対するプラグインチェックボックスリスト
*
* @param string $fieldName フィールド名
* @param array $attributes HTMLの属性オプション
* @return string HTML
*/
public function checkboxRooms($fieldName, $attributes = array()) {
$html = '';
$roomTreeList = $this->_View->viewVars['roomTreeList'];
if (! $roomTreeList) {
return $html;
}
$html .= $this->NetCommonsForm->hidden($fieldName, array(
'value' => false,
));
$this->NetCommonsForm->unlockField($fieldName);
$html .= '<dl>';
foreach ($roomTreeList as $roomId => $tree) {
$nest = substr_count($tree, Room::$treeParser);
$html .= $this->__room($fieldName, $roomId, $nest, $attributes);
}
$html .= '</dl>';
return $html;
}
/**
* Roomに対するプラグインチェックボックスリスト
*
* self::checkboxRooms()から実行される
*
* @param string $fieldName フィールド名
* @param int $roomId ルームID
* @param string $nest インデント
* @param array $attributes HTMLの属性オプション
* @return string HTML
*/
private function __room($fieldName, $roomId, $nest, $attributes = array()) {
$html = '';
$rooms = $this->_View->viewVars['rooms'];
$default = Hash::get($attributes, 'default', array());
if (! Hash::get($rooms, $roomId) ||
Hash::get($rooms, $roomId . '.Room.space_id') === Space::PRIVATE_SPACE_ID &&
! Hash::get($attributes, 'privateSpace', true)) {
return $html;
}
$room = Hash::get($rooms, $roomId);
$html .= '<dd class="form-group form-inline">';
$html .= str_repeat('<span class="rooms-tree"> </span>', $nest);
$html .= $this->NetCommonsForm->checkbox($fieldName . '.', array(
'label' => $this->Rooms->roomName($room),
'escape' => false,
'div' => false,
'id' => $this->domId($fieldName . $roomId),
'value' => $roomId,
'hiddenField' => false,
'checked' => in_array((string)$roomId, $default, true),
));
$html .= $this->NetCommonsForm->hidden('Room.' . $roomId . '.id', array(
'value' => $roomId
));
$html .= '</dd>';
return $html;
}
/**
* ルーム設定タブの出力
*
* @return string HTML
*/
public function settingTabs() {
$activeSpaceId = $this->_View->viewVars['activeSpaceId'];
if (isset($this->_View->viewVars['activeRoomId'])) {
$activeRoomId = $this->_View->viewVars['activeRoomId'];
} else {
$activeRoomId = null;
}
$output = '';
if ($this->_View->params['action'] === 'add') {
$disabled = 'disabled';
$urlRooms = '#';
$urlRolesRoomsUsers = '#';
$urlPluginsRooms = '#';
} else {
$disabled = '';
$urlRooms = '/rooms/rooms/' . $this->_View->params['action'] . '/' .
h($activeSpaceId) . '/' . h($activeRoomId) . '/';
$urlRolesRoomsUsers = '/rooms/rooms_roles_users/edit/' .
h($activeSpaceId) . '/' . h($activeRoomId) . '/';
$urlPluginsRooms = '/rooms/plugins_rooms/edit/' .
h($activeSpaceId) . '/' . h($activeRoomId) . '/';
}
$output .= '<ul class="nav nav-pills" role="tablist">';
if ($this->_View->params['controller'] === 'rooms') {
$class = 'active';
} else {
$class = $disabled;
}
$output .= '<li class="' . $class . '">';
$output .= $this->NetCommonsHtml->link(__d('rooms', 'General setting'), $urlRooms);
$output .= '</li>';
$communityRoomId = Space::getRoomIdRoot(Space::COMMUNITY_SPACE_ID);
$privateRoomId = Space::getRoomIdRoot(Space::PRIVATE_SPACE_ID);
$noRoomsRolesUsers = [$privateRoomId, $communityRoomId];
if (! in_array(Hash::get($this->_View->request->data, 'Room.id'), $noRoomsRolesUsers, true)) {
if ($this->_View->params['controller'] === 'rooms_roles_users') {
$class = 'active';
} else {
$class = $disabled;
}
$output .= '<li class="' . $class . '">';
$output .= $this->NetCommonsHtml->link(
__d('rooms', 'Edit the members to join'), $urlRolesRoomsUsers
);
$output .= '</li>';
}
if (Hash::get($this->_View->request->data, 'Room.id') !== $communityRoomId) {
if ($this->_View->params['controller'] === 'plugins_rooms') {
$class = 'active';
} else {
$class = $disabled;
}
$output .= '<li class="' . $class . '">';
$output .= $this->NetCommonsHtml->link(
__d('rooms', 'Select the plugins to join'), $urlPluginsRooms
);
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
/**
* 状態の変更
*
* @param array $room ルームデータ配列
* @return string HTML
*/
public function changeStatus($room) {
$this->_View->request->data = $room;
$output = '';
$output .= $this->NetCommonsForm->create('Room', array(
'type' => 'put',
'class' => 'inline-block rooms-change-status',
'url' => NetCommonsUrl::actionUrlAsArray(array(
'action' => 'active', $room['Space']['id'], $room['Room']['id']
)),
));
$output .= $this->NetCommonsForm->hidden('Room.id');
if ($room['Room']['active']) {
$output .= $this->NetCommonsForm->hidden('Room.active', array('value' => '0'));
$output .= $this->NetCommonsForm->button(__d('rooms', 'Open'), array(
'name' => 'save',
'class' => 'btn btn-default btn-xs',
'ng-disabled' => 'sending'
));
} else {
$output .= $this->NetCommonsForm->hidden('Room.active', array('value' => '1'));
$output .= $this->NetCommonsForm->button(__d('rooms', 'Under maintenance'), array(
'name' => 'save',
'class' => 'btn btn-default btn-xs',
'ng-disabled' => 'sending'
));
}
$output .= $this->NetCommonsForm->end();
return $output;
}
/**
* スペース編集の説明+ボタン
*
* @param int $spaceId スペースID
* @return string HTML
*/
public function editSpaceDescription($spaceId) {
$space = $this->_View->viewVars['spaces'][$spaceId];
$output = '';
$output .= '<div class="clearfix">';
$button = '';
$button .= $this->LinkButton->edit(
'',
array(
'controller' => 'rooms',
'action' => 'edit',
'key' => $space['Space']['id'],
'key2' => $space['Room']['id']
),
array('iconSize' => 'btn-xs')
);
if ($spaceId === Space::PUBLIC_SPACE_ID) {
$output .= sprintf(
__d('rooms', 'The setting of %s space also to non-members is published.'),
$this->Rooms->roomName($space)
);
$button .= $this->LinkButton->edit(
__d('rooms', 'Edit the members'),
array(
'controller' => 'rooms_roles_users',
'action' => 'edit',
'key' => $space['Space']['id'],
'key2' => $space['Room']['id']
),
array('iconSize' => 'btn-xs space-edit-rooms-roles-users')
);
} elseif ($spaceId === Space::PRIVATE_SPACE_ID) {
$output .= sprintf(
__d('rooms', 'The setting of %s space.'),
$this->Rooms->roomName($space)
);
$button .= $this->LinkButton->edit(
__d('rooms', 'Select the plugins to join'),
array(
'controller' => 'plugins_rooms',
'action' => 'edit',
'key' => $space['Space']['id'],
'key2' => $space['Room']['id']
),
array('iconSize' => 'btn-xs space-edit-rooms-roles-users')
);
} else {
$output .= sprintf(
__d('rooms', 'The setting of %s space.'),
$this->Rooms->roomName($space)
);
}
$output .= $this->NetCommonsHtml->div(
null, $button, array('class' => 'pull-right')
);
$output .= '</div>';
return $this->MessageFlash->description($output);
}
/**
* ルーム追加の説明+ボタン
*
* @param int $spaceId スペースID
* @return string HTML
*/
public function addRoomDescription($spaceId) {
$space = $this->_View->viewVars['spaces'][$spaceId];
$output = '';
$output .= '<div class="clearfix">';
$output .= sprintf(
__d('rooms', 'In %s space, to add a new room.'),
$this->Rooms->roomName($space)
);
$output .= $this->NetCommonsHtml->div(null,
$this->LinkButton->add(
__d('rooms', 'Room'),
array(
'controller' => 'room_add',
'action' => 'basic',
'key' => $space['Space']['id'],
'key2' => $space['Room']['id']
),
array('iconSize' => 'btn-xs')
),
array(
'class' => 'pull-right'
)
);
$output .= '</div>';
return $this->MessageFlash->description($output);
}
/**
* ルームの説明
*
* @param int $spaceId スペースID
* @return string HTML
*/
public function indexRoomDescription($spaceId) {
$space = $this->_View->viewVars['spaces'][$spaceId];
$output = '';
$output .= sprintf(
__d('rooms', 'The setting of each room was created in a %s space.'),
$this->Rooms->roomName($space)
);
return $this->MessageFlash->description($output);
}
/**
* すべての会員をデフォルトで参加させる
*
* @param string $fieldName フィールド名
* @param array $options HTMLの属性オプション
* @return string HTML
*/
public function inputDefaultParticipation($fieldName, $options = array()) {
$output = '';
$roomNames = [];
if (isset($this->_View->viewVars['parentRooms'])) {
$pathName = '{n}.RoomsLanguage.{n}[language_id=' . Current::read('Language.id') . '].name';
$roomNames = Hash::extract($this->_View->viewVars['parentRooms'], $pathName);
}
if ($this->_View->request->params['controller'] === 'room_add') {
if (! $roomNames) {
$label = __d('rooms', 'Open for all members');
} else {
$label = sprintf(
__d('rooms', 'Open for %s room\'s members'),
implode(RoomsHelper::ROOM_NAME_PAUSE, array_map('h', $roomNames))
);
}
} else {
if (count($roomNames) <= 2) {
$label = __d('rooms', 'Open for all members');
} else {
array_pop($roomNames);
$label = sprintf(
__d('rooms', 'Open for %s room\'s members'),
implode(RoomsHelper::ROOM_NAME_PAUSE, array_map('h', $roomNames))
);
}
}
if ($this->_View->viewVars['participationFixed']) {
$output .= $this->NetCommonsForm->hidden($fieldName);
}
$output .= $this->NetCommonsForm->inlineCheckbox($fieldName,
Hash::merge(array(
'label' => $label,
'disabled' => $this->_View->viewVars['participationFixed'],
), $options)
);
return $output;
}
/**
* Roomに対するセレクトボックス
*
* @param string $fieldName フィールド名
* @param array $attributes HTMLの属性オプション
* @return string HTML
*/
public function selectRooms($fieldName, $attributes = array()) {
$html = '';
$roomTreeList = $this->_View->viewVars['roomTreeList'];
$rooms = $this->_View->viewVars['rooms'];
if (! $roomTreeList) {
return $html;
}
$options = array();
foreach ($roomTreeList as $roomId => $tree) {
$room = Hash::get($rooms, $roomId);
$nest = substr_count($tree, Room::$treeParser);
$options[$roomId] = str_repeat(' ', $nest) . $this->Rooms->roomName($room);
}
$html .= $this->NetCommonsForm->input($fieldName,
Hash::merge(array(
'type' => 'select',
'options' => $options,
'label' => false,
'div' => false,
'error' => false,
'escape' => false,
), $attributes)
);
return $html;
}
/**
* ルーム管理一覧で使用する各ルームでの並び順情報
*
* @param array $rooms 一覧で表示するルーム情報配列
* @return array
*/
public function getRoomOrderList($rooms) {
$roomOrderList = [];
$childCount = [];
foreach ($rooms as $room) {
if (isset($childCount[$room['Room']['parent_id']])) {
$childCount[$room['Room']['parent_id']]++;
} else {
$childCount[$room['Room']['parent_id']] = 1;
}
$roomOrderList[] = [
'room_id' => $room['Room']['id'],
'order' => $room['Room']['weight'],
'siblings' => 0,
'parent_id' => $room['Room']['parent_id']
];
}
foreach ($roomOrderList as &$roomOrder) {
$roomOrder['siblings'] = $childCount[$roomOrder['parent_id']];
}
return $roomOrderList;
}
}