mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
801025c39a
Added translation support for the CommentsAdmin's GridField's inline spam/approve marking labels, and also for the success messages (controller response).
111 lines
2.8 KiB
PHP
111 lines
2.8 KiB
PHP
<?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',
|
|
_t('CommentsGridFieldAction.SPAM', 'Spam'),
|
|
'spam',
|
|
array('RecordID' => $record->ID)
|
|
)->Field();
|
|
}
|
|
|
|
if ($record->IsSpam || !$record->Moderated) {
|
|
$field .= GridField_FormAction::create(
|
|
$gridField,
|
|
'CustomAction' . $record->ID . 'Approve',
|
|
_t('CommentsGridFieldAction.APPROVE', 'Approve'),
|
|
'approve',
|
|
array('RecordID' => $record->ID)
|
|
)->Field();
|
|
}
|
|
|
|
return $field;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getActions($gridField)
|
|
{
|
|
return array('spam', 'approve');
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
|
{
|
|
if ($actionName == 'spam') {
|
|
$comment = Comment::get()->byID($arguments["RecordID"]);
|
|
$comment->markSpam();
|
|
|
|
// output a success message to the user
|
|
Controller::curr()->getResponse()->setStatusCode(
|
|
200,
|
|
_t('CommentsGridFieldAction.COMMENTMARKEDSPAM', 'Comment marked as spam.')
|
|
);
|
|
}
|
|
|
|
if ($actionName == 'approve') {
|
|
$comment = Comment::get()->byID($arguments["RecordID"]);
|
|
$comment->markApproved();
|
|
|
|
// output a success message to the user
|
|
Controller::curr()->getResponse()->setStatusCode(
|
|
200,
|
|
_t('CommentsGridFieldAction.COMMENTAPPROVED', 'Comment approved.')
|
|
);
|
|
}
|
|
}
|
|
}
|