diff --git a/code/admin/CommentsGridFieldAction.php b/code/admin/CommentsGridFieldAction.php index 0043555c..bb1fc304 100644 --- a/code/admin/CommentsGridFieldAction.php +++ b/code/admin/CommentsGridFieldAction.php @@ -41,21 +41,25 @@ public function getColumnContent($gridField, $record, $columnName) { $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 @@ public function getActions($gridField) { 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 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat 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( diff --git a/code/admin/CommentsGridFieldBulkAction.php b/code/admin/CommentsGridFieldBulkAction.php index 47611cd4..138ff701 100644 --- a/code/admin/CommentsGridFieldBulkAction.php +++ b/code/admin/CommentsGridFieldBulkAction.php @@ -30,10 +30,7 @@ public function spam(SS_HTTPRequest $request) { 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 @@ public function approve(SS_HTTPRequest $request) { 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( diff --git a/code/admin/CommentsGridFieldConfig.php b/code/admin/CommentsGridFieldConfig.php index a4910b3a..bc01dd4a 100644 --- a/code/admin/CommentsGridFieldConfig.php +++ b/code/admin/CommentsGridFieldConfig.php @@ -14,8 +14,8 @@ public function __construct($itemsPerPage = 25) { 'ParentTitle' => function($value, &$item) { return sprintf( '%s', - Convert::raw2xml($item->Link()), - Convert::raw2xml($value) + Convert::raw2att($item->Link()), + $item->obj('ParentTitle')->forTemplate() ); } )); diff --git a/code/controllers/CommentingController.php b/code/controllers/CommentingController.php index b7d3b4d6..844bb194 100644 --- a/code/controllers/CommentingController.php +++ b/code/controllers/CommentingController.php @@ -225,9 +225,7 @@ public function spam() { } 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 @@ public function ham() { 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 @@ public function approve() { } 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') diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index 264211f3..2ec20849 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -446,6 +446,34 @@ public function ApproveLink($member = null) { } } + /** + * 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 */