-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBoxesHelper.php
More file actions
338 lines (309 loc) · 9 KB
/
BoxesHelper.php
File metadata and controls
338 lines (309 loc) · 9 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
<?php
/**
* LayoutHelper
*
* @copyright Copyright 2014, NetCommons Project
* @author Kohei Teraguchi <kteraguchi@commonsnet.org>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('AppHelper', 'View/Helper');
App::uses('Container', 'Containers.Model');
App::uses('Box', 'Boxes.Model');
App::uses('Current', 'NetCommons.Utility');
/**
* LayoutHelper
*
*/
class BoxesHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'Html',
'NetCommons.Button',
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
);
/**
* Containers data
*
* @var array
*/
public $containers;
/**
* 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()) {
parent::__construct($View, $settings);
$this->containers = Hash::get($settings, 'containers', array());
}
/**
* Get the box data for container
*
* @param string $containerType コンテナータイプ
* Container::TYPE_HEADER or Container::TYPE_MAJOR or Container::TYPE_MAIN or
* Container::TYPE_MINOR or Container::TYPE_FOOTER
* @return array Box data
*/
public function getBox($containerType) {
return Hash::get($this->containers, $containerType . '.Box', array());
}
/**
* プラグイン追加のHTMLを出力
*
* @param array $box Boxデータ
* @return string
*/
public function renderAddPlugin($box) {
$containerType = $box['BoxesPageContainer']['container_type'];
if ($this->hasAddPlugin($box)) {
return $this->_View->element('Frames.add_plugin', array(
'boxId' => $box['Box']['id'],
'roomId' => $box['Box']['room_id'],
'containerType' => $containerType,
));
} else {
return '';
}
}
/**
* プラグイン追加のHTMLを出力
*
* @param array $box Boxデータ
* @return string
*/
public function hasAddPlugin($box) {
return Current::isSettingMode() && Current::permission('page_editable', $box['Box']['room_id']);
}
/**
* ボックス内のFrameのHTMLを出力
*
* @param int $containerType コンテナータイプ
* @param array $boxes Boxデータ
* @return string
*/
public function renderBoxes($containerType, $boxes) {
$html = '';
if (! Current::isSettingMode()) {
foreach ($boxes as $box) {
$html .= $this->renderFrames($box);
}
} elseif ($containerType === Container::TYPE_HEADER ||
$containerType === Container::TYPE_FOOTER) {
$html .= $this->_View->element(
'Boxes.render_boxes_header_footer',
array('boxes' => $boxes, 'containerType' => $containerType)
);
} elseif ($containerType === Container::TYPE_MAIN) {
$html .= $this->_View->element(
'Boxes.render_boxes_main',
array('boxes' => $boxes, 'containerType' => $containerType)
);
} else {
$html .= $this->_View->element(
'Boxes.render_boxes_major_minor',
array('boxes' => $boxes, 'containerType' => $containerType)
);
}
return $html;
}
/**
* ボックス内のFrameのHTMLを出力
*
* @param array $box Boxデータ
* @return string
*/
public function renderFrames($box) {
$html = '';
if (! empty($box['Frame'])) {
$containerType = $box['BoxesPageContainer']['container_type'];
$html .= '<div id="box-' . $box['Box']['id'] . '">';
$html .= $this->_View->element('Frames.render_frames', array(
'box' => $box, 'containerType' => $containerType,
));
$html .= '</div>';
} elseif ($this->hasBox($box)) {
$html .= '<div>';
$html .= __d('boxes', 'Not found plugin.');
$html .= '</div>';
}
return $html;
}
/**
* ボックスエリアのタイトル表示
*
* @param array $box Boxデータ
* @return string
*/
public function boxTitle($box) {
App::uses('Box', 'Boxes.Model');
$html = '';
$containerType = $box['BoxesPageContainer']['container_type'];
if ($containerType === Container::TYPE_MAJOR) {
$containerTitle = __d('boxes', '(left column)');
} elseif ($containerType === Container::TYPE_MINOR) {
$containerTitle = __d('boxes', '(right column)');
} else {
$containerTitle = '';
}
if ($box['Box']['type'] === Box::TYPE_WITH_SITE) {
$title = __d('boxes', 'Common area of the whole site%s', $containerTitle);
} elseif ($box['Box']['type'] === Box::TYPE_WITH_SPACE) {
$title = __d(
'boxes',
'Common area of the whole %s space%s',
h($box['RoomsLanguage']['name']),
$containerTitle
);
} elseif ($box['Box']['type'] === Box::TYPE_WITH_ROOM) {
$title = __d('boxes', 'Common area of the whole room%s', $containerTitle);
} else {
$title = __d('boxes', 'Area of this page only%s', $containerTitle);
}
if ($this->hasBoxSetting($box)) {
$html .= $this->displayBoxSetting($box, $title);
} else {
$html .= $title;
}
return $html;
}
/**
* 表示・非表示の変更HTMLを出力する
*
* @param array $box Boxデータ
* @param string $title タイトル
* @return string
*/
public function displayBoxSetting($box, $title) {
$html = '';
$containerType = $box['BoxesPageContainer']['container_type'];
if ($containerType === Container::TYPE_MAJOR || $containerType === Container::TYPE_MINOR) {
$classOptions = array(
'pull-left box-display'
);
} else {
$classOptions = array(
'box-display'
);
}
$html .= $this->NetCommonsForm->create(null, array(
'id' => 'BoxForm' . $box['Box']['id'],
'url' => NetCommonsUrl::actionUrlAsArray(array(
'plugin' => 'boxes',
'controller' => 'boxes',
'action' => 'display',
'page_id' => Current::read('Page.id')
//$box['Box']['id'],
)),
'type' => 'put',
'class' => $classOptions,
'ng-controller' => 'BoxesController'
));
$html .= $this->NetCommonsForm->hidden('BoxesPageContainer.id', array(
'value' => $box['BoxesPageContainer']['id'],
));
$html .= $this->NetCommonsForm->hidden('BoxesPageContainer.box_id', array(
'value' => $box['BoxesPageContainer']['box_id'],
));
$html .= $this->NetCommonsForm->hidden('BoxesPageContainer.page_container_id', array(
'value' => $box['BoxesPageContainer']['page_container_id'],
));
$html .= $this->NetCommonsForm->hidden('BoxesPageContainer.page_id', array(
'value' => $box['BoxesPageContainer']['page_id'],
));
$html .= $this->NetCommonsForm->hidden('BoxesPageContainer.container_type', array(
'value' => $box['BoxesPageContainer']['container_type'],
));
$html .= $this->NetCommonsForm->hidden('Page.id', array(
'value' => Current::read('Page.id'),
));
$html .= $this->NetCommonsForm->hidden('Page.room_id', array(
'value' => Current::read('Page.room_id'),
));
$html .= $this->NetCommonsForm->hidden('Box.id', array(
'value' => $box['Box']['id'],
));
$html .= $this->NetCommonsForm->hidden('Box.type', array(
'value' => $box['Box']['type'],
));
if ($containerType === Container::TYPE_HEADER || $containerType === Container::TYPE_FOOTER) {
$html .= $this->NetCommonsForm->radio(
'BoxesPageContainer.is_published',
array('1' => $title),
array(
'id' => 'BoxesPageContainerIsPublished' . $box['Box']['id'],
'value' => $box['BoxesPageContainer']['is_published'],
'ng-click' => 'select(' . $containerType . ', ' . $box['Box']['id'] . ')',
'ng-disabled' => 'sending',
'containerType' => $box['BoxesPageContainer']['container_type']
)
);
} else {
if ($box['BoxesPageContainer']['is_published']) {
$html .= $this->NetCommonsForm->hidden(
'BoxesPageContainer.is_published', array('value' => '0')
);
$buttonIcon = 'glyphicon-eye-open';
$active = ' active';
$label = __d('boxes', 'Display');
} else {
$html .= $this->NetCommonsForm->hidden(
'BoxesPageContainer.is_published', array('value' => '1')
);
$buttonIcon = 'glyphicon-minus';
$active = '';
$label = __d('boxes', 'Non display');
}
$html .= $this->Button->save(
'<span class="glyphicon ' . $buttonIcon . '" aria-hidden="true"> </span>',
array(
'class' => 'btn btn-xs btn-default' . $active,
)
);
}
$html .= $this->NetCommonsForm->end();
if ($containerType === Container::TYPE_MAJOR || $containerType === Container::TYPE_MINOR) {
$html .= $title;
}
return $html;
}
/**
* 表示・非表示の変更の有無
*
* @param array $box Boxデータ
* @return bool
*/
public function hasBoxSetting($box) {
if (isset($box['BoxesPageContainer']['container_type'])) {
$containerType = $box['BoxesPageContainer']['container_type'];
} else {
$containerType = null;
}
if (! Current::isSettingMode()) {
return false;
} elseif ($containerType === Container::TYPE_MAJOR || $containerType === Container::TYPE_MINOR) {
return Current::permission('page_editable', $box['Box']['room_id']);
} else {
return Current::permission('page_editable');
}
}
/**
* ボックスの表示有無
*
* @param array $box Boxデータ
* @return bool
*/
public function hasBox($box) {
if (! empty($box['Frame']) || $this->hasBoxSetting($box)) {
return true;
} else {
return false;
}
}
}