-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContentCommentsController.php
More file actions
178 lines (158 loc) · 4.14 KB
/
ContentCommentsController.php
File metadata and controls
178 lines (158 loc) · 4.14 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
<?php
/**
* コンテントコメント Controller
*
* @author Noriko Arai <arai@nii.ac.jp>
* @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('ContentCommentsAppController', 'ContentComments.Controller');
/**
* コンテントコメント Controller
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @package NetCommons\ContentComments\Controller
*/
class ContentCommentsController extends ContentCommentsAppController {
/**
* use model
*
* @var array
*/
public $uses = array(
'ContentComments.ContentComment',
);
/**
* use components
*
* @var array
*/
public $components = array(
'ContentComments.ContentComments',
'NetCommons.Permission' => array(
//アクセスの権限
'allow' => array(
'add' => 'content_comment_creatable',
'edit' => 'content_comment_creatable',
'approve' => 'content_comment_publishable',
'delete' => 'content_comment_creatable'
),
),
);
/**
* beforeFilter
*
* @return void
* @see NetCommonsAppController::beforeFilter()
*/
public function beforeFilter() {
parent::beforeFilter();
// ブロック未選択は、何も表示しない
if (! Current::read('Block.id')) {
$this->setAction('emptyRender');
return false;
}
$isVisitorCreatable = $this->request->data('_tmp.is_visitor_creatable');
// ビジターまで投稿OKなら、ログインなしでもコメント投稿できる
if ($this->action == 'add' && $isVisitorCreatable) {
// 暫定対応:Permissionコンポーネント外す https://github.com/NetCommons3/NetCommons3/issues/198
$this->Components->unload('NetCommons.Permission');
// ゲストアクセスOKのアクションを設定
$this->Auth->allow('add');
}
}
/**
* 登録
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
// コメントする
if (!$this->ContentComments->comment()) {
$this->throwBadRequest();
return;
}
$message = __d('content_comments', 'Commented.');
$this->__setFlashMessageAndRedirect($message);
}
}
/**
* 編集
*
* @return CakeResponse
*/
public function edit() {
if ($this->request->is('put')) {
// コメントする
if (!$this->ContentComments->comment()) {
$this->throwBadRequest();
return;
}
$message = __d('content_comments', 'Edit the comment.');
$this->__setFlashMessageAndRedirect($message);
}
}
/**
* 承認
*
* @return CakeResponse
*/
public function approve() {
if ($this->request->is('put')) {
// コメントする
if (!$this->ContentComments->comment()) {
$this->throwBadRequest();
return;
}
$message = __d('content_comments', 'Approved the comment.');
$this->__setFlashMessageAndRedirect($message);
}
}
/**
* 削除
*
* @return CakeResponse
*/
public function delete() {
if ($this->request->is('delete')) {
// コメントする
if (!$this->ContentComments->comment()) {
$this->throwBadRequest();
return;
}
$message = __d('content_comments', 'Comment has been deleted.');
$this->__setFlashMessageAndRedirect($message);
}
}
/**
* _setFlashMessageAndRedirect
*
* @param string $message flash error message
* @return void
*/
private function __setFlashMessageAndRedirect($message) {
// エラーなし
if (!$this->ContentComment->validationErrors) {
$status = $this->request->data('ContentComment.status');
// 承認依頼ならワーニング表示
if ($status == WorkflowComponent::STATUS_APPROVAL_WAITING) {
$message = __d('content_comments',
'Received your comment. It does not appear until it has been approved.');
$this->NetCommons->setFlashNotification($message, array(
'class' => 'warning',
'interval' => NetCommonsComponent::ALERT_VALIDATE_ERROR_INTERVAL,
));
} else {
$this->NetCommons->setFlashNotification($message, array(
'class' => 'success',
'interval' => NetCommonsComponent::ALERT_SUCCESS_INTERVAL,
));
}
}
// 一覧へ
$this->redirect($this->request->referer(true));
}
}