GridFieldBulkEditingTools/src/BulkManager/BulkAction/DeleteHandler.php

58 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace Colymba\BulkManager\BulkAction;
use Colymba\BulkManager\BulkAction\Handler;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
/**
2014-05-04 16:12:05 +02:00
* Bulk action handler for deleting records.
*
* @author colymba
*/
class DeleteHandler extends Handler
2015-12-15 13:08:57 +01:00
{
/**
* RequestHandler allowed actions.
*
* @var array
*/
private static $allowed_actions = array('delete');
2015-12-15 13:08:57 +01:00
/**
* RequestHandler url => action map.
*
* @var array
*/
private static $url_handlers = array(
'delete' => 'delete',
);
2014-05-11 12:32:21 +02:00
2015-12-15 13:08:57 +01:00
/**
* Delete the selected records passed from the delete bulk action.
*
* @param HTTPRequest $request
*
* @return HTTPResponse List of deleted records ID
2015-12-15 13:08:57 +01:00
*/
public function delete(HTTPRequest $request)
2015-12-15 13:08:57 +01:00
{
$ids = array();
2015-12-15 13:08:57 +01:00
foreach ($this->getRecords() as $record) {
array_push($ids, $record->ID);
$record->delete();
}
$response = new HTTPResponse(Convert::raw2json(array(
2015-12-15 13:08:57 +01:00
'done' => true,
'records' => $ids,
)));
$response->addHeader('Content-Type', 'text/json');
return $response;
}
}