mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Merge pull request #113 from tractorcow/pulls/2.0/comment-gridfield-actions
BUG Only show correct gridfield options for comments
This commit is contained in:
commit
0c698a813a
@ -41,21 +41,25 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
|
||||
$field = "";
|
||||
|
||||
$field .= GridField_FormAction::create(
|
||||
$gridField,
|
||||
'CustomAction' . $record->ID,
|
||||
'Spam',
|
||||
'spam',
|
||||
array('RecordID' => $record->ID)
|
||||
)->Field();
|
||||
if(!$record->IsSpam || !$record->Moderated) {
|
||||
$field .= GridField_FormAction::create(
|
||||
$gridField,
|
||||
'CustomAction' . $record->ID,
|
||||
'Spam',
|
||||
'spam',
|
||||
array('RecordID' => $record->ID)
|
||||
)->Field();
|
||||
}
|
||||
|
||||
$field .= GridField_FormAction::create(
|
||||
$gridField,
|
||||
'CustomAction' . $record->ID,
|
||||
'Approve',
|
||||
'approve',
|
||||
array('RecordID' => $record->ID)
|
||||
)->Field();
|
||||
if($record->IsSpam || !$record->Moderated) {
|
||||
$field .= GridField_FormAction::create(
|
||||
$gridField,
|
||||
'CustomAction' . $record->ID,
|
||||
'Approve',
|
||||
'approve',
|
||||
array('RecordID' => $record->ID)
|
||||
)->Field();
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
@ -73,10 +77,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
||||
if($actionName == 'spam') {
|
||||
$comment = Comment::get()->byID($arguments["RecordID"]);
|
||||
|
||||
$comment->Moderated = true;
|
||||
$comment->IsSpam = true;
|
||||
$comment->write();
|
||||
$comment->markSpam();
|
||||
|
||||
// output a success message to the user
|
||||
Controller::curr()->getResponse()->setStatusCode(
|
||||
@ -87,10 +88,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
|
||||
if($actionName == 'approve') {
|
||||
$comment = Comment::get()->byID($arguments["RecordID"]);
|
||||
|
||||
$comment->Moderated = true;
|
||||
$comment->IsSpam = false;
|
||||
$comment->write();
|
||||
$comment->markApproved();
|
||||
|
||||
// output a success message to the user
|
||||
Controller::curr()->getResponse()->setStatusCode(
|
||||
|
@ -30,10 +30,7 @@ class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction {
|
||||
|
||||
foreach($this->getRecords() as $record) {
|
||||
array_push($ids, $record->ID);
|
||||
|
||||
$record->Moderated = 1;
|
||||
$record->IsSpam = 1;
|
||||
$record->write();
|
||||
$record->markSpam();
|
||||
}
|
||||
|
||||
$response = new SS_HTTPResponse(Convert::raw2json(array(
|
||||
@ -52,10 +49,7 @@ class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction {
|
||||
|
||||
foreach($this->getRecords() as $record) {
|
||||
array_push($ids, $record->ID);
|
||||
|
||||
$record->Moderated = 1;
|
||||
$record->IsSpam = 0;
|
||||
$record->write();
|
||||
$record->markApproved();
|
||||
}
|
||||
|
||||
$response = new SS_HTTPResponse(Convert::raw2json(array(
|
||||
|
@ -14,8 +14,8 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor {
|
||||
'ParentTitle' => function($value, &$item) {
|
||||
return sprintf(
|
||||
'<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
|
||||
Convert::raw2xml($item->Link()),
|
||||
Convert::raw2xml($value)
|
||||
Convert::raw2att($item->Link()),
|
||||
$item->obj('ParentTitle')->forTemplate()
|
||||
);
|
||||
}
|
||||
));
|
||||
|
@ -225,9 +225,7 @@ class CommentingController extends Controller {
|
||||
}
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
|
||||
$comment->IsSpam = true;
|
||||
$comment->Moderated = true;
|
||||
$comment->write();
|
||||
$comment->markSpam();
|
||||
|
||||
return $this->request->isAjax()
|
||||
? $comment->renderWith('CommentsInterface_singlecomment')
|
||||
@ -244,10 +242,8 @@ class CommentingController extends Controller {
|
||||
return Security::permissionFailure($this, 'You do not have permission to edit this comment');
|
||||
}
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
|
||||
$comment->IsSpam = false;
|
||||
$comment->Moderated = true;
|
||||
$comment->write();
|
||||
|
||||
$comment->markApproved();
|
||||
|
||||
return $this->request->isAjax()
|
||||
? $comment->renderWith('CommentsInterface_singlecomment')
|
||||
@ -265,9 +261,7 @@ class CommentingController extends Controller {
|
||||
}
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
|
||||
$comment->IsSpam = false;
|
||||
$comment->Moderated = true;
|
||||
$comment->write();
|
||||
$comment->markApproved();
|
||||
|
||||
return $this->request->isAjax()
|
||||
? $comment->renderWith('CommentsInterface_singlecomment')
|
||||
|
@ -446,6 +446,34 @@ class Comment extends DataObject {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this comment as spam
|
||||
*/
|
||||
public function markSpam() {
|
||||
$this->IsSpam = true;
|
||||
$this->Moderated = true;
|
||||
$this->write();
|
||||
$this->extend('afterMarkSpam');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this comment as approved
|
||||
*/
|
||||
public function markApproved() {
|
||||
$this->IsSpam = false;
|
||||
$this->Moderated = true;
|
||||
$this->write();
|
||||
$this->extend('afterMarkApproved');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this comment as unapproved
|
||||
*/
|
||||
public function markUnapproved() {
|
||||
$this->Moderated = false;
|
||||
$this->write();
|
||||
$this->extend('afterMarkUnapproved');
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user