2015-04-13 05:41:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_ActionProvider {
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function augmentColumns($gridField, &$columns) {
|
|
|
|
if(!in_array('Actions', $columns)) {
|
|
|
|
$columns[] = 'Actions';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) {
|
|
|
|
return array('class' => 'col-buttons');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getColumnMetadata($gridField, $columnName) {
|
|
|
|
if($columnName == 'Actions') {
|
|
|
|
return array('title' => '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getColumnsHandled($gridField) {
|
|
|
|
return array('Actions');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getColumnContent($gridField, $record, $columnName) {
|
|
|
|
if(!$record->canEdit()) return;
|
|
|
|
|
|
|
|
$field = "";
|
|
|
|
|
2015-04-16 02:48:30 +02:00
|
|
|
if(!$record->IsSpam || !$record->Moderated) {
|
|
|
|
$field .= GridField_FormAction::create(
|
|
|
|
$gridField,
|
2015-11-17 01:12:21 +01:00
|
|
|
'CustomAction' . $record->ID . 'Spam',
|
2015-04-16 02:48:30 +02:00
|
|
|
'Spam',
|
|
|
|
'spam',
|
|
|
|
array('RecordID' => $record->ID)
|
|
|
|
)->Field();
|
|
|
|
}
|
2015-04-13 05:41:18 +02:00
|
|
|
|
2015-04-16 02:48:30 +02:00
|
|
|
if($record->IsSpam || !$record->Moderated) {
|
|
|
|
$field .= GridField_FormAction::create(
|
|
|
|
$gridField,
|
2015-11-17 01:12:21 +01:00
|
|
|
'CustomAction' . $record->ID . 'Approve',
|
2015-04-16 02:48:30 +02:00
|
|
|
'Approve',
|
|
|
|
'approve',
|
|
|
|
array('RecordID' => $record->ID)
|
|
|
|
)->Field();
|
|
|
|
}
|
2015-04-13 05:41:18 +02:00
|
|
|
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getActions($gridField) {
|
2015-04-16 04:40:16 +02:00
|
|
|
return array('spam', 'approve');
|
2015-04-13 05:41:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
|
|
|
if($actionName == 'spam') {
|
|
|
|
$comment = Comment::get()->byID($arguments["RecordID"]);
|
2015-04-16 02:48:30 +02:00
|
|
|
$comment->markSpam();
|
2015-04-13 05:41:18 +02:00
|
|
|
|
|
|
|
// output a success message to the user
|
|
|
|
Controller::curr()->getResponse()->setStatusCode(
|
|
|
|
200,
|
|
|
|
'Comment marked as spam.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-16 04:40:16 +02:00
|
|
|
if($actionName == 'approve') {
|
2015-04-13 05:41:18 +02:00
|
|
|
$comment = Comment::get()->byID($arguments["RecordID"]);
|
2015-04-16 02:48:30 +02:00
|
|
|
$comment->markApproved();
|
2015-04-13 05:41:18 +02:00
|
|
|
|
|
|
|
// output a success message to the user
|
|
|
|
Controller::curr()->getResponse()->setStatusCode(
|
|
|
|
200,
|
2015-04-16 04:40:16 +02:00
|
|
|
'Comment approved.'
|
2015-04-13 05:41:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2015-11-17 01:12:21 +01:00
|
|
|
}
|