silverstripe-comments/code/admin/CommentsGridFieldAction.php

101 lines
2.0 KiB
PHP
Raw Normal View History

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 = "";
if(!$record->IsSpam || !$record->Moderated) {
$field .= GridField_FormAction::create(
$gridField,
'CustomAction' . $record->ID . 'Spam',
'Spam',
'spam',
array('RecordID' => $record->ID)
)->Field();
}
2015-04-13 05:41:18 +02:00
if($record->IsSpam || !$record->Moderated) {
$field .= GridField_FormAction::create(
$gridField,
'CustomAction' . $record->ID . 'Approve',
'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"]);
$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"]);
$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
);
}
}
}