2013-12-21 12:19:11 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package comments
|
|
|
|
*/
|
|
|
|
class CommentsGridFieldBulkAction extends GridFieldBulkActionHandler {
|
2015-04-16 14:40:16 +12:00
|
|
|
|
2013-12-21 12:19:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-11 22:15:24 +12:00
|
|
|
* A {@link GridFieldBulkActionHandler} for bulk marking comments as spam.
|
2013-12-21 12:19:11 +13:00
|
|
|
*
|
|
|
|
* @package comments
|
|
|
|
*/
|
2015-04-13 15:41:18 +12:00
|
|
|
class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction {
|
2015-05-11 22:15:24 +12:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-12-21 12:19:11 +13:00
|
|
|
private static $allowed_actions = array(
|
2015-04-16 14:40:16 +12:00
|
|
|
'spam',
|
|
|
|
'approve',
|
2013-12-21 12:19:11 +13:00
|
|
|
);
|
|
|
|
|
2015-05-11 22:15:24 +12:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-12-21 12:19:11 +13:00
|
|
|
private static $url_handlers = array(
|
2015-04-16 14:40:16 +12:00
|
|
|
'spam' => 'spam',
|
|
|
|
'approve' => 'approve',
|
2013-12-21 12:19:11 +13:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2015-05-11 22:15:24 +12:00
|
|
|
/**
|
|
|
|
* @param SS_HTTPRequest $request
|
|
|
|
*
|
|
|
|
* @return SS_HTTPResponse
|
|
|
|
*/
|
2015-04-16 14:40:16 +12:00
|
|
|
public function spam(SS_HTTPRequest $request) {
|
2013-12-21 12:19:11 +13:00
|
|
|
$ids = array();
|
2015-04-16 14:40:16 +12:00
|
|
|
|
|
|
|
foreach($this->getRecords() as $record) {
|
2015-05-11 22:15:24 +12:00
|
|
|
/**
|
|
|
|
* @var Comment $record
|
|
|
|
*/
|
2015-04-16 12:48:30 +12:00
|
|
|
$record->markSpam();
|
2015-05-11 22:15:24 +12:00
|
|
|
|
|
|
|
array_push($ids, $record->ID);
|
2013-12-21 12:19:11 +13:00
|
|
|
}
|
|
|
|
|
2015-05-11 22:15:24 +12:00
|
|
|
$response = new SS_HTTPResponse(
|
|
|
|
Convert::raw2json(array(
|
|
|
|
'done' => true,
|
|
|
|
'records' => $ids,
|
|
|
|
))
|
|
|
|
);
|
2013-12-21 12:19:11 +13:00
|
|
|
|
|
|
|
$response->addHeader('Content-Type', 'text/json');
|
|
|
|
|
2015-04-16 14:40:16 +12:00
|
|
|
return $response;
|
2013-12-21 12:19:11 +13:00
|
|
|
}
|
2015-04-13 15:41:18 +12:00
|
|
|
|
2015-05-11 22:15:24 +12:00
|
|
|
/**
|
|
|
|
* @param SS_HTTPRequest $request
|
|
|
|
*
|
|
|
|
* @return SS_HTTPResponse
|
|
|
|
*/
|
2015-04-16 14:40:16 +12:00
|
|
|
public function approve(SS_HTTPRequest $request) {
|
2015-04-13 15:41:18 +12:00
|
|
|
$ids = array();
|
|
|
|
|
|
|
|
foreach($this->getRecords() as $record) {
|
2015-05-11 22:15:24 +12:00
|
|
|
/**
|
|
|
|
* @var Comment $record
|
|
|
|
*/
|
2015-04-16 12:48:30 +12:00
|
|
|
$record->markApproved();
|
2015-05-11 22:15:24 +12:00
|
|
|
|
|
|
|
array_push($ids, $record->ID);
|
2015-04-13 15:41:18 +12:00
|
|
|
}
|
|
|
|
|
2015-05-11 22:15:24 +12:00
|
|
|
$response = new SS_HTTPResponse(
|
|
|
|
Convert::raw2json(array(
|
|
|
|
'done' => true,
|
|
|
|
'records' => $ids,
|
|
|
|
))
|
|
|
|
);
|
2015-04-13 15:41:18 +12:00
|
|
|
|
|
|
|
$response->addHeader('Content-Type', 'text/json');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2015-05-11 22:15:24 +12:00
|
|
|
}
|