GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-plugin-hooks-gravityformsquiz.php
Go to the documentation of this file.
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  */
20 
21  /**
22  * @inheritDoc
23  * @since 1.17
24  */
25  protected $constant_name = 'GF_QUIZ_VERSION';
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 
add_form_fields($fields=array(), $form=array(), $include_parent_field=true)
If a form has quiz fields, add the fields to the field picker.
Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles...