-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPluginsFormHelper.php
More file actions
110 lines (96 loc) · 2.86 KB
/
PluginsFormHelper.php
File metadata and controls
110 lines (96 loc) · 2.86 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
<?php
/**
* PluginsFormHelper
*
* @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');
/**
* PluginsFormHelper
*
* @package NetCommons\PluginManager\View\Helper
*/
class PluginsFormHelper extends AppHelper {
/**
* 使用ヘルパー
*
* @var array
*/
public $helpers = array(
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
);
/**
* 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('/plugin_manager/css/style.css');
parent::beforeRender($viewFile);
}
/**
* Roomに対するプラグインチェックボックスリスト
*
* @param string $fieldName フィールド名
* @param array $attributes HTMLの属性オプション
* @return string HTML
*/
public function checkboxPluginsRoom($fieldName = 'PluginsRoom.plugin_key', $attributes = array()) {
$html = '';
//チェックボックスの設定
$options = Hash::combine(
$this->_View->viewVars['pluginsRoom'], '{n}.Plugin.key', '{n}.Plugin.name'
);
if (Hash::get($attributes, 'hiddenField', true)) {
$this->_View->request->data['Plugin']['key'] = array_keys($options);
foreach (array_keys($this->_View->request->data['Plugin']['key']) as $index) {
$html .= $this->NetCommonsForm->hidden('Plugin.' . $index . '.key', array(
'value' => $this->_View->request->data['Plugin']['key'][$index],
));
}
}
$defaults = Hash::get($attributes, 'default', array());
$attributes = Hash::remove($attributes, 'default');
$this->_View->request->data = Hash::insert(
$this->_View->request->data, $fieldName, $defaults
);
$html .= $this->NetCommonsForm->select(
$fieldName, $options, Hash::merge($attributes, array('multiple' => 'checkbox'))
);
return $html;
}
/**
* Roomに対するプラグインのセレクトボックス表示
*
* @param string $fieldName フィールド名
* @param array $attributes HTMLの属性オプション
* @return string HTML
*/
public function selectPluginsRoom($fieldName, $attributes = array()) {
$html = '';
//チェックボックスの設定
$options = Hash::get(
$attributes,
'options',
Hash::combine($this->_View->viewVars['pluginsRoom'], '{n}.Plugin.key', '{n}.Plugin.name')
);
$attributes = Hash::merge(
array(
'type' => 'select',
'options' => $options,
'label' => __d('plugin_manager', 'Select plugin'),
),
$attributes
);
$html .= $this->NetCommonsForm->input($fieldName, $attributes);
return $html;
}
}