2013-12-01 23:54:39 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-04 16:12:05 +02:00
|
|
|
* Bulk action handler for deleting records.
|
|
|
|
*
|
2013-12-01 23:54:39 +01:00
|
|
|
* @author colymba
|
|
|
|
*/
|
|
|
|
class GridFieldBulkActionDeleteHandler extends GridFieldBulkActionHandler
|
2015-12-15 13:08:57 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* RequestHandler allowed actions.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $allowed_actions = array('delete');
|
2013-12-01 23:54:39 +01:00
|
|
|
|
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 SS_HTTPRequest $request
|
|
|
|
*
|
|
|
|
* @return SS_HTTPResponse List of deleted records ID
|
|
|
|
*/
|
|
|
|
public function delete(SS_HTTPRequest $request)
|
|
|
|
{
|
|
|
|
$ids = array();
|
2013-12-01 23:54:39 +01:00
|
|
|
|
2015-12-15 13:08:57 +01:00
|
|
|
foreach ($this->getRecords() as $record) {
|
|
|
|
array_push($ids, $record->ID);
|
|
|
|
$record->delete();
|
|
|
|
}
|
2013-12-01 23:54:39 +01:00
|
|
|
|
2015-12-15 13:08:57 +01:00
|
|
|
$response = new SS_HTTPResponse(Convert::raw2json(array(
|
|
|
|
'done' => true,
|
|
|
|
'records' => $ids,
|
|
|
|
)));
|
|
|
|
$response->addHeader('Content-Type', 'text/json');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|