mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
7221897f27
* Basic SS4 compat: Implemented namespacing, updated some Image manipulations, readmes, composer configuration * Add bootstrap form styles to the bulk manager * API Rename classes to be less confusing with the namespaces
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Colymba\BulkManager\BulkAction;
|
|
|
|
use Colymba\BulkManager\BulkAction\Handler;
|
|
use SilverStripe\Control\HTTPRequest;
|
|
use SilverStripe\Control\HTTPResponse;
|
|
use SilverStripe\Core\Convert;
|
|
|
|
/**
|
|
* Bulk action handler for deleting records.
|
|
*
|
|
* @author colymba
|
|
*/
|
|
class DeleteHandler extends Handler
|
|
{
|
|
/**
|
|
* RequestHandler allowed actions.
|
|
*
|
|
* @var array
|
|
*/
|
|
private static $allowed_actions = array('delete');
|
|
|
|
/**
|
|
* RequestHandler url => action map.
|
|
*
|
|
* @var array
|
|
*/
|
|
private static $url_handlers = array(
|
|
'delete' => 'delete',
|
|
);
|
|
|
|
/**
|
|
* Delete the selected records passed from the delete bulk action.
|
|
*
|
|
* @param HTTPRequest $request
|
|
*
|
|
* @return HTTPResponse List of deleted records ID
|
|
*/
|
|
public function delete(HTTPRequest $request)
|
|
{
|
|
$ids = array();
|
|
|
|
foreach ($this->getRecords() as $record) {
|
|
array_push($ids, $record->ID);
|
|
$record->delete();
|
|
}
|
|
|
|
$response = new HTTPResponse(Convert::raw2json(array(
|
|
'done' => true,
|
|
'records' => $ids,
|
|
)));
|
|
$response->addHeader('Content-Type', 'text/json');
|
|
|
|
return $response;
|
|
}
|
|
}
|