GravityView  2.1.1
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-field-date-created.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file class-gravityview-field-date-created.php
4  * @package GravityView
5  * @subpackage includes\fields
6  */
7 
9 
10  var $name = 'date_created';
11 
12  var $is_searchable = true;
13 
14  var $search_operators = array( 'less_than', 'greater_than', 'is', 'isnot' );
15 
16  var $group = 'meta';
17 
18  var $contexts = array( 'single', 'multiple', 'export' );
19 
20  var $_custom_merge_tag = 'date_created';
21 
22  /**
23  * GravityView_Field_Date_Created constructor.
24  */
25  public function __construct() {
26 
27  $this->label = esc_html__( 'Date Created', 'gravityview' );
28  $this->default_search_label = $this->label;
29  $this->description = esc_html__( 'The date the entry was created.', 'gravityview' );
30 
31  add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
32 
33  parent::__construct();
34  }
35 
36  function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
37 
38  if( 'edit' === $context ) {
39  return $field_options;
40  }
41 
42  $this->add_field_support('date_display', $field_options );
43 
44  return $field_options;
45  }
46 
47  /**
48  * Filter the value of the field
49  *
50  * @todo Consider how to add to parent class
51  *
52  * @since 1.16
53  *
54  * @param string $output HTML value output
55  * @param array $entry The GF entry array
56  * @param array $field_settings Settings for the particular GV field
57  * @param array $field Current field being displayed
58  *
59  * @return String values for this field based on the numeric values used by Gravity Forms
60  */
61  public function get_content( $output = '', $entry = array(), $field_settings = array(), $field = array() ) {
62 
63  /** Overridden by a template. */
64  if( ! empty( $field['field_path'] ) ) { return $output; }
65 
66  return GVCommon::format_date( $field['value'], 'format=' . \GV\Utils::get( $field_settings, 'date_display' ) );
67  }
68 
69  /**
70  * Add {date_created} merge tag and format the values using format_date
71  *
72  * @since 1.16
73  *
74  * @see https://docs.gravityview.co/article/331-date-created-merge-tag for usage information
75  *
76  * @param array $matches Array of Merge Tag matches found in text by preg_match_all
77  * @param string $text Text to replace
78  * @param array $form Gravity Forms form array
79  * @param array $entry Entry array
80  * @param bool $url_encode Whether to URL-encode output
81  *
82  * @return string Original text if {date_created} isn't found. Otherwise, replaced text.
83  */
84  public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
85 
86  $return = $text;
87 
88  /** Use $this->name instead of date_created because Payment Date uses this as well*/
89  $date_created = \GV\Utils::get( $entry, $this->name );
90 
91  foreach ( $matches as $match ) {
92 
93  $full_tag = $match[0];
94  $property = $match[1];
95 
96  $formatted_date = GravityView_Merge_Tags::format_date( $date_created, $property );
97 
98  $return = str_replace( $full_tag, $formatted_date, $return );
99  }
100 
101  return $return;
102  }
103 
104 }
105 
Modify field settings by extending this class.
__construct()
GravityView_Field_Date_Created constructor.
get_content( $output='', $entry=array(), $field_settings=array(), $field=array())
Filter the value of the field.
$field_settings['content']
Definition: custom.php:27
field_options( $field_options, $template_id, $field_id, $context, $input_type)
get( $key, $default=null)
Retrieve a setting.
replace_merge_tag( $matches=array(), $text='', $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
Add {date_created} merge tag and format the values using format_date.
scale description p description
static format_date( $date_string='', $args=array())
Allow formatting date and time based on GravityView standards.
$field_id
Definition: time.php:17
add_field_support( $key='', &$field_options)
static format_date( $date_created='', $property='')
Format Merge Tags using GVCommon::format_date()
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
$entry
Definition: notes.php:27
$field
Definition: gquiz_grade.php:11