BUG Only show correct gridfield options for comments

This commit is contained in:
Damian Mooyman 2015-04-16 12:48:30 +12:00
parent 26361cccba
commit 85653fea1e
5 changed files with 56 additions and 42 deletions

View File

@ -41,6 +41,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
$field = "";
if(!$record->IsSpam || !$record->Moderated) {
$field .= GridField_FormAction::create(
$gridField,
'CustomAction' . $record->ID,
@ -48,7 +49,9 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
'spam',
array('RecordID' => $record->ID)
)->Field();
}
if($record->IsSpam || !$record->Moderated) {
$field .= GridField_FormAction::create(
$gridField,
'CustomAction' . $record->ID,
@ -56,6 +59,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
'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(

View File

@ -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(

View File

@ -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()
);
}
));

View File

@ -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')
@ -245,9 +243,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')
@ -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')

View File

@ -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
*/