Completed
Push — develop ( 20c6d6...2cbb28 )
by Zack
04:30
created

GravityView_Plugin_Hooks_Gravity_Forms_Quiz   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 61
rs 10
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add_hooks() 0 5 1
B add_form_fields() 0 32 2
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 19 and the first side effect is on line 81.

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
 * Add Gravity Forms Quiz customizations
4
 *
5
 * @file      class-gravityview-plugin-hooks-gravityformsquiz.php
6
 * @package   GravityView
7
 * @license   GPL2
8
 * @author    Katz Web Services, Inc.
9
 * @link      https://gravityview.co
10
 * @copyright Copyright 2016, Katz Web Services, Inc.
11
 *
12
 * @since 1.17
13
 */
14
15
/**
16
 * @inheritDoc
17
 * @since 1.17
18
 */
19
class GravityView_Plugin_Hooks_Gravity_Forms_Quiz extends GravityView_Plugin_and_Theme_Hooks {
20
21
	/**
22
	 * @inheritDoc
23
	 * @since 1.17
24
	 */
25
	protected $function_name = 'acf';
26
27
	/**
28
	 * @since 1.17
29
	 */
30
	protected function add_hooks() {
31
		parent::add_hooks();
32
33
		add_filter( 'gravityview/common/get_form_fields', array( $this, 'add_form_fields' ), 10, 3 );
34
	}
35
36
	/**
37
	 * If a form has quiz fields, add the fields to the field picker
38
	 *
39
	 * @since 1.17
40
	 *
41
	 * @param array $fields Associative array of fields, with keys as field type
42
	 * @param array $form GF Form array
43
	 * @param bool $include_parent_field Whether to include the parent field when getting a field with inputs
44
	 *
45
	 * @return array $fields with quiz fields added, if exist. Unmodified if form has no quiz fields.
46
	 */
47
	function add_form_fields( $fields = array(), $form = array(), $include_parent_field = true ) {
0 ignored issues
show
Unused Code introduced by
The parameter $include_parent_field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
48
		
49
		$quiz_fields = GFAPI::get_fields_by_type( $form, 'quiz' );
50
		
51
		if( ! empty( $quiz_fields ) ) {
52
			
53
			$fields['gquiz_score']   = array(
54
				'label' => __( 'Quiz Score Total', 'gravityview' ),
55
				'type'  => 'quiz_score',
56
				'desc'  => __( 'Displays the number of correct Quiz answers the user submitted.', 'gravityview' ),
57
			);
58
			$fields['gquiz_percent'] = array(
59
				'label' => __( 'Quiz Percentage Grade', 'gravityview' ),
60
				'type'  => 'quiz_percent',
61
				'desc'  => __( 'Displays the percentage of correct Quiz answers the user submitted.', 'gravityview' ),
62
			);
63
			$fields['gquiz_grade']   = array(
64
				/* translators: This is a field type used by the Gravity Forms Quiz Addon. "A" is 100-90, "B" is 89-80, "C" is 79-70, etc.  */
65
				'label' => __( 'Quiz Letter Grade', 'gravityview' ),
66
				'type'  => 'quiz_grade',
67
				'desc'  => __( 'Displays the Grade the user achieved based on Letter Grading configured in the Quiz Settings.', 'gravityview' ),
68
			);
69
			$fields['gquiz_is_pass'] = array(
70
				'label' => __( 'Quiz Pass/Fail', 'gravityview' ),
71
				'type'  => 'quiz_is_pass',
72
				'desc'  => __( 'Displays either Passed or Failed based on the Pass/Fail settings configured in the Quiz Settings.', 'gravityview' ),
73
			);
74
			
75
		}
76
		
77
		return $fields;
78
	}
79
}
80
81
new GravityView_Plugin_Hooks_Gravity_Forms_Quiz;