Completed
Push — develop ( 363d85...76f199 )
by Zack
04:46
created

GravityView_GF_Entries_List   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 66
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A add_edit_script() 0 18 3
A add_edit_link() 0 17 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 73.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Actions to be performed on the Gravity Forms Entries list screen
5
 */
6
class GravityView_GF_Entries_List {
7
8
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
9
10
		// Add Edit link to the entry actions
11
		add_action( 'gform_entries_first_column_actions', array( $this, 'add_edit_link' ), 10, 5 );
12
13
		// Add script to enable edit link
14
		add_action( 'admin_head-forms_page_gf_entries', array( $this, 'add_edit_script') );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
15
16
	}
17
18
	/**
19
	 * When clicking the edit link, convert the Entries form to go to the edit screen.
20
	 *
21
	 * Gravity Forms requires $_POST['screen_mode'] to be set to get to the "Edit" mode. This enables direct access to the edit mode.
22
	 *
23
	 * @hack
24
	 * @return void
25
	 */
26
	public function add_edit_script() {
27
28
		// We're on a single entry page, or at least not the Entries page.
29
		if( !empty( $_GET['view'] ) && $_GET['view'] !== 'entries' ) { return; }
0 ignored issues
show
introduced by
Found "!== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Space after opening control structure is required
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
30
	?>
31
		<script>
32
		jQuery( document ).ready( function( $ ) {
33
			$('.edit_entry a').click(function(e) {
34
				e.preventDefault();
35
				$( e.target ).parents('form')
36
					.prepend('<input name="screen_mode" type="hidden" value="edit" />')
37
					.attr('action', $(e.target).attr('href') )
38
					.submit();
39
			});
40
		});
41
		</script>
42
	<?php
43
	}
44
45
	/**
46
	 * Add an Edit link to the GF Entry actions row
47
	 * @param int $form_id      ID of the current form
48
	 * @param int $field_id     The ID of the field in the first column, where the row actions are shown
49
	 * @param string $value        The value of the `$field_id` field
50
	 * @param array  $lead         The current entry data
51
	 * @param string $query_string URL query string for a link to the current entry. Missing the `?page=` part, which is strange. Example: `gf_entries&view=entry&id=35&lid=5212&filter=&paged=1`
52
	 */
53
	function add_edit_link( $form_id = NULL, $field_id = NULL, $value = NULL, $lead = array(), $query_string = NULL ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
54
55
		$params = array(
56
			'page' => 'gf_entries',
57
			'view' => 'entry',
58
			'id'	=> (int)$form_id,
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
59
			'lid'	=>	(int)$lead["id"],
0 ignored issues
show
introduced by
Expected 1 space after "=>"; 2 found
Loading history...
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
Coding Style Comprehensibility introduced by
The string literal id does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
60
			'screen_mode'	=> 'edit',
61
		);
62
		?>
63
64
		<span class="edit edit_entry">
65
			|
66
		    <a title="<?php esc_attr_e( 'Edit this entry', 'gravityview'); ?>" href="<?php echo esc_url( add_query_arg( $params, admin_url( 'admin.php?page='.$query_string ) ) ); ?>"><?php esc_html_e( 'Edit', 'gravityview' ); ?></a>
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
67
		</span>
68
		<?php
69
	}
70
71
}
72
73
new GravityView_GF_Entries_List;
74