-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBlockRolePermissionFormHelper.php
More file actions
100 lines (85 loc) · 2.84 KB
/
BlockRolePermissionFormHelper.php
File metadata and controls
100 lines (85 loc) · 2.84 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
<?php
/**
* BlockRolePermissionForm 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');
/**
* BlockRolePermissionForm Helper
*
* @package NetCommons\Blocks\View\Helper
*/
class BlockRolePermissionFormHelper extends AppHelper {
/**
* 使用するヘルパー
*
* @var array
*/
public $helpers = array(
'NetCommons.NetCommonsForm',
'Rooms.Rooms',
);
/**
* BlockRolePermissionのチェックボックス表示
*
* @param string $fieldName フィールド名
* @param array $attributes Formヘルパーのオプション
* @return string HTML
*/
public function checkboxBlockRolePermission($fieldName, $attributes = array()) {
list($model, $permission) = explode('.', $fieldName);
$html = '';
if (! isset($this->_View->request->data[$model][$permission])) {
return $html;
}
$html .= '<div class="form-inline">';
foreach ($this->_View->request->data[$model][$permission] as $roleKey => $role) {
if (! $role['default'] && $role['fixed'] || ! Hash::get($role, 'roles_room_id')) {
continue;
}
$html .= $this->__inputBlockRolePermission($model, $permission, $roleKey, $attributes);
}
$html .= '</div>';
return $html;
}
/**
* BlockRolePermissionのチェックボックス表示
*
* @param string $model モデル名
* @param string $permission パーミッション
* @param string $roleKey ロールキー
* @param array $attributes Formヘルパーのオプション
* @return string HTML
*/
private function __inputBlockRolePermission($model, $permission, $roleKey, $attributes = array()) {
$html = '';
$html .= '<div class="checkbox checkbox-inline">';
$fieldName = $model . '.' . $permission . '.' . $roleKey;
if (! Hash::get($this->_View->request->data, $fieldName . '.fixed')) {
$html .= $this->NetCommonsForm->hidden($fieldName . '.id');
$html .= $this->NetCommonsForm->hidden($fieldName . '.roles_room_id');
$html .= $this->NetCommonsForm->hidden($fieldName . '.block_key');
$html .= $this->NetCommonsForm->hidden($fieldName . '.permission');
}
$options = Hash::merge(array(
'div' => false,
'disabled' => (bool)Hash::get($this->_View->request->data, $fieldName . '.fixed'),
), $attributes);
if (! $options['disabled']) {
$options['ng-click'] = 'clickRole($event, ' .
'\'' . $permission . '\', \'' . Inflector::variable($roleKey) . '\')';
}
$options['label'] = $this->Rooms->roomRoleName(
$roleKey, ['help' => true, 'roles' => $this->_View->viewVars['roles']]
);
$options['escape'] = false;
$html .= $this->NetCommonsForm->checkbox($fieldName . '.value', $options);
$html .= '</div>';
return $html;
}
}