silverstripe-comments/src/Admin/CommentAdmin.php

144 lines
3.9 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Comments\Admin;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Comments\Admin\CommentsGridField;
use SilverStripe\Comments\Model\Comment;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Security\Security;
2017-09-18 04:16:24 +02:00
use SilverStripe\View\SSViewer;
/**
* Comment administration system within the CMS
*
* @package comments
*/
2016-02-19 01:48:25 +01:00
class CommentAdmin extends LeftAndMain implements PermissionProvider
{
private static $url_segment = 'comments';
private static $url_rule = '/$Action';
private static $menu_title = 'Comments';
2017-09-18 04:16:24 +02:00
private static $menu_icon_class = 'font-icon-comment';
2016-02-19 01:48:25 +01:00
private static $allowed_actions = array(
'approvedmarked',
'deleteall',
'deletemarked',
'hammarked',
'showtable',
'spammarked',
'EditForm',
'unmoderated'
);
2017-09-18 04:16:24 +02:00
private static $required_permission_codes = 'CMS_ACCESS_CommentAdmin';
2016-02-19 01:48:25 +01:00
public function providePermissions()
{
return array(
"CMS_ACCESS_CommentAdmin" => array(
2017-09-18 04:16:24 +02:00
'name' => _t('SilverStripe\\Comments\\Admin\\CommentAdmin.ADMIN_PERMISSION', "Access to 'Comments' section"),
'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
2016-02-19 01:48:25 +01:00
)
);
}
/**
* @return Form
*/
public function getEditForm($id = null, $fields = null)
{
if (!$id) {
$id = $this->currentPageID();
}
$form = parent::getEditForm($id);
$record = $this->getRecord($id);
if ($record && !$record->canView()) {
return Security::permissionFailure($this);
}
$newComments = Comment::get()->filter('Moderated', 0);
$newGrid = new CommentsGridField(
'NewComments',
2017-09-18 04:16:24 +02:00
'',
2016-02-19 01:48:25 +01:00
$newComments,
CommentsGridFieldConfig::create()
);
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
$approvedGrid = new CommentsGridField(
'ApprovedComments',
2017-09-18 04:16:24 +02:00
'',
2016-02-19 01:48:25 +01:00
$approvedComments,
CommentsGridFieldConfig::create()
);
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
$spamGrid = new CommentsGridField(
'SpamComments',
2017-09-18 04:16:24 +02:00
'',
2016-02-19 01:48:25 +01:00
$spamComments,
CommentsGridFieldConfig::create()
);
$newCount = '(' . count($newComments) . ')';
$approvedCount = '(' . count($approvedComments) . ')';
$spamCount = '(' . count($spamComments) . ')';
$fields = new FieldList(
$root = new TabSet(
2017-09-18 04:16:24 +02:00
'Comments',
2017-09-13 23:41:11 +02:00
new Tab(
'NewComments',
2017-09-18 04:16:24 +02:00
_t(__CLASS__.'.NewComments', 'New') . ' ' . $newCount,
2016-02-19 01:48:25 +01:00
$newGrid
),
2017-09-13 23:41:11 +02:00
new Tab(
'ApprovedComments',
2017-09-18 04:16:24 +02:00
_t(__CLASS__.'.ApprovedComments', 'Approved') . ' ' . $approvedCount,
2016-02-19 01:48:25 +01:00
$approvedGrid
),
2017-09-13 23:41:11 +02:00
new Tab(
'SpamComments',
2017-09-18 04:16:24 +02:00
_t(__CLASS__.'.SpamComments', 'Spam') . ' ' . $spamCount,
2016-02-19 01:48:25 +01:00
$spamGrid
)
)
);
$actions = new FieldList();
$form = new Form(
$this,
'EditForm',
$fields,
$actions
);
$form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
if ($form->Fields()->hasTabset()) {
2017-09-18 04:16:24 +02:00
// $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
2016-02-19 01:48:25 +01:00
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
}
$this->extend('updateEditForm', $form);
return $form;
}
}