GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-field-transaction-type.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file class-gravityview-field-transaction-type.php
4  * @package GravityView
5  * @subpackage includes\fields
6  * @since 1.16
7  */
8 
10 
11  var $name = 'transaction_type';
12 
13  var $is_searchable = true;
14 
15  var $is_numeric = true;
16 
17  var $search_operators = array( 'is', 'isnot', 'in', 'not in' );
18 
19  var $group = 'pricing';
20 
21  var $_custom_merge_tag = 'transaction_type';
22 
23  var $icon = 'dashicons-cart';
24 
25  /**
26  * @var int One-time payments are stored by Gravity Forms in the database as `1`
27  */
28  const ONE_TIME_PAYMENT = 1;
29 
30  /**
31  * @var int Subscriptions are stored by Gravity Forms in the database as `2`
32  */
33  const SUBSCRIPTION = 2;
34 
35  /**
36  * GravityView_Field_Transaction_Type constructor.
37  */
38  public function __construct() {
39  $this->label = esc_html__( 'Transaction Type', 'gk-gravityview' );
40  $this->description = esc_html__( 'The type of the order: one-time payment or subscription', 'gk-gravityview' );
41 
42  add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
43  add_filter( 'gravityview/field/transaction_type/value', array( $this, 'get_value' ), 10 );
44 
45  parent::__construct();
46  }
47 
48  /**
49  * Filter the value of the field
50  *
51  * @todo Consider how to add to parent class
52  *
53  * @since 1.16
54  *
55  * @param string $output HTML value output
56  * @param array $entry The GF entry array
57  * @param array $field_settings Settings for the particular GV field
58  * @param array $field Current field being displayed
59  *
60  * @return String values for this field based on the numeric values used by Gravity Forms
61  */
62  public function get_content( $output, $entry = array(), $field_settings = array(), $field = array() ) {
63 
64  /** Overridden by a template. */
65  if( ! empty( $field['field_path'] ) ) { return $output; }
66 
67  return $this->get_string_from_value( $output );
68  }
69 
70  /**
71  * Filter the value of the field (future)
72  *
73  * @since 2.0
74  *
75  * @param mixed $value The value in.
76  *
77  * @return mixed The value out.
78  */
79  public function get_value( $value ) {
80  return $this->get_string_from_value( $value );
81  }
82 
83  /**
84  * Get the string output based on the numeric value used by Gravity Forms
85  *
86  * @since 1.16
87  *
88  * @param int|string $value Number value for the field
89  *
90  * @return string Based on $value; `1`: "One-Time Payment"; `2`: "Subscription"
91  */
92  private function get_string_from_value( $value ) {
93 
94  switch ( intval( $value ) ) {
95  case self::ONE_TIME_PAYMENT:
96  default:
97  $return = __('One-Time Payment', 'gk-gravityview');
98  break;
99 
100  case self::SUBSCRIPTION:
101  $return = __('Subscription', 'gk-gravityview');
102  break;
103  }
104 
105  return $return;
106  }
107 }
108 
Modify field settings by extending this class.
__construct()
GravityView_Field_Transaction_Type constructor.
$field_settings['content']
Definition: custom.php:27
get_value( $value)
Filter the value of the field (future)
scale description p description
$entry
Definition: notes.php:27
get_content( $output, $entry=array(), $field_settings=array(), $field=array())
Filter the value of the field.
get_string_from_value( $value)
Get the string output based on the numeric value used by Gravity Forms.