silverstripe-comments/code/admin/CommentAdmin.php

119 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/**
* Comment administration system within the CMS
*
* @package comments
*/
class CommentAdmin extends LeftAndMain implements PermissionProvider {
2013-04-11 14:23:03 +02:00
private static $url_segment = 'comments';
2013-04-11 14:23:03 +02:00
private static $url_rule = '/$Action';
2013-04-11 14:23:03 +02:00
private static $menu_title = 'Comments';
2013-04-11 14:23:03 +02:00
private static $allowed_actions = array(
'approvedmarked',
'deleteall',
'deletemarked',
'hammarked',
'showtable',
'spammarked',
'EditForm',
'unmoderated'
);
public function providePermissions() {
return array(
"CMS_ACCESS_CommentAdmin" => array(
'name' => _t('CommentAdmin.ADMIN_PERMISSION', "Access to 'Comments' section"),
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
)
);
}
/**
* @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);
}
2015-04-13 05:41:18 +02:00
$newComments = Comment::get()->filter('Moderated', 0);
2015-04-17 02:36:15 +02:00
$newGrid = new CommentsGridField(
2015-04-13 05:41:18 +02:00
'NewComments',
2015-04-16 04:40:16 +02:00
_t('CommentsAdmin.NewComments', 'New'),
2015-04-13 05:41:18 +02:00
$newComments,
CommentsGridFieldConfig::create()
2015-04-13 05:41:18 +02:00
);
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
2015-04-17 02:36:15 +02:00
$approvedGrid = new CommentsGridField(
2015-04-13 05:41:18 +02:00
'ApprovedComments',
2015-04-16 04:40:16 +02:00
_t('CommentsAdmin.ApprovedComments', 'Approved'),
2015-04-13 05:41:18 +02:00
$approvedComments,
CommentsGridFieldConfig::create()
);
2015-04-13 05:41:18 +02:00
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
2015-04-17 02:36:15 +02:00
$spamGrid = new CommentsGridField(
2015-04-13 05:41:18 +02:00
'SpamComments',
_t('CommentsAdmin.SpamComments', 'Spam'),
$spamComments,
CommentsGridFieldConfig::create()
);
2015-04-13 05:41:18 +02:00
$newCount = '(' . count($newComments) . ')';
$approvedCount = '(' . count($approvedComments) . ')';
$spamCount = '(' . count($spamComments) . ')';
$fields = new FieldList(
$root = new TabSet(
'Root',
2015-04-16 04:40:16 +02:00
new Tab('NewComments', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount,
2015-04-13 05:41:18 +02:00
$newGrid
),
2015-04-16 04:40:16 +02:00
new Tab('ApprovedComments', _t('CommentAdmin.ApprovedComments', 'Approved') . ' ' . $approvedCount,
2015-04-13 05:41:18 +02:00
$approvedGrid
),
2015-04-13 05:41:18 +02:00
new Tab('SpamComments', _t('CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount,
$spamGrid
)
)
);
2015-04-13 05:41:18 +02:00
$root->setTemplate('CMSTabSet');
$actions = new FieldList();
2015-04-13 05:41:18 +02:00
$form = new Form(
$this,
'EditForm',
$fields,
$actions
);
$form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
2015-04-13 05:41:18 +02:00
if($form->Fields()->hasTabset()) {
$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
}
$this->extend('updateEditForm', $form);
return $form;
}
}