GravityView  2.17
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  * @since 1.17
7  * @license GPL2
8  * @author GravityView <[email protected]>
9  * @link https://gravityview.co
10  * @copyright Copyright 2016, Katz Web Services, Inc.
11  *
12  * @package GravityView
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', 'gk-gravityview' ),
55  'type' => 'quiz_score',
56  'desc' => __( 'Displays the number of correct Quiz answers the user submitted.', 'gk-gravityview' ),
57  'icon' => 'dashicons-forms',
58  );
59  $fields['gquiz_percent'] = array(
60  'label' => __( 'Quiz Percentage Grade', 'gk-gravityview' ),
61  'type' => 'quiz_percent',
62  'desc' => __( 'Displays the percentage of correct Quiz answers the user submitted.', 'gk-gravityview' ),
63  'icon' => 'dashicons-forms',
64  );
65  $fields['gquiz_grade'] = array(
66  /* 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. */
67  'label' => __( 'Quiz Letter Grade', 'gk-gravityview' ),
68  'type' => 'quiz_grade',
69  'desc' => __( 'Displays the Grade the user achieved based on Letter Grading configured in the Quiz Settings.', 'gk-gravityview' ),
70  'icon' => 'dashicons-forms',
71  );
72  $fields['gquiz_is_pass'] = array(
73  'label' => __( 'Quiz Pass/Fail', 'gk-gravityview' ),
74  'type' => 'quiz_is_pass',
75  'desc' => __( 'Displays either Passed or Failed based on the Pass/Fail settings configured in the Quiz Settings.', 'gk-gravityview' ),
76  'icon' => 'dashicons-forms',
77  );
78 
79  }
80 
81  return $fields;
82  }
83 }
84 
if(gravityview() ->plugin->is_GF_25()) $form
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...