silverstripe-comments/code/admin/CommentsGridFieldAction.php

111 lines
2.8 KiB
PHP
Raw Permalink Normal View History

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