mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Move comment handles to shared parent class
This commit is contained in:
parent
192ddbb4b5
commit
909066c0a8
@ -2,48 +2,27 @@
|
||||
|
||||
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
||||
|
||||
use Colymba\BulkManager\BulkAction\Handler;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Comments\Model\Comment;
|
||||
|
||||
/**
|
||||
* A {@link Handler} for bulk approving comments
|
||||
*/
|
||||
class ApproveHandler extends Handler
|
||||
class ApproveHandler extends CommentHandler
|
||||
{
|
||||
private static $allowed_actions = ['index'];
|
||||
|
||||
private static $url_segment = 'approve';
|
||||
|
||||
protected $xhr = true;
|
||||
|
||||
protected $buttonClasses = 'font-icon-tick';
|
||||
|
||||
protected $destructive = false;
|
||||
|
||||
protected $label = 'Approve';
|
||||
|
||||
/**
|
||||
* @param HTTPRequest $request
|
||||
* @return HTTPResponse
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @return Comment
|
||||
*/
|
||||
public function index(HTTPRequest $request)
|
||||
public function updateComment($comment)
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach ($this->getRecords() as $record) {
|
||||
array_push($ids, $record->ID);
|
||||
$record->markApproved();
|
||||
}
|
||||
|
||||
$response = new HTTPResponse(Convert::raw2json([
|
||||
'done' => true,
|
||||
'records' => $ids,
|
||||
]));
|
||||
|
||||
$response->addHeader('Content-Type', 'text/json');
|
||||
|
||||
return $response;
|
||||
$comment->markApproved();
|
||||
return $comment;
|
||||
}
|
||||
}
|
||||
|
46
src/Admin/CommentsGridFieldBulkAction/CommentHandler.php
Normal file
46
src/Admin/CommentsGridFieldBulkAction/CommentHandler.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
||||
|
||||
use Colymba\BulkManager\BulkAction\Handler;
|
||||
use SilverStripe\Comments\Model\Comment;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
|
||||
abstract class CommentHandler extends Handler
|
||||
{
|
||||
protected $xhr = true;
|
||||
|
||||
protected $destructive = false;
|
||||
|
||||
/**
|
||||
* @param HTTPRequest $request
|
||||
* @return HTTPResponse
|
||||
*/
|
||||
public function index(HTTPRequest $request)
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach ($this->getRecords() as $comment) {
|
||||
array_push($ids, $comment->ID);
|
||||
$this->updateComment($comment);
|
||||
}
|
||||
|
||||
$response = new HTTPResponse(Convert::raw2json([
|
||||
'done' => true,
|
||||
'records' => $ids,
|
||||
]));
|
||||
|
||||
$response->addHeader('Content-Type', 'application/json');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @return Comment
|
||||
*/
|
||||
abstract public function updateComment($comment);
|
||||
}
|
@ -2,48 +2,27 @@
|
||||
|
||||
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
||||
|
||||
use Colymba\BulkManager\BulkAction\Handler;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Comments\Model\Comment;
|
||||
|
||||
/**
|
||||
* A {@link Handler} for bulk marking comments as spam
|
||||
*/
|
||||
class SpamHandler extends Handler
|
||||
class SpamHandler extends CommentHandler
|
||||
{
|
||||
private static $allowed_actions = ['index'];
|
||||
|
||||
private static $url_segment = 'spam';
|
||||
|
||||
protected $xhr = true;
|
||||
|
||||
protected $buttonClasses = 'font-icon-cross-mark';
|
||||
|
||||
protected $destructive = false;
|
||||
|
||||
protected $label = 'Spam';
|
||||
|
||||
/**
|
||||
* @param HTTPRequest $request
|
||||
* @return HTTPResponse
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @return Comment
|
||||
*/
|
||||
public function index(HTTPRequest $request)
|
||||
public function updateComment($comment)
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach ($this->getRecords() as $record) {
|
||||
array_push($ids, $record->ID);
|
||||
$record->markSpam();
|
||||
}
|
||||
|
||||
$response = new HTTPResponse(Convert::raw2json([
|
||||
'done' => true,
|
||||
'records' => $ids,
|
||||
]));
|
||||
|
||||
$response->addHeader('Content-Type', 'text/json');
|
||||
|
||||
return $response;
|
||||
$comment->markSpam();
|
||||
return $comment;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user