-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContentCommentHelper.php
More file actions
137 lines (117 loc) · 4.03 KB
/
ContentCommentHelper.php
File metadata and controls
137 lines (117 loc) · 4.03 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
<?php
/**
* ContentComment Helper
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @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('WorkflowComponent', 'Workflow.Controller/Component');
/**
* ContentComment Helper
*
* @package NetCommons\ContentComments\View\Helper
*/
class ContentCommentHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'Html',
'Users.DisplayUser',
'Paginator',
'Workflow.Workflow',
);
/**
* コメント数表示
*
* コメント数の表示HTMLを返します。<br>
* 設定データ配列、コンテンツデータ配列を指定してください。<br>
* 設定データ配列の['viewVarsKey']['useComment']を判断し、コンテンツデータ配列のContentCommentCnt.cntを表示します。
*
* #### Sample code
* ##### template file(ctp file)
* ```
* <?php echo $this->ContentComment->count($video); ?>
* ```
*
* @param array $content Array of content data with ContentComment count.
* @param array $attributes Array of attributes and HTML arguments.
* @return string HTML tags
*/
public function count($content, $attributes = array()) {
$output = '';
$useComment = Hash::get($this->_View->viewVars, $this->settings['viewVarsKey']['useComment']);
// コメントを利用する
if ($useComment) {
$element = '<span class="glyphicon glyphicon-comment" aria-hidden="true"></span> ';
// nullを考慮して intにキャスト
$element .= (int)Hash::get($content, 'ContentCommentCnt.cnt');
$approvalCnt = (int)Hash::get($content, 'ContentCommentCnt.approval_cnt');
// 未承認1件以上
if ($approvalCnt >= 1) {
$element .= sprintf(__d('content_comments', '(%s unapproved)'), $approvalCnt);
}
/* @link http://book.cakephp.org/2.0/ja/core-libraries/helpers/html.html#HtmlHelper::tag */
$output .= $this->Html->tag('span', $element, $attributes);
}
return $output;
}
/**
* コメント一覧表示&コメント登録
*
* #### Sample code
* ##### template file(ctp file)
* ```
* <?php echo $this->ContentComment->index($video); ?>
* ```
*
* @param array $content Array of content data with ContentComment count.
* @return string HTML tags
*/
public function index($content) {
$output = '';
$viewVars = $this->_View->viewVars;
$viewVarsKey = $this->settings['viewVarsKey'];
$useComment = Hash::get($viewVars, $viewVarsKey['useComment']);
// コメント承認を使う
$useCommentApproval = Hash::get($viewVars, $viewVarsKey['useCommentApproval']);
// コンテンツキー
$contentKey = Hash::get($viewVars, $viewVarsKey['contentKey']);
// コメントを利用しない
if (! $useComment) {
return;
}
// コンテンツキーのDB項目名なし
if (! isset($contentKey)) {
return;
}
// コメントを利用する
if ($useComment) {
$WorkflowComponent = new WorkflowComponent(new ComponentCollection());
// ビジター投稿許可フラグ
$permissions = $WorkflowComponent->getBlockRolePermissions(array('content_comment_creatable'));
$isVisitorCreatable = Hash::get($permissions,
'BlockRolePermissions.content_comment_creatable.visitor.value');
// 未承認件数
$approvalCnt = (int)Hash::get($content, 'ContentCommentCnt.approval_cnt');
// メールのためのコンテンツタイトル
$contentTitleForMail = Hash::get($viewVars, $viewVarsKey['contentTitleForMail']);
$output .= $this->_View->element('ContentComments.index', array(
'contentKey' => $contentKey,
'contentTitleForMail' => $contentTitleForMail,
'useCommentApproval' => $useCommentApproval,
'contentComments' => $this->request->data('ContentComments'),
'approvalCnt' => $approvalCnt,
'isVisitorCreatable' => $isVisitorCreatable,
));
}
return $output;
}
}