silverstripe-comments/src/Admin/CommentAdmin.php

152 lines
4.2 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(
'name' => _t(__CLASS__ . '.ADMIN_PERMISSION', "Access to 'Comments' section"),
2017-09-18 04:16:24 +02:00
'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()
);
$fields = FieldList::create(
$root = TabSet::create(
'Root',
Tab::create(
2017-09-13 23:41:11 +02:00
'NewComments',
_t(
__CLASS__.'.NewComments',
'New ({count})',
['count' => count($newComments)]
),
2016-02-19 01:48:25 +01:00
$newGrid
),
Tab::create(
2017-09-13 23:41:11 +02:00
'ApprovedComments',
_t(
__CLASS__.'.ApprovedComments',
'Approved ({count})',
['count' => count($approvedComments)]
),
2016-02-19 01:48:25 +01:00
$approvedGrid
),
Tab::create(
2017-09-13 23:41:11 +02:00
'SpamComments',
_t(
__CLASS__.'.SpamComments',
'Spam ({count})',
['count' => count($spamComments)]
),
2016-02-19 01:48:25 +01:00
$spamGrid
)
)
);
$actions = FieldList::create();
2016-02-19 01:48:25 +01:00
$form = Form::create(
2016-02-19 01:48:25 +01:00
$this,
'EditForm',
$fields,
$actions
);
$form->addExtraClass('cms-edit-form fill-height');
2016-02-19 01:48:25 +01:00
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
if ($form->Fields()->hasTabset()) {
$form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet');
2016-02-19 01:48:25 +01:00
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
}
$this->extend('updateEditForm', $form);
return $form;
}
}