-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBlocksHelper.php
More file actions
152 lines (130 loc) · 3.53 KB
/
BlocksHelper.php
File metadata and controls
152 lines (130 loc) · 3.53 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
<?php
/**
* BlocksHelper
*
* @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('Block', 'Blocks.Model');
/**
* BlocksHelper
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Blocks\View\Helper
*/
class BlocksHelper extends AppHelper {
/**
* 使用ヘルパー
*
* @var array
*/
public $helpers = array(
'Html',
'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('/blocks/css/style.css');
parent::beforeRender($viewFile);
}
/**
* タイトル(ブロックタイトル)の出力
*
* #### サンプル
* ```
* echo $this->NetCommonsHtml->blockTitle($bbs['name'])
* ```
* ##### 出力結果
* ```
* <h1>新しい掲示板 20160513074815</h1>
* ```
*
* @param string $text タイトル
* @param string $titleIcon タイトルアイコン
* @param array $options HTML属性オプション
* @return string `<h1>`タグ
*/
public function blockTitle($text = '', $titleIcon = null, $options = array()) {
$output = '';
$escape = Hash::get($options, 'escape', true);
if ($escape) {
$text = h($text);
}
$options = Hash::insert($options, 'escape', false);
if ($titleIcon) {
$text = $this->NetCommonsHtml->titleIcon($titleIcon) . ' ' . $text;
}
if (Hash::get($options, 'status')) {
$text = Hash::get($options, 'status') . ' ' . $text;
$options = Hash::remove($options, 'status');
}
if (! isset($options['class'])) {
$options['class'] = 'block-title';
}
$output .= $this->Html->tag('h1', $text, $options);
return $output;
}
/**
* ブロックのステータスラベルを表示
*
* @param null|bool $isSetting 強制的にセッティングモード
* @return string HTML
*/
public function getBlockStatus($isSetting = null) {
if (! Current::permission('block_editable')) {
return '';
}
if (! isset($isSetting)) {
$isSetting = Current::isSettingMode();
}
if (! $isSetting || ! Current::read('Block.id')) {
return '';
}
$block = Current::read('Block', array());
$publicType = Hash::get($block, 'public_type');
if ($publicType === Block::TYPE_PUBLIC) {
return '';
}
$html = $this->__getBlockStatus();
return $html;
}
/**
* ブロックのステータスラベルを表示
*
* @return string HTML
*/
private function __getBlockStatus() {
$html = '';
$block = Current::read('Block', array());
$publicType = Hash::get($block, 'public_type', false);
if ($publicType === false || $publicType === Block::TYPE_PUBLIC) {
return $html;
}
$now = date('Y-m-d H:i:s');
$html .= '<span class="block-style-label label label-default">';
if ($publicType === Block::TYPE_PRIVATE) {
$html .= __d('blocks', 'Private');
} elseif ($publicType === Block::TYPE_LIMITED) {
if ($now <= Hash::get($block, 'publish_start', '0000-00-00 00:00:00')) {
$html .= __d('blocks', 'Public before');
} elseif ($now > Hash::get($block, 'publish_end', '9999-99-99 99:99:99')) {
$html .= __d('blocks', 'Public end');
} else {
$html .= __d('blocks', 'Limited');
}
}
$html .= '</span>';
return $html;
}
}