Completed
Push — master ( b1bf62...c2fee6 )
by Damian
01:51
created

code/admin/CommentsGridFieldAction.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_ActionProvider {
4
	/**
5
	 * {@inheritdoc}
6
	 */
7
	public function augmentColumns($gridField, &$columns) {
8
		if(!in_array('Actions', $columns)) {
9
			$columns[] = 'Actions';
10
		}
11
	}
12
13
	/**
14
	 * {@inheritdoc}
15
	 */
16
	public function getColumnAttributes($gridField, $record, $columnName) {
17
		return array('class' => 'col-buttons');
18
	}
19
20
	/**
21
	 * {@inheritdoc}
22
	 */
23
	public function getColumnMetadata($gridField, $columnName) {
24
		if($columnName == 'Actions') {
25
			return array('title' => '');
26
		}
27
	}
28
29
	/**
30
	 * {@inheritdoc}
31
	 */
32
	public function getColumnsHandled($gridField) {
33
		return array('Actions');
34
	}
35
36
	/**
37
	 * {@inheritdoc}
38
	 */
39
	public function getColumnContent($gridField, $record, $columnName) {
40
		if(!$record->canEdit()) return;
41
42
		$field = "";
43
44 View Code Duplication
		if(!$record->IsSpam || !$record->Moderated) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
			$field .= GridField_FormAction::create(
46
				$gridField,
47
				'CustomAction' . $record->ID . 'Spam',
48
				'Spam',
49
				'spam',
50
				array('RecordID' => $record->ID)
51
			)->Field();
52
		}
53
54 View Code Duplication
		if($record->IsSpam || !$record->Moderated) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
			$field .= GridField_FormAction::create(
56
				$gridField,
57
				'CustomAction' . $record->ID . 'Approve',
58
				'Approve',
59
				'approve',
60
				array('RecordID' => $record->ID)
61
			)->Field();
62
		}
63
64
		return $field;
65
	}
66
67
	/**
68
	 * {@inheritdoc}
69
	 */
70
	public function getActions($gridField) {
71
		return array('spam', 'approve');
72
	}
73
74
	/**
75
	 * {@inheritdoc}
76
	 */
77
	public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
78 View Code Duplication
		if($actionName == 'spam') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
			$comment = Comment::get()->byID($arguments["RecordID"]);
80
			$comment->markSpam();
81
82
			// output a success message to the user
83
			Controller::curr()->getResponse()->setStatusCode(
84
				200,
85
				'Comment marked as spam.'
86
			);
87
		}
88
89 View Code Duplication
		if($actionName == 'approve') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
			$comment = Comment::get()->byID($arguments["RecordID"]);
91
			$comment->markApproved();
92
93
			// output a success message to the user
94
			Controller::curr()->getResponse()->setStatusCode(
95
				200,
96
				'Comment approved.'
97
			);
98
		}
99
	}
100
}
101