GravityView  2.17
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  var $icon = 'dashicons-calendar-alt';
23 
24  /**
25  * GravityView_Field_Date_Created constructor.
26  */
27  public function __construct() {
28 
29  $this->label = esc_html__( 'Date Created', 'gk-gravityview' );
30  $this->default_search_label = $this->label;
31  $this->description = esc_html__( 'The date the entry was created.', 'gk-gravityview' );
32 
33  add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
34 
35  parent::__construct();
36  }
37 
38  public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) {
39 
40  if( 'edit' === $context ) {
41  return $field_options;
42  }
43 
44  $this->add_field_support('date_display', $field_options );
45 
46  return $field_options;
47  }
48 
49  /**
50  * Filter the value of the field
51  *
52  * @todo Consider how to add to parent class
53  *
54  * @since 1.16
55  *
56  * @param string $output HTML value output
57  * @param array $entry The GF entry array
58  * @param array $field_settings Settings for the particular GV field
59  * @param array $field Current field being displayed
60  *
61  * @return string values for this field based on the numeric values used by Gravity Forms
62  */
63  public function get_content( $output = '', $entry = array(), $field_settings = array(), $field = array() ) {
64 
65  /** Overridden by a template. */
66  if( ! empty( $field['field_path'] ) ) { return $output; }
67 
68  return GVCommon::format_date( $field['value'], 'format=' . \GV\Utils::get( $field_settings, 'date_display' ) );
69  }
70 
71  /**
72  * Add {date_created} merge tag and format the values using format_date
73  *
74  * @since 1.16
75  *
76  * @see https://docs.gravityview.co/article/331-date-created-merge-tag for usage information
77  *
78  * @param array $matches Array of Merge Tag matches found in text by preg_match_all
79  * @param string $text Text to replace
80  * @param array $form Gravity Forms form array
81  * @param array $entry Entry array
82  * @param bool $url_encode Whether to URL-encode output
83  *
84  * @return string Original text if {date_created} isn't found. Otherwise, replaced text.
85  */
86  public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
87 
88  $return = $text;
89 
90  /** Use $this->name instead of date_created because Payment Date uses this as well*/
91  $date_created = \GV\Utils::get( $entry, $this->name );
92 
93  foreach ( $matches as $match ) {
94 
95  $full_tag = $match[0];
96  $property = $match[1];
97 
98  $formatted_date = GravityView_Merge_Tags::format_date( $date_created, $property );
99 
100  $return = str_replace( $full_tag, $formatted_date, $return );
101  }
102 
103  return $return;
104  }
105 
106 }
107 
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
add_field_support( $key, &$field_options)
if(gravityview() ->plugin->is_GF_25()) $form
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_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
static format_date( $date_created='', $property='')
Format Merge Tags using GVCommon::format_date()
if(empty( $created_by)) $form_id
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
$entry
Definition: notes.php:27
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
Definition: time.php:22