-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSiteManagerHelper.php
More file actions
388 lines (336 loc) · 9.93 KB
/
SiteManagerHelper.php
File metadata and controls
388 lines (336 loc) · 9.93 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
<?php
/**
* SiteManager 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');
App::uses('Space', 'Rooms.Model');
App::uses('SiteManagerComponent', 'SiteManager.Controller/Component');
/**
* サイト管理ヘルパー
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\SiteManager\View\Helper
*/
class SiteManagerHelper extends AppHelper {
/**
* 使用するヘルパー
*
* @var array
*/
public $helpers = array(
'Form',
'M17n.SwitchLanguage',
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
);
/**
* タブ
*
* @var array
*/
protected $_tabs = array(
'site_manager' => array(
'controller' => 'site_manager',
'action' => 'edit',
),
'meta_settings' => array(
'controller' => 'meta_settings',
'action' => 'edit',
),
'default_page_settings' => array(
'controller' => 'default_page_settings',
'action' => 'edit',
//ここは、__constractでやるように修正
//'key' => Room::PUBLIC_PARENT_ID
),
'membership' => array(
'controller' => 'membership',
'action' => 'edit',
),
'workflow' => array(
'controller' => 'workflow',
'action' => 'edit',
),
'mail_signature_settings' => array(
'controller' => 'mail_signature_settings',
'action' => 'edit',
),
'use_languages' => array(
'controller' => 'use_languages',
'action' => 'edit',
),
);
/**
* Default Constructor
*
* @param View $View The View this helper is being attached to.
* @param array $settings Configuration settings for the helper.
*/
public function __construct(View $View, $settings = array()) {
$this->_tabs['default_page_settings']['key'] = Space::getRoomIdRoot(Space::PUBLIC_SPACE_ID);
parent::__construct($View, $settings);
}
/**
* 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(array(
'/site_manager/css/style.css'
));
$this->NetCommonsHtml->script(array(
'/site_manager/js/site_manager.js'
));
parent::beforeRender($viewFile);
}
/**
* タブの出力
*
* @param string|null $active アクティブタブ
* @return string HTML
*/
public function tabs($active = null) {
if (! isset($active)) {
$active = $this->_View->request->params['controller'];
}
$output = '';
$output .= '<ul class="nav nav-tabs" role="tablist">';
foreach ($this->_tabs as $key => $tab) {
$output .= '<li class="' . ($key === $active ? 'active' : '') . '">';
$output .= $this->NetCommonsHtml->link(__d('site_manager', 'Tab.' . $key), $tab);
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
/**
* タブの出力
*
* @return string HTML
*/
public function roomTabs() {
$output = '';
$output .= '<ul class="nav nav-pills" role="tablist">';
foreach ($this->_View->viewVars['rooms'] as $roomId => $room) {
if ((string)$roomId === $this->_View->viewVars['activeRoomId']) {
$active = 'active';
} else {
$active = '';
}
$output .= '<li class="' . $active . '">';
$output .= $this->NetCommonsHtml->link(
Hash::get($room, 'RoomsLanguage.name'),
Hash::merge(
Hash::get($this->_tabs, $this->_View->request->params['controller']),
array('key' => $roomId)
)
);
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
/**
* タブの出力
*
* @return string HTML
*/
public function membershipTabs() {
$output = '';
$output .= '<ul class="nav nav-pills" role="tablist">';
$tabs = array(
'automatic-registration' => __d('site_manager', 'Automatic registration'),
'membership-cancellation' => __d('site_manager', 'Membership cancellation'),
);
$active = $this->_View->viewVars['membershipTab'];
foreach ($tabs as $key => $label) {
if ($key === $active) {
$output .= '<li class="active">';
} else {
$output .= '<li>';
}
$output .= '<a href="#' . $key . '" aria-controls="' . $key . '" role="tab" data-toggle="tab" ' .
'ng-click="' . $this->domId('membershipTab') . ' = \'' . $key . '\'">';
$output .= $label;
$output .= '</a>';
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
/**
* inputタグ
*
* @param string $model モデル名
* @param string $key キー
* @param int $languageId 言語ID
* @return string HTML
*/
public function inputHidden($model, $key, $languageId) {
$output = '';
$requestKey = SiteManagerComponent::convertRequestKey($key);
if (! isset($this->_View->request->data[$model][$requestKey])) {
return $output;
}
$inputValue = $model . '.' . $requestKey . '.' . $languageId;
//id
$output .= $this->NetCommonsForm->hidden($inputValue . '.id');
//key
$output .= $this->NetCommonsForm->hidden($inputValue . '.key');
//language_id
$output .= $this->NetCommonsForm->hidden($inputValue . '.language_id');
return $output;
}
/**
* ヘルプオプションの取得
*
* @param string $key キー
* @param array $options オプション
* @return array オプション
*/
private function __getHelpOption($key, $options = array()) {
if (Hash::get($options, 'mailHelp', false)) {
$help = '';
if (is_array(Hash::get($options, 'mailHelp'))) {
$help .= Hash::get($options, 'mailHelp.addMessage');
}
$help .= $this->NetCommonsHtml->mailHelp(Hash::get($options, 'help'));
$options = Hash::insert($options, 'help', $help);
$options = Hash::remove($options, 'mailHelp');
}
return $options;
}
/**
* inputタグ
*
* @param string $model モデル名
* @param string $key キー
* @param array $options オプション
* @return string HTML
*/
public function inputCommon($model, $key, $options = array()) {
$output = '';
$requestKey = SiteManagerComponent::convertRequestKey($key);
if (! isset($this->_View->request->data[$model][$requestKey])) {
return $output;
}
$label = Hash::get($options, 'label');
$options = Hash::remove($options, 'label');
$options = $this->__getHelpOption($key, $options);
$languageId = '0';
$inputValue = $model . '.' . $requestKey . '.' . $languageId;
//hidden
$output .= $this->inputHidden($model, $key, $languageId);
if (Hash::get($options, 'type', 'text') === 'radio') {
$options = Hash::merge(array(
'class' => false,
'inline' => true
), $options);
}
$output .= $this->NetCommonsForm->input($inputValue . '.value',
Hash::merge(array(
'label' => $label,
), $options)
);
return $output;
}
/**
* inputタグ(言語)
*
* @param string $model モデル名
* @param string $key キー
* @param array $options オプション
* @return string HTML
*/
public function inputLanguage($model, $key, $options = array()) {
$output = '';
$requestKey = SiteManagerComponent::convertRequestKey($key);
if (! isset($this->_View->request->data[$model][$requestKey])) {
return $output;
}
$label = Hash::get($options, 'label');
$options = Hash::remove($options, 'label');
$options = $this->__getHelpOption($key, $options);
$activeLangId = $this->_View->viewVars['activeLangId'];
$languageIds = array_keys($this->_View->viewVars['languages']);
foreach ($languageIds as $languageId) {
$inputValue = $model . '.' . $requestKey . '.' . $languageId;
if ((string)$activeLangId === (string)$languageId) {
$active = ' active';
} else {
$active = '';
}
$output .= '<div class="tab-pane' . $active . '" ' .
'ng-show="' . 'activeLangId === \'' . $languageId . '\'' . '">';
//hidden
$output .= $this->inputHidden($model, $requestKey, $languageId);
if (Hash::get($options, 'type') === 'wysiwyg') {
//$options = Hash::remove($options, 'type');
$field = SiteManagerComponent::invertRequestKey($inputValue . '.value');
$value = h(json_encode($this->getValue($model, $key, $languageId)));
$output .= '<div ng-init="' . $this->domId($field) . ' = ' . $value . '">';
$output .= $this->NetCommonsForm->wysiwyg($inputValue . '.value',
Hash::merge(
array(
'label' => $this->SwitchLanguage->inputLabel($label, $languageId),
'ng-model' => $this->domId($field),
),
$options
)
);
$output .= '</div>';
} else {
$output .= $this->NetCommonsForm->input($inputValue . '.value',
Hash::merge(array(
'label' => $this->SwitchLanguage->inputLabel($label, $languageId),
), $options)
);
}
$output .= '</div>';
}
return $output;
}
/**
* 値の取得
*
* @param string $model モデル名
* @param string $key キー
* @param int $languageId 言語ID
* @return string HTML
*/
public function getValue($model, $key, $languageId = '0') {
$requestKey = SiteManagerComponent::convertRequestKey($key);
return Hash::get($this->_View->request->data[$model][$requestKey], $languageId . '.value');
}
/**
* サイト停止のヘルプの表示
*
* @param string $placement ポジション
* @return string ヘルプHTML出力
*/
public function helpSiteClose($placement = 'bottom') {
$html = '';
$content = __d('net_commons', '{X-SITE_NAME} : Site name');
$content = __d('net_commons', 'Each of the embedded keywords, will be converted ' .
'to the corresponding content. <br />') . $content;
$html .= __d('net_commons', 'Can use an embedded keyword.') . ' ';
$html .= '<a href="" data-toggle="popover" data-placement="' . $placement . '"' .
' title="' . __d('mails', 'Embedded keyword?') . '"' . ' data-content="' . $content . '">';
$html .= '<span class="glyphicon glyphicon-info-sign"></span>';
$html .= '</a>';
$html .= '<script type="text/javascript">' .
'$(function () { $(\'[data-toggle="popover"]\').popover({html: true}) });</script>';
return $html;
}
}