GravityView  1.19.4
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  /**
24  * @var int One-time payments are stored by Gravity Forms in the database as `1`
25  */
26  const ONE_TIME_PAYMENT = 1;
27 
28  /**
29  * @var int Subscriptions are stored by Gravity Forms in the database as `2`
30  */
31  const SUBSCRIPTION = 2;
32 
33  /**
34  * GravityView_Field_Transaction_Type constructor.
35  */
36  public function __construct() {
37  $this->label = esc_html__( 'Transaction Type', 'gravityview' );
38  $this->description = esc_html__( 'The type of the order: one-time payment or subscription', 'gravityview' );
39 
40  add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
41 
42  parent::__construct();
43  }
44 
45  /**
46  * Filter the value of the field
47  *
48  * @todo Consider how to add to parent class
49  *
50  * @since 1.16
51  *
52  * @param string $output HTML value output
53  * @param array $entry The GF entry array
54  * @param array $field_settings Settings for the particular GV field
55  * @param array $field Current field being displayed
56  *
57  * @return String values for this field based on the numeric values used by Gravity Forms
58  */
59  public function get_content( $output, $entry = array(), $field_settings = array(), $field = array() ) {
60 
61  /** Overridden by a template. */
62  if( ! empty( $field['field_path'] ) ) { return $output; }
63 
64  return $this->get_string_from_value( $output );
65  }
66 
67  /**
68  * Get the string output based on the numeric value used by Gravity Forms
69  *
70  * @since 1.16
71  *
72  * @param int|string $value Number value for the field
73  *
74  * @return string Based on $value; `1`: "One-Time Payment"; `2`: "Subscription"
75  */
76  private function get_string_from_value( $value ) {
77 
78  switch ( intval( $value ) ) {
79  case self::ONE_TIME_PAYMENT:
80  default:
81  $return = __('One-Time Payment', 'gravityview');
82  break;
83 
84  case self::SUBSCRIPTION:
85  $return = __('Subscription', 'gravityview');
86  break;
87  }
88 
89  return $return;
90  }
91 }
92 
Modify field settings by extending this class.
__construct()
GravityView_Field_Transaction_Type constructor.
$field_settings['content']
Definition: custom.php:27
scale description p description
get_string_from_value($value)
Get the string output based on the numeric value used by Gravity Forms.
get_content($output, $entry=array(), $field_settings=array(), $field=array())
Filter the value of the field.
$entry
Definition: notes.php:27
$field
Definition: gquiz_grade.php:11