mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
API Use concrete Handler implementations for Spam and Approve bulk editing
This commit is contained in:
parent
b90ec7715e
commit
192ddbb4b5
49
src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php
Normal file
49
src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
||||
|
||||
use Colymba\BulkManager\BulkAction\Handler;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
|
||||
/**
|
||||
* A {@link Handler} for bulk approving comments
|
||||
*/
|
||||
class ApproveHandler extends Handler
|
||||
{
|
||||
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
|
||||
*/
|
||||
public function index(HTTPRequest $request)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
49
src/Admin/CommentsGridFieldBulkAction/SpamHandler.php
Normal file
49
src/Admin/CommentsGridFieldBulkAction/SpamHandler.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
||||
|
||||
use Colymba\BulkManager\BulkAction\Handler;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
|
||||
/**
|
||||
* A {@link Handler} for bulk marking comments as spam
|
||||
*/
|
||||
class SpamHandler extends Handler
|
||||
{
|
||||
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
|
||||
*/
|
||||
public function index(HTTPRequest $request)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
@ -3,7 +3,8 @@
|
||||
namespace SilverStripe\Comments\Admin;
|
||||
|
||||
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\Forms\GridField\GridFieldConfig_RecordEditor;
|
||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||
@ -31,32 +32,14 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
|
||||
));
|
||||
|
||||
// Add bulk option
|
||||
$manager = new BulkManager();
|
||||
$manager = new BulkManager(null, false);
|
||||
|
||||
$manager->addBulkAction(
|
||||
'spam',
|
||||
_t(__CLASS__ . '.SPAM', 'Spam'),
|
||||
Handler::class,
|
||||
array(
|
||||
'isAjax' => true,
|
||||
'icon' => 'cross',
|
||||
'isDestructive' => false
|
||||
)
|
||||
);
|
||||
$spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam'));
|
||||
$approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve'));
|
||||
|
||||
$manager->addBulkAction(
|
||||
'approve',
|
||||
_t(__CLASS__ . '.APPROVE', 'Approve'),
|
||||
Handler::class,
|
||||
array(
|
||||
'isAjax' => true,
|
||||
'icon' => 'cross',
|
||||
'isDestructive' => false
|
||||
)
|
||||
);
|
||||
|
||||
$manager->removeBulkAction('bulkEdit');
|
||||
$manager->removeBulkAction('unLink');
|
||||
$manager
|
||||
->addBulkAction($spamAction)
|
||||
->addBulkAction($approveAction);
|
||||
|
||||
$this->addComponent($manager);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user