mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Merge pull request #232 from creative-commoners/pulls/3.0/bulk-editing-compat
API Use concrete Handler implementations for Spam and Approve bulk editing
This commit is contained in:
commit
90c42ff027
28
src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php
Normal file
28
src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
||||||
|
|
||||||
|
use SilverStripe\Comments\Model\Comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Handler} for bulk approving comments
|
||||||
|
*/
|
||||||
|
class ApproveHandler extends CommentHandler
|
||||||
|
{
|
||||||
|
private static $url_segment = 'approve';
|
||||||
|
|
||||||
|
protected $buttonClasses = 'font-icon-tick';
|
||||||
|
|
||||||
|
protected $label = 'Approve';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Comment $comment
|
||||||
|
*
|
||||||
|
* @return Comment
|
||||||
|
*/
|
||||||
|
public function updateComment($comment)
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
}
|
@ -1,72 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
|
||||||
|
|
||||||
use Colymba\BulkManager\BulkAction\Handler as GridFieldBulkActionHandler;
|
|
||||||
use SilverStripe\Core\Convert;
|
|
||||||
use SilverStripe\Control\HTTPRequest;
|
|
||||||
use SilverStripe\Control\HTTPResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link GridFieldBulkActionHandler} for bulk marking comments as spam
|
|
||||||
*
|
|
||||||
* @package comments
|
|
||||||
*/
|
|
||||||
class Handler extends GridFieldBulkActionHandler
|
|
||||||
{
|
|
||||||
private static $allowed_actions = array(
|
|
||||||
'spam',
|
|
||||||
'approve',
|
|
||||||
);
|
|
||||||
|
|
||||||
private static $url_handlers = array(
|
|
||||||
'spam' => 'spam',
|
|
||||||
'approve' => 'approve',
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param HTTPRequest $request
|
|
||||||
* @return HTTPResponse
|
|
||||||
*/
|
|
||||||
public function spam(HTTPRequest $request)
|
|
||||||
{
|
|
||||||
$ids = array();
|
|
||||||
|
|
||||||
foreach ($this->getRecords() as $record) {
|
|
||||||
array_push($ids, $record->ID);
|
|
||||||
$record->markSpam();
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = new HTTPResponse(Convert::raw2json(array(
|
|
||||||
'done' => true,
|
|
||||||
'records' => $ids
|
|
||||||
)));
|
|
||||||
|
|
||||||
$response->addHeader('Content-Type', 'text/json');
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param HTTPRequest $request
|
|
||||||
* @return HTTPResponse
|
|
||||||
*/
|
|
||||||
public function approve(HTTPRequest $request)
|
|
||||||
{
|
|
||||||
$ids = array();
|
|
||||||
|
|
||||||
foreach ($this->getRecords() as $record) {
|
|
||||||
array_push($ids, $record->ID);
|
|
||||||
$record->markApproved();
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = new HTTPResponse(Convert::raw2json(array(
|
|
||||||
'done' => true,
|
|
||||||
'records' => $ids
|
|
||||||
)));
|
|
||||||
|
|
||||||
$response->addHeader('Content-Type', 'text/json');
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
28
src/Admin/CommentsGridFieldBulkAction/SpamHandler.php
Normal file
28
src/Admin/CommentsGridFieldBulkAction/SpamHandler.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
||||||
|
|
||||||
|
use SilverStripe\Comments\Model\Comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Handler} for bulk marking comments as spam
|
||||||
|
*/
|
||||||
|
class SpamHandler extends CommentHandler
|
||||||
|
{
|
||||||
|
private static $url_segment = 'spam';
|
||||||
|
|
||||||
|
protected $buttonClasses = 'font-icon-cross-mark';
|
||||||
|
|
||||||
|
protected $label = 'Spam';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Comment $comment
|
||||||
|
*
|
||||||
|
* @return Comment
|
||||||
|
*/
|
||||||
|
public function updateComment($comment)
|
||||||
|
{
|
||||||
|
$comment->markSpam();
|
||||||
|
return $comment;
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,8 @@
|
|||||||
namespace SilverStripe\Comments\Admin;
|
namespace SilverStripe\Comments\Admin;
|
||||||
|
|
||||||
use Colymba\BulkManager\BulkManager;
|
use Colymba\BulkManager\BulkManager;
|
||||||
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handler;
|
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\ApproveHandler;
|
||||||
|
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\SpamHandler;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||||
@ -31,32 +32,14 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
|
|||||||
));
|
));
|
||||||
|
|
||||||
// Add bulk option
|
// Add bulk option
|
||||||
$manager = new BulkManager();
|
$manager = new BulkManager(null, false);
|
||||||
|
|
||||||
$manager->addBulkAction(
|
$spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam'));
|
||||||
'spam',
|
$approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve'));
|
||||||
_t(__CLASS__ . '.SPAM', 'Spam'),
|
|
||||||
Handler::class,
|
|
||||||
array(
|
|
||||||
'isAjax' => true,
|
|
||||||
'icon' => 'cross',
|
|
||||||
'isDestructive' => false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$manager->addBulkAction(
|
$manager
|
||||||
'approve',
|
->addBulkAction($spamAction)
|
||||||
_t(__CLASS__ . '.APPROVE', 'Approve'),
|
->addBulkAction($approveAction);
|
||||||
Handler::class,
|
|
||||||
array(
|
|
||||||
'isAjax' => true,
|
|
||||||
'icon' => 'cross',
|
|
||||||
'isDestructive' => false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$manager->removeBulkAction('bulkEdit');
|
|
||||||
$manager->removeBulkAction('unLink');
|
|
||||||
|
|
||||||
$this->addComponent($manager);
|
$this->addComponent($manager);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user