-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRoomsHelper.php
More file actions
351 lines (313 loc) · 10 KB
/
RoomsHelper.php
File metadata and controls
351 lines (313 loc) · 10 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
<?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('RoomsComponent', 'Rooms.Controller/Component');
App::uses('RoomsAppController', 'Rooms.Controller');
/**
* ルーム表示ヘルパー
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\UserAttribute\View\Helper
*/
class RoomsHelper extends AppHelper {
/**
* ルーム名のナビゲータの区切り文字
*
* @var const
*/
const ROOM_NAME_PAUSE = ' / ';
/**
* 使用するヘルパー
*
* @var array
*/
public $helpers = array(
'NetCommons.Date',
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
'Users.DisplayUser',
);
/**
* 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);
}
/**
* ルームナビの出力
*
* @param int $activeSpaceId スペースID
* @return string HTML
*/
public function roomsNavi($activeSpaceId) {
$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 ($roomNames) {
//array_shift($roomNames);
$output = implode(self::ROOM_NAME_PAUSE, array_map('h', $roomNames));
} else {
$output = $this->roomName($this->_View->viewVars['spaces'][$activeSpaceId]);
}
if ($this->_View->request->params['controller'] === 'room_add') {
if (! $roomNames) {
$output .= self::ROOM_NAME_PAUSE . __d('rooms', 'Add new room');
} else {
$output .= self::ROOM_NAME_PAUSE . __d('rooms', 'Add new subroom');
}
}
return $output;
}
/**
* タブの出力
*
* @param int $activeSpaceId スペースID
* @param bool $tabType タブの種類(tabs or pills)
* @param string|null $urls URLオプション
* @return string HTML
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function spaceTabs($activeSpaceId, $tabType = 'tabs', $urls = null) {
$output = '';
$output .= '<ul class="nav nav-' . $tabType . '" role="tablist">';
foreach ($this->_View->viewVars['spaces'] as $space) {
if (is_array($urls) && ! isset($urls[$space['Space']['id']])) {
continue;
}
if ($space['Space']['default_setting_action']) {
if ($space['Space']['id'] === $activeSpaceId) {
$listClass = ' class="active"';
} elseif ($urls === false) {
$listClass = ' class="disabled"';
} else {
$listClass = '';
}
if ($urls === false) {
$output .= '<li' . $listClass . '>';
$output .= '<a href="">' . $this->roomName($space) . '</a>';
$output .= '</li>';
continue;
}
$attributes = array();
$output .= '<li' . $listClass . '>';
if (! isset($urls)) {
$url = '/rooms/' . $space['Space']['default_setting_action'];
} elseif (is_string($urls)) {
$url = sprintf($urls, (int)$space['Space']['id']);
} elseif (isset($urls[$space['Space']['id']])) {
$url = Hash::get($urls[$space['Space']['id']], 'url');
$attributes = (array)Hash::get($urls[$space['Space']['id']], 'attributes');
}
$output .= $this->NetCommonsHtml->link($this->roomName($space), $url, $attributes);
$output .= '</li>';
}
}
$output .= '</ul>';
return $output;
}
/**
* ルーム一覧の出力
*
* @param int $activeSpaceId スペースID
* @param array $element データ表示エレメント
* ```
* array(
* 'headElement' => ヘッダ表示エレメント,
* 'dataElemen' => データ表示エレメント,
* )
* ```
* @param array $options オプション
* ```
* array(
* 'paginator' => ページネーションの有無 デフォルト:true,
* 'displaySpace' => スペース表示,
* 'roomTreeList' => ルームのTreeリスト,
* 'rooms' => ルームリスト,
* 'tableClass' => テーブルタグのclass属性,
* )
* ```
* @return string HTML
*/
public function roomsRender($activeSpaceId, $element, $options = []) {
$output = '';
$roomTreeList = Hash::get($options, 'roomTreeList');
if (! isset($roomTreeList)) {
$roomTreeList = Hash::get($this->_View->viewVars, 'roomTreeList');
}
$rooms = Hash::get($options, 'rooms');
if (! isset($rooms)) {
$rooms = Hash::get($this->_View->viewVars, 'rooms');
}
$output .= $this->_View->element('Rooms.Rooms/render_index', array(
'headElementPath' => Hash::get($element, 'headElement'),
'dataElementPath' => Hash::get($element, 'dataElemen'),
'roomTreeList' => $roomTreeList,
'rooms' => $rooms,
'space' => $this->_View->viewVars['spaces'][$activeSpaceId],
'paginator' => Hash::get($options, 'paginator', true),
'displaySpace' => Hash::get($options, 'displaySpace', false),
'tableClass' => Hash::get($options, 'tableClass', 'table'),
));
return $output;
}
/**
* 上下ボタンタグを返す
*
* @param array $room ルーム情報
* @return string
*/
protected function _getUpDownBtnTag($room) {
$btn = '<span class="text-nowrap rooms-index-updown-btn">' .
'<button type="button" class="btn btn-default btn-xs"' .
'ng-click="moveUp($event, ' . $room['Room']['id'] . ')"' .
'ng-disabled="isUpDisabled(' . $room['Room']['id'] . ')">' .
'<span class="glyphicon glyphicon-arrow-up"></span>' .
'</button>' .
'<button type="button" class="btn btn-default btn-xs"' .
'ng-click="moveDown($event, ' . $room['Room']['id'] . ')"' .
'ng-disabled="isDownDisabled(' . $room['Room']['id'] . ')">' .
'<span class="glyphicon glyphicon-arrow-down"></span>' .
'</button>' .
'</span>';
return $btn;
}
/**
* ルーム名の出力
*
* @param array $room ルームデータ配列
* @param int|null $nest インデント
* @param bool $withBtn 上下操作ボタンをつけるか否か(ルーム管理での一覧画面でしか使用しない)
* @return string HTML
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function roomName($room, $nest = null, $withBtn = false) {
$name = '';
foreach ($room['RoomsLanguage'] as $item) {
if ($item['language_id'] == Current::read('Language.id')) {
$name = $item['name'];
break;
}
}
$output = '';
if (isset($nest)) {
$output .= str_repeat('<span class="rooms-tree"> </span>', $nest);
}
if ($withBtn) {
$output .= $this->_getUpDownBtnTag($room);
}
$output .= h($name);
return $output;
}
/**
* 状態によるCSSのクラス定義を返す
*
* @param array $room ルームデータ配列
* @param string|null $prefix CSSクラスのプレフィックス
* @return string HTML
*/
public function statusCss($room, $prefix = '') {
$output = '';
if (! $room['Room']['active']) {
$output .= $prefix . 'danger';
}
return $output;
}
/**
* 状態のラベルを出力
*
* @param array $room ルームデータ配列
* @param string $messageFormat メッセージフォーマット
* @param bool $displayActive アクティブの表示有無
* @return string HTML
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* @link https://github.com/NetCommons3/UserManager/blob/3.0.1/View/Elements/UsersRolesRooms/render_room_index.ctp#L31
* @link https://github.com/NetCommons3/Users/blob/3.0.1/View/Elements/Users/view_rooms_index.ctp#L27
*/
public function statusLabel($room, $messageFormat = '%s', $displayActive = false) {
$output = '';
if (! $room['Room']['active']) {
if ($messageFormat === '(%s)') {
$output .= ' ' . __d('rooms', '(Under maintenance)');
} else {
$output .= ' ' . __d('rooms', 'Under maintenance');
}
} elseif ($displayActive) {
if ($messageFormat === '(%s)') {
$output .= ' ' . __d('rooms', '(Open)');
} else {
$output .= ' ' . __d('rooms', 'Open');
}
}
return $output;
}
/**
* ルームロール名の出力
*
* @param string|array $roomRoleKey ルームロールKey
* @param array $options オプション
* @return string HTML
*/
public function roomRoleName($roomRoleKey, $options = []) {
if (is_array($roomRoleKey)) {
$roomRoleKey = Hash::get($roomRoleKey, 'RolesRoom.role_key', '');
}
if (Hash::get($options, 'roles')) {
$role = Hash::get($options, 'roles')[$roomRoleKey];
} elseif (Hash::get($this->_View->request->data, 'Role.' . $roomRoleKey)) {
$role = $this->_View->request->data['Role'][$roomRoleKey];
} elseif (Hash::get($this->_View->viewVars, 'defaultRoles.' . $roomRoleKey)) {
$role = Hash::get($this->_View->viewVars, 'defaultRoles.' . $roomRoleKey);
} else {
return h(Hash::get(
$this->_View->viewVars, 'defaultRoles.' . $roomRoleKey, Hash::get($options, 'default', ''))
);
}
$roleName = h($role['name']);
$html = $roleName;
if (Hash::get($options, 'help') && $role['description']) {
$roleDesc = h(__d('roles', $role['description']));
$html .= ' <a href="" data-toggle="popover"' .
' data-placement="' . Hash::get($options, 'placement', 'top') . '"' .
' title="' . h($roleName) . '"' .
' data-content="' . $roleDesc . '"' .
//' data-trigger="focus">';
' data-trigger="focus">';
$html .= '<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>';
$html .= '</a>';
$html .= '<script type="text/javascript">' .
'$(function () { $(\'[data-toggle="popover"]\').popover({html: true}) });</script>';
}
return $html;
}
/**
* ルームのアクセス日時の出力
*
* @param array $room ルームデータ配列
* @param string $field フィールド
* @return string HTML
*/
public function roomAccessed($room, $field = 'last_accessed') {
$output = '';
if (Hash::get($room, 'RolesRoomsUser.' . $field)) {
$output .= $this->Date->dateFormat(Hash::get($room, 'RolesRoomsUser.' . $field));
}
return $output;
}
}