GridFieldExportAction   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7
Metric Value
wmc 10
lcom 0
cbo 7
dl 0
loc 101
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumnAttributes() 0 3 1
A getColumnsHandled() 0 3 1
A getActions() 0 3 1
A getColumnContent() 0 22 2
A handleAction() 0 2 1
A augmentColumns() 0 5 2
A getColumnMetadata() 0 5 2
1
<?php
2
/**
3
 * This class is a {@link GridField} component that adds an export action for 
4
 * WorkflowDefinition objects shown in GridFields.
5
 *
6
 * @license BSD License (http://silverstripe.org/bsd-license/)
7
 * @package advancedworkflow
8
 */
9
class GridFieldExportAction implements GridField_ColumnProvider, GridField_ActionProvider {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
	
11
	/**
12
	 * Add a column 'Delete'
13
	 * 
14
	 * @param type $gridField
15
	 * @param array $columns 
16
	 */
17
	public function augmentColumns($gridField, &$columns) {
18
		if(!in_array('Actions', $columns)) {
19
			$columns[] = 'Actions';
20
		}
21
	}
22
	
23
	/**
24
	 * Return any special attributes that will be used for FormField::create_tag()
25
	 *
26
	 * @param GridField $gridField
27
	 * @param DataObject $record
28
	 * @param string $columnName
29
	 * @return array
30
	 */
31
	public function getColumnAttributes($gridField, $record, $columnName) {
32
		return array('class' => 'col-buttons');
33
	}
34
	
35
	/**
36
	 * Add the title 
37
	 * 
38
	 * @param GridField $gridField
39
	 * @param string $columnName
40
	 * @return array
41
	 */
42
	public function getColumnMetadata($gridField, $columnName) {
43
		if($columnName == 'Actions') {
44
			return array('title' => '');
45
		}
46
	}
47
	
48
	/**
49
	 * Which columns are handled by this component
50
	 * 
51
	 * @param type $gridField
52
	 * @return type 
53
	 */
54
	public function getColumnsHandled($gridField) {
55
		return array('Actions');
56
	}
57
	
58
	/**
59
	 * Which GridField actions are this component handling
60
	 *
61
	 * @param GridField $gridField
62
	 * @return array 
63
	 */
64
	public function getActions($gridField) {
65
		return array('exportrecord');
66
	}
67
	
68
	/**
69
	 *
70
	 * @param GridField $gridField
71
	 * @param DataObject $record
72
	 * @param string $columnName
73
	 * @return string - the HTML for the column 
74
	 */
75
	public function getColumnContent($gridField, $record, $columnName) {
76
		// Disable the export icon if current user doesn't have access to view CMS Security settings
77
		if(!Permission::check('CMS_ACCESS_SecurityAdmin')) {
78
			return '';
79
		}
80
		
81
		$field = GridField_FormAction::create($gridField,  'ExportRecord'.$record->ID, false, "exportrecord",
82
				array('RecordID' => $record->ID))
83
			->addExtraClass('gridfield-button-export')
84
			->setAttribute('title', _t('GridAction.Export', "Export"))
85
			->setAttribute('data-icon', 'export')
86
			->setDescription(_t('GridAction.EXPORT_DESCRIPTION','Export'));
87
		
88
		$segment1 = Director::baseURL();
89
		$segment2 = Config::inst()->get('AdvancedWorkflowAdmin', 'url_segment');
90
		$segment3 = $record->getClassName();
91
		$fields = new ArrayData(array(
92
			'Link' => Controller::join_links($segment1, 'admin', $segment2 , $segment3, 'export', $record->ID)
93
		));
94
		
95
		return $field->Field()->renderWith('GridField_ExportAction', $fields);
0 ignored issues
show
Bug introduced by
The method renderWith cannot be called on $field->Field() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
96
	}
97
	
98
	/**
99
	 * Handle the actions and apply any changes to the GridField
100
	 *
101
	 * @param GridField $gridField
102
	 * @param string $actionName
103
	 * @param mixed $arguments
104
	 * @param array $data - form data
105
	 * @return void
106
	 */
107
	public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
108
	}
109
}
110