PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataAccess / Simple_Form / WPDA_Simple_Form_Item_DateTime.php

WPDA_Simple_Form_Item_DateTime.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.84, at WPDataAccess/Simple_Form/WPDA_Simple_Form_Item_DateTime.php

98 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 *
6 * @package WPDataAccess\Simple_Form
7 */
8
9 namespace WPDataAccess\Simple_Form {
10
11 use WPDataAccess\WPDA;
12
13 /**
14 * Class WPDA_Simple_Form_Item_DateTime
15 *
16 * Adds a date/time picker to fields of type: date, datetime, timestamp and time
17 *
18 * @author Peter Schulz
19 * @since 2.5.1
20 */
21 class WPDA_Simple_Form_Item_DateTime extends WPDA_Simple_Form_Item {
22
23 protected $date_format = 'Y-m-d';
24 protected $time_format = 'H:i';
25
26 protected $date_placeholder = 'yyyy-mm-dd';
27 protected $time_placeholder = 'hh:mi';
28
29 protected $date_picker = 'true';
30 protected $time_picker = 'false';
31
32 /**
33 * WPDA_Simple_Form_Item_DateTime constructor.
34 *
35 * @param array $args
36 */
37 public function __construct( $args = array() ) {
38 parent::__construct( $args );
39
40 // Get date and time formats
41 $this->date_format = WPDA::get_option( WPDA::OPTION_PLUGIN_DATE_FORMAT );
42 $this->time_format = WPDA::get_option( WPDA::OPTION_PLUGIN_TIME_FORMAT );
43
44 // Get date and time placeholders
45 $this->date_placeholder = WPDA::get_option( WPDA::OPTION_PLUGIN_DATE_PLACEHOLDER );
46 $this->time_placeholder = WPDA::get_option( WPDA::OPTION_PLUGIN_TIME_PLACEHOLDER );
47
48 switch ( $this->column_type ) {
49 case 'time':
50 $this->date_format = $this->time_format;
51 $this->date_picker = 'false';
52 $this->time_picker = 'true';
53 $this->item_placeholder = $this->time_placeholder;
54 $db_format = WPDA::DB_TIME_FORMAT;
55 break;
56 case 'date':
57 $this->item_placeholder = $this->date_placeholder;
58 $db_format = WPDA::DB_DATE_FORMAT;
59 break;
60 default:
61 $this->date_format = $this->date_format . ' ' . $this->time_format;
62 $this->time_picker = 'true';
63 $this->item_placeholder = $this->date_placeholder . ' ' . $this->time_placeholder;
64 $db_format = WPDA::DB_DATETIME_FORMAT;
65 }
66
67 if ( null !== $this->item_value && '' !== $this->item_value ) {
68 $convert_date = \DateTime::createFromFormat( $db_format, $this->item_value );
69 $this->item_value = $convert_date->format( $this->date_format );
70 }
71 }
72
73 /**
74 * Overwrite method show_item: add date/time picker
75 */
76 public function show_item() {
77 parent::show_item();
78 ?>
79 <script type='text/javascript'>
80 jQuery(function () {
81 jQuery.datetimepicker.setLocale('<?php echo esc_attr( substr( get_locale(), 0, 2 ) ); ?>');
82 jQuery('#<?php echo esc_attr( $this->item_name ); ?>').datetimepicker({
83 format: '<?php echo $this->date_format; // phpcs:ignore WordPress.Security.EscapeOutput ?>',
84 datepicker: <?php echo $this->date_picker; // phpcs:ignore WordPress.Security.EscapeOutput ?>,
85 timepicker: <?php echo $this->time_picker; // phpcs:ignore WordPress.Security.EscapeOutput ?>,
86 scrollMonth: false,
87 scrollInput: false
88 });
89 jQuery('#<?php echo esc_attr( $this->item_name ); ?>').attr('autocomplete', 'off');
90 });
91 </script>
92 <?php
93 }
94
95 }
96
97 }
98