|
1
|
|
|
<?php |
|
|
|
|
|
|
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 ) { |
|
|
|
|
|
|
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; |
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.