2018-04-03 02:21:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
|
|
|
|
|
2022-11-16 00:13:50 +01:00
|
|
|
use SilverStripe\Dev\Deprecation;
|
2018-04-03 02:21:47 +02:00
|
|
|
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
|
|
|
|
*
|
2022-11-16 00:13:50 +01:00
|
|
|
* @deprecated 3.1.0 Use concrete Spam or Approve handlers instead
|
2018-04-03 02:21:47 +02:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
2022-11-16 00:13:50 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
Deprecation::notice('3.1.0', 'Use concrete Spam or Approve handlers instead', Deprecation::SCOPE_CLASS);
|
|
|
|
}
|
|
|
|
|
2018-04-03 02:21:47 +02:00
|
|
|
public function spam(HTTPRequest $request)
|
|
|
|
{
|
|
|
|
$ids = array();
|
|
|
|
|
|
|
|
foreach ($this->getRecords() as $record) {
|
|
|
|
array_push($ids, $record->ID);
|
|
|
|
$record->markSpam();
|
|
|
|
}
|
|
|
|
|
2018-10-28 22:31:19 +01:00
|
|
|
$response = new HTTPResponse(json_encode(array(
|
2018-04-03 02:21:47 +02:00
|
|
|
'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();
|
|
|
|
}
|
|
|
|
|
2018-10-28 22:31:19 +01:00
|
|
|
$response = new HTTPResponse(json_encode(array(
|
2018-04-03 02:21:47 +02:00
|
|
|
'done' => true,
|
|
|
|
'records' => $ids
|
|
|
|
)));
|
|
|
|
|
|
|
|
$response->addHeader('Content-Type', 'text/json');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|