-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPluginsFormComponent.php
More file actions
120 lines (107 loc) · 3.02 KB
/
PluginsFormComponent.php
File metadata and controls
120 lines (107 loc) · 3.02 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
<?php
/**
* PluginsFormComponent
*
* @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');
/**
* PluginsFormComponent
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\PluginManager\Controller\Component
*/
class PluginsFormComponent extends Component {
/**
* ルームID
*
* $roomIdがnullの場合、Current::read('Room.id')を使用する
*
* @var string
*/
public $roomId = null;
/**
* findのオプション
*
* @var array
*/
public $findOptions = array();
/**
* Called after the Controller::beforeFilter() and before the controller action
*
* @param Controller $controller 呼び出し元Controller
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup
*/
public function startup(Controller $controller) {
if (! $this->roomId) {
$this->roomId = Current::read('Room.id');
}
$controller->helpers[] = 'PluginManager.PluginsForm';
}
/**
* beforeRender
*
* @param Controller $controller 呼び出し元Controller
* @return void
* @throws NotFoundException
*/
public function beforeRender(Controller $controller) {
//RequestActionの場合、スキップする
if (! empty($controller->request->params['requested'])) {
return;
}
$this->setPluginsRoomForCheckbox($controller, $this->findOptions);
}
/**
* PluginsFormHelper::checkboxPluginsRoom()のためデータをセット
*
* @param Controller $controller 呼び出し元Controller
* @param array $findOptions findのオプション
* @return void
*/
public function setPluginsRoomForCheckbox(Controller $controller, $findOptions = array()) {
if (Hash::get($controller->viewVars, 'pluginsRoom')) {
return;
}
//Modelの呼び出し
$Plugin = ClassRegistry::init('PluginManager.Plugin');
$PluginsRoom = ClassRegistry::init('PluginManager.PluginsRoom');
//optionsセット
$defaultOptions = array(
'recursive' => -1,
'fields' => array(
$Plugin->alias . '.key',
$Plugin->alias . '.name',
$PluginsRoom->alias . '.room_id',
$PluginsRoom->alias . '.plugin_key'
),
'joins' => array(
array(
'table' => $PluginsRoom->table,
'alias' => $PluginsRoom->alias,
'type' => 'LEFT',
'conditions' => array(
$Plugin->alias . '.key' . ' = ' . $PluginsRoom->alias . '.plugin_key',
$PluginsRoom->alias . '.room_id' => $this->roomId,
),
)
),
'conditions' => array(
$Plugin->alias . '.type' => Plugin::PLUGIN_TYPE_FOR_FRAME,
$Plugin->alias . '.language_id' => Current::read('Language.id'),
),
'order' => array(
$Plugin->alias . '.weight' => 'asc',
$Plugin->alias . '.id' => 'asc',
)
);
//データ取得
$pluginsRoom = $Plugin->find('all', Hash::merge($defaultOptions, $findOptions));
$controller->set('pluginsRoom', $pluginsRoom);
}
}