1 | <?php |
||
2 | |||
3 | namespace SilverStripe\Comments\Admin; |
||
4 | |||
5 | use SilverStripe\Admin\LeftAndMain; |
||
6 | use SilverStripe\Comments\Model\Comment; |
||
7 | use SilverStripe\Forms\FieldList; |
||
8 | use SilverStripe\Forms\Form; |
||
9 | use SilverStripe\Forms\Tab; |
||
10 | use SilverStripe\Forms\TabSet; |
||
11 | use SilverStripe\Security\Security; |
||
12 | |||
13 | /** |
||
14 | * Comment administration system within the CMS |
||
15 | * |
||
16 | * @package comments |
||
17 | */ |
||
18 | class CommentAdmin extends LeftAndMain |
||
19 | { |
||
20 | private static $url_segment = 'comments'; |
||
21 | |||
22 | private static $url_rule = '/$Action'; |
||
23 | |||
24 | private static $menu_title = 'Comments'; |
||
25 | |||
26 | private static $menu_icon_class = 'font-icon-comment'; |
||
27 | |||
28 | private static $allowed_actions = [ |
||
29 | 'approvedmarked', |
||
30 | 'deleteall', |
||
31 | 'deletemarked', |
||
32 | 'hammarked', |
||
33 | 'showtable', |
||
34 | 'spammarked', |
||
35 | 'EditForm', |
||
36 | 'unmoderated' |
||
37 | ]; |
||
38 | |||
39 | private static $required_permission_codes = 'CMS_ACCESS_CommentAdmin'; |
||
40 | |||
41 | public function providePermissions() |
||
42 | { |
||
43 | return [ |
||
44 | 'CMS_ACCESS_CommentAdmin' => [ |
||
45 | 'name' => _t(__CLASS__ . '.ADMIN_PERMISSION', "Access to 'Comments' section"), |
||
46 | 'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access') |
||
47 | ], |
||
48 | ]; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return Form |
||
53 | */ |
||
54 | public function getEditForm($id = null, $fields = null) |
||
55 | { |
||
56 | if (!$id) { |
||
57 | $id = $this->currentPageID(); |
||
58 | } |
||
59 | |||
60 | $form = parent::getEditForm($id); |
||
61 | $record = $this->getRecord($id); |
||
62 | |||
63 | if ($record && !$record->canView()) { |
||
64 | return Security::permissionFailure($this); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
65 | } |
||
66 | |||
67 | $newComments = Comment::get()->filter('Moderated', 0); |
||
68 | |||
69 | $newGrid = CommentsGridField::create( |
||
70 | 'NewComments', |
||
71 | '', |
||
72 | $newComments, |
||
73 | CommentsGridFieldConfig::create() |
||
74 | ); |
||
75 | |||
76 | $approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0); |
||
77 | |||
78 | $approvedGrid = CommentsGridField::create( |
||
79 | 'ApprovedComments', |
||
80 | '', |
||
81 | $approvedComments, |
||
82 | CommentsGridFieldConfig::create() |
||
83 | ); |
||
84 | |||
85 | $spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1); |
||
86 | |||
87 | $spamGrid = CommentsGridField::create( |
||
88 | 'SpamComments', |
||
89 | '', |
||
90 | $spamComments, |
||
91 | CommentsGridFieldConfig::create() |
||
92 | ); |
||
93 | |||
94 | $fields = FieldList::create( |
||
95 | $root = TabSet::create( |
||
96 | 'Root', |
||
97 | Tab::create( |
||
98 | 'NewComments', |
||
99 | _t( |
||
100 | __CLASS__.'.NewComments', |
||
101 | 'New ({count})', |
||
102 | ['count' => count($newComments)] |
||
103 | ), |
||
104 | $newGrid |
||
105 | ), |
||
106 | Tab::create( |
||
107 | 'ApprovedComments', |
||
108 | _t( |
||
109 | __CLASS__.'.ApprovedComments', |
||
110 | 'Approved ({count})', |
||
111 | ['count' => count($approvedComments)] |
||
112 | ), |
||
113 | $approvedGrid |
||
114 | ), |
||
115 | Tab::create( |
||
116 | 'SpamComments', |
||
117 | _t( |
||
118 | __CLASS__.'.SpamComments', |
||
119 | 'Spam ({count})', |
||
120 | ['count' => count($spamComments)] |
||
121 | ), |
||
122 | $spamGrid |
||
123 | ) |
||
124 | ) |
||
125 | ); |
||
126 | |||
127 | $actions = FieldList::create(); |
||
128 | |||
129 | $form = Form::create( |
||
130 | $this, |
||
131 | 'EditForm', |
||
132 | $fields, |
||
133 | $actions |
||
134 | ); |
||
135 | |||
136 | $form->addExtraClass('cms-edit-form fill-height'); |
||
137 | $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
||
138 | |||
139 | if ($form->Fields()->hasTabset()) { |
||
140 | $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
||
141 | $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); |
||
142 | } |
||
143 | |||
144 | $this->extend('updateEditForm', $form); |
||
145 | |||
146 | return $form; |
||
147 | } |
||
148 | } |
||
149 |