GravityView  1.19.4
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 $search_operators = array( 'less_than', 'greater_than', 'is', 'isnot' );
13 
14  var $group = 'meta';
15 
16  var $contexts = array( 'single', 'multiple', 'export' );
17 
18  var $_custom_merge_tag = 'date_created';
19 
20  /**
21  * GravityView_Field_Date_Created constructor.
22  */
23  public function __construct() {
24 
25  $this->label = esc_html__( 'Date Created', 'gravityview' );
26  $this->default_search_label = $this->label;
27  $this->description = esc_html__( 'The date the entry was created.', 'gravityview' );
28 
29  add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
30 
31  parent::__construct();
32  }
33 
34  function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
35 
36  if( 'edit' === $context ) {
37  return $field_options;
38  }
39 
40  $this->add_field_support('date_display', $field_options );
41 
42  return $field_options;
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 GVCommon::format_date( $field['value'], 'format='.rgar( $field_settings, 'date_display' ) );
65  }
66 
67  /**
68  * Add {date_created} merge tag and format the values using format_date
69  *
70  * @since 1.16
71  *
72  * @see http://docs.gravityview.co/article/331-date-created-merge-tag for usage information
73  *
74  * @param array $matches Array of Merge Tag matches found in text by preg_match_all
75  * @param string $text Text to replace
76  * @param array $form Gravity Forms form array
77  * @param array $entry Entry array
78  * @param bool $url_encode Whether to URL-encode output
79  *
80  * @return string Original text if {date_created} isn't found. Otherwise, replaced text.
81  */
82  public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
83 
84  $return = $text;
85 
86  /** Use $this->name instead of date_created because Payment Date uses this as well*/
87  $date_created = rgar( $entry, $this->name );
88 
89  foreach ( $matches as $match ) {
90 
91  $full_tag = $match[0];
92  $property = $match[1];
93 
94  $formatted_date = GravityView_Merge_Tags::format_date( $date_created, $property );
95 
96  $return = str_replace( $full_tag, $formatted_date, $return );
97  }
98 
99  return $return;
100  }
101 
102 }
103 
Modify field settings by extending this class.
get_content($output= '', $entry=array(), $field_settings=array(), $field=array())
Filter the value of the field.
__construct()
GravityView_Field_Date_Created constructor.
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.
field_options($field_options, $template_id, $field_id, $context, $input_type)
static format_date($date_string= '', $args=array())
Allow formatting date and time based on GravityView standards.
$field_settings['content']
Definition: custom.php:27
add_field_support($key= '', &$field_options)
scale description p description
$field_id
Definition: time.php:17
$entry
Definition: notes.php:27
static format_date($date_created= '', $property= '')
Format Merge Tags using GVCommon::format_date()
$field
Definition: gquiz_grade.php:11