PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / custom-field-types / class-wpsc-df-date-updated.php

class-wpsc-df-date-updated.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.4, at includes/custom-field-types/class-wpsc-df-date-updated.php

713 lines 23.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_DF_Date_Updated' ) ) :
7
8 final class WPSC_DF_Date_Updated {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'df_date_updated';
16
17 /**
18 * Set whether this custom field type is of type date
19 *
20 * @var boolean
21 */
22 public static $is_date = true;
23
24 /**
25 * Set whether this custom field type has applicable to date range
26 *
27 * @var boolean
28 */
29 public static $has_date_range = false;
30
31 /**
32 * Set whether this custom field type has multiple values
33 *
34 * @var boolean
35 */
36 public static $has_multiple_val = false;
37
38 /**
39 * Data type for column created in tickets table
40 *
41 * @var string
42 */
43 public static $data_type = 'DATETIME NOT NULL';
44
45 /**
46 * Set whether this custom field type has reference to other class
47 *
48 * @var boolean
49 */
50 public static $has_ref = true;
51
52 /**
53 * Reference class for this custom field type so that its value(s) return with object or array of objects automatically. Empty string indicate no reference.
54 *
55 * @var string
56 */
57 public static $ref_class = 'datetime';
58
59 /**
60 * Set whether this custom field field type is system default (no fields can be created from it).
61 *
62 * @var boolean
63 */
64 public static $is_default = true;
65
66 /**
67 * Set whether this field type has extra information that can be used in ticket form, edit custom fields, etc.
68 *
69 * @var boolean
70 */
71 public static $has_extra_info = false;
72
73 /**
74 * Set whether this custom field type can accept personal info.
75 *
76 * @var boolean
77 */
78 public static $has_personal_info = false;
79
80 /**
81 * Set whether fields created from this custom field type is allowed in create ticket form
82 *
83 * @var boolean
84 */
85 public static $is_ctf = false;
86
87 /**
88 * Set whether fields created from this custom field type is allowed in ticket list
89 *
90 * @var boolean
91 */
92 public static $is_list = true;
93
94 /**
95 * Set whether fields created from this custom field type is allowed in ticket filter
96 *
97 * @var boolean
98 */
99 public static $is_filter = true;
100
101 /**
102 * Set whether fields created from this custom field type can be given character limits
103 *
104 * @var boolean
105 */
106 public static $has_char_limit = false;
107
108 /**
109 * Set whether fields created from this custom field type has custom options set in options table
110 *
111 * @var boolean
112 */
113 public static $has_options = false;
114
115 /**
116 * Set whether fields created from this custom field type can be auto-filled
117 *
118 * @var boolean
119 */
120 public static $is_auto_fill = false;
121
122 /**
123 * Set whether fields created from this custom field type can be available for ticket list sorting
124 *
125 * @var boolean
126 */
127 public static $is_sort = true;
128
129 /**
130 * Set whether fields created from this custom field type can have placeholder
131 *
132 * @var boolean
133 */
134 public static $is_placeholder = false;
135
136 /**
137 * Set whether fields created from this custom field type is applicable for visibility conditions in create ticket form
138 *
139 * @var boolean
140 */
141 public static $is_visibility_conditions = false;
142
143 /**
144 * Set whether fields created from this custom field type is applicable for macros
145 *
146 * @var boolean
147 */
148 public static $has_macro = true;
149
150 /**
151 * Set whether fields of this custom field type is applicalbe for search on ticket list page.
152 *
153 * @var boolean
154 */
155 public static $is_search = false;
156
157 /**
158 * Initialize the class
159 *
160 * @return void
161 */
162 public static function init() {
163
164 // Get object of this class.
165 add_filter( 'wpsc_load_ref_classes', array( __CLASS__, 'load_ref_class' ) );
166
167 // ticket form.
168 add_filter( 'wpsc_create_ticket_data', array( __CLASS__, 'set_create_ticket_data' ), 10, 3 );
169
170 // create ticket data for rest api.
171 add_filter( 'wpsc_rest_create_ticket', array( __CLASS__, 'set_rest_ticket_data' ), 10, 3 );
172
173 // Set custom field type.
174 add_filter( 'wpsc_default_cf_types', array( __CLASS__, 'default_cf_types' ), 4 );
175 }
176
177 /**
178 * Load current class to reference classes
179 *
180 * @param array $classes - Associative array of class names indexed by its slug.
181 * @return array
182 */
183 public static function load_ref_class( $classes ) {
184
185 $classes[ self::$slug ] = array(
186 'class' => __CLASS__,
187 'save-key' => 'id',
188 );
189 return $classes;
190 }
191
192 /**
193 * Add default custom field type to list
194 *
195 * @param array $default_cf_types - default custom field types array.
196 * @return array
197 */
198 public static function default_cf_types( $default_cf_types ) {
199 $default_cf_types[ self::$slug ] = array(
200 'label' => esc_attr__( 'Date Updated', 'supportcandy' ),
201 'class' => __CLASS__,
202 );
203 return $default_cf_types;
204 }
205
206 /**
207 * Print operators for ticket form filter
208 *
209 * @param WPSC_Custom_Field $cf - custom field object.
210 * @param array $filter - Existing filters (if any).
211 * @return void
212 */
213 public static function get_operators( $cf, $filter = array() ) {
214 ?>
215
216 <div class="item conditional">
217 <select class="operator" onchange="wpsc_tc_get_operand(this, '<?php echo esc_attr( $cf->slug ); ?>', '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operand' ) ); ?>');">
218 <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
219 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
220 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '<' ); ?> value="<"><?php esc_attr_e( 'Less than', 'supportcandy' ); ?></option>
221 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '<=' ); ?> value="<="><?php esc_attr_e( 'Less than or equals', 'supportcandy' ); ?></option>
222 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '>' ); ?> value=">"><?php esc_attr_e( 'Greater than', 'supportcandy' ); ?></option>
223 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '>=' ); ?> value=">="><?php esc_attr_e( 'Greater than or equals', 'supportcandy' ); ?></option>
224 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'BETWEEN' ); ?> value="BETWEEN"><?php esc_attr_e( 'Between', 'supportcandy' ); ?></option>
225 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'today' ); ?> value="today"><?php esc_attr_e( 'Today', 'supportcandy' ); ?></option>
226 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'yesterday' ); ?> value="yesterday"><?php esc_attr_e( 'Yesterday', 'supportcandy' ); ?></option>
227 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'this-week' ); ?> value="this-week"><?php esc_attr_e( 'This week', 'supportcandy' ); ?></option>
228 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'last-week' ); ?> value="last-week"><?php esc_attr_e( 'Last week', 'supportcandy' ); ?></option>
229 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'last-7-days' ); ?> value="last-7-days"><?php esc_attr_e( 'Last 7 days', 'supportcandy' ); ?></option>
230 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'last-30-days' ); ?> value="last-30-days"><?php esc_attr_e( 'Last 30 days', 'supportcandy' ); ?></option>
231 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'this-month' ); ?> value="this-month"><?php esc_attr_e( 'This month', 'supportcandy' ); ?></option>
232 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'last-month' ); ?> value="last-month"><?php esc_attr_e( 'Last month', 'supportcandy' ); ?></option>
233 </select>
234 </select>
235 </div>
236 <?php
237 }
238
239 /**
240 * Print operators for ticket form filter
241 *
242 * @param string $operator - condition operator on which operands should be returned.
243 * @param WPSC_Custom_Field $cf - custom field object.
244 * @param array $filter - Exising functions (if any).
245 * @return void
246 */
247 public static function get_operands( $operator, $cf, $filter = array() ) {
248
249 $unique_id = uniqid( 'wpsc_' );
250 $is_between = $operator == 'BETWEEN' ? true : false;
251 $operand_val_1 = isset( $filter['operand_val_1'] ) ? $filter['operand_val_1'] : '';
252 $operand_val_2 = isset( $filter['operand_val_2'] ) ? $filter['operand_val_2'] : '';
253
254 $short_filters = array( 'today', 'yesterday', 'this-week', 'last-week', 'last-7-days', 'last-30-days', 'this-month', 'last-month' );
255 if ( in_array( $operator, $short_filters ) ) {
256 $today = ( new DateTime() )->format( 'Y-m-d' );
257 ?>
258 <div class="item conditional operand <?php echo ! $is_between ? 'single' : ''; ?>">
259 <input type="hidden" class="operand_val_1 <?php echo esc_attr( $unique_id ); ?>" value="<?php echo esc_attr( $today ); ?>">
260 </div>
261 <?php
262 } else {
263 ?>
264 <div class="item conditional operand <?php echo ! $is_between ? 'single' : ''; ?>">
265 <input type="text" class="operand_val_1 <?php echo esc_attr( $unique_id ); ?>" placeholder="<?php echo $is_between ? esc_attr__( 'From date', 'supportcandy' ) : ''; ?>" value="<?php echo esc_attr( $operand_val_1 ); ?>">
266 </div>
267 <script>
268 jQuery('.operand_val_1.<?php echo esc_attr( $unique_id ); ?>').flatpickr({
269 locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>",
270 });
271 </script>
272 <?php
273 }
274
275 if ( $is_between ) {
276 ?>
277 <div class="item conditional operand">
278 <input type="text" class="operand_val_2 <?php echo esc_attr( $unique_id ); ?>" placeholder="<?php esc_attr_e( 'To date', 'supportcandy' ); ?>" value="">
279 </div>
280 <script>
281 jQuery('.operand_val_1.<?php echo esc_attr( $unique_id ); ?>').change(function() {
282 var fromDate = jQuery(this).val().trim();
283 jQuery('.operand_val_2.<?php echo esc_attr( $unique_id ); ?>').flatpickr({
284 minDate: fromDate,
285 defaultDate: fromDate,
286 locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>",
287 });
288 });
289 <?php
290 if ( $operand_val_2 ) {
291 ?>
292 jQuery('.operand_val_2.<?php echo esc_attr( $unique_id ); ?>').flatpickr({
293 minDate: '<?php echo esc_attr( $operand_val_1 ); ?>',
294 defaultDate: '<?php echo esc_attr( $operand_val_2 ); ?>',
295 locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>",
296 });
297 <?php
298 }
299 ?>
300 </script>
301 <?php
302 }
303 }
304
305 /**
306 * Parse filter and return sql query to be merged in ticket model query builder
307 *
308 * @param WPSC_Custom_Field $cf - custom field of this type.
309 * @param mixed $compare - comparison operator.
310 * @param mixed $val - value to compare.
311 * @return string
312 */
313 public static function parse_filter( $cf, $compare, $val ) {
314
315 $slug = is_string( $cf->slug ) ? trim( $cf->slug ) : '';
316 if ( $slug === '' || ! preg_match( '/^[a-zA-Z0-9_]+$/', $slug ) ) {
317 return '1=0';
318 }
319 $column = 't.' . $cf->slug;
320
321 switch ( $compare ) {
322
323 case '=':
324 $from = WPSC_Functions::normalize_date( $val, false );
325 $to = WPSC_Functions::normalize_date( $val, true );
326
327 return ( $from && $to )
328 ? WPSC_Functions::sql_between( $column, $from, $to )
329 : '1=0';
330
331 case '<':
332 $from = WPSC_Functions::normalize_date( $val, false );
333 return $from
334 ? "$column < '" . esc_sql( $from ) . "'"
335 : '1=0';
336
337 case '>':
338 $to = WPSC_Functions::normalize_date( $val, true );
339 return $to
340 ? "$column > '" . esc_sql( $to ) . "'"
341 : '1=0';
342
343 case '<=':
344 case '>=':
345 $from = WPSC_Functions::normalize_date( $val, false );
346 $to = WPSC_Functions::normalize_date( $val, true );
347
348 if ( ! $from || ! $to ) {
349 return '1=0';
350 }
351
352 return sprintf(
353 "( %s %s '%s' OR %s )",
354 $column,
355 esc_sql( $compare ),
356 esc_sql( $compare === '<=' ? $from : $to ),
357 WPSC_Functions::sql_between( $column, $from, $to )
358 );
359
360 case 'BETWEEN':
361 if ( ! is_array( $val ) ) {
362 return '1=0';
363 }
364
365 $from = WPSC_Functions::normalize_date( $val['operand_val_1'] ?? '', false );
366 $to = WPSC_Functions::normalize_date( $val['operand_val_2'] ?? '', true );
367
368 return ( $from && $to )
369 ? WPSC_Functions::sql_between( $column, $from, $to )
370 : '1=0';
371
372 /* ---------- Relative Date Filters ---------- */
373
374 case 'today':
375 $dt = new DateTime( 'today' );
376 return WPSC_Functions::sql_between(
377 $column,
378 $dt->format( 'Y-m-d 00:00:00' ),
379 $dt->format( 'Y-m-d 23:59:59' )
380 );
381
382 case 'yesterday':
383 $dt = ( new DateTime( 'today' ) )->modify( '-1 day' );
384 return WPSC_Functions::sql_between(
385 $column,
386 $dt->format( 'Y-m-d 00:00:00' ),
387 $dt->format( 'Y-m-d 23:59:59' )
388 );
389
390 case 'this-week':
391 return WPSC_Functions::sql_between(
392 $column,
393 ( new DateTime( 'monday this week' ) )->format( 'Y-m-d 00:00:00' ),
394 ( new DateTime( 'sunday this week' ) )->format( 'Y-m-d 23:59:59' )
395 );
396
397 case 'last-week':
398 return WPSC_Functions::sql_between(
399 $column,
400 ( new DateTime( 'monday last week' ) )->format( 'Y-m-d 00:00:00' ),
401 ( new DateTime( 'sunday last week' ) )->format( 'Y-m-d 23:59:59' )
402 );
403
404 case 'last-7-days':
405 return WPSC_Functions::sql_between(
406 $column,
407 ( new DateTime( '-7 days' ) )->format( 'Y-m-d 00:00:00' ),
408 ( new DateTime() )->format( 'Y-m-d 23:59:59' )
409 );
410
411 case 'last-30-days':
412 return WPSC_Functions::sql_between(
413 $column,
414 ( new DateTime( '-30 days' ) )->format( 'Y-m-d 00:00:00' ),
415 ( new DateTime() )->format( 'Y-m-d 23:59:59' )
416 );
417
418 case 'this-month':
419 return WPSC_Functions::sql_between(
420 $column,
421 ( new DateTime( 'first day of this month' ) )->format( 'Y-m-d 00:00:00' ),
422 ( new DateTime( 'last day of this month' ) )->format( 'Y-m-d 23:59:59' )
423 );
424
425 case 'last-month':
426 return WPSC_Functions::sql_between(
427 $column,
428 ( new DateTime( 'first day of last month' ) )->format( 'Y-m-d 00:00:00' ),
429 ( new DateTime( 'last day of last month' ) )->format( 'Y-m-d 23:59:59' )
430 );
431 }
432
433 return '1=0';
434 }
435
436 /**
437 * Return orderby string
438 *
439 * @param WPSC_Custom_Field $cf - custom field object.
440 * @return string
441 */
442 public static function get_orderby_string( $cf ) {
443
444 return 't.' . $cf->slug;
445 }
446
447 /**
448 * Check ticket condition
449 *
450 * @param array $condition - array with condition data.
451 * @param WPSC_Custom_Field $cf - custom field object.
452 * @param WPSC_Ticket $ticket - ticket object.
453 * @return boolean
454 */
455 public static function is_valid_ticket_condition( $condition, $cf, $ticket ) {
456
457 $flag = true;
458 $date = $ticket->{$cf->slug};
459 if ( ! is_object( $date ) ) {
460 return false;
461 }
462
463 $date->setTimezone( wp_timezone() );
464
465 switch ( $condition['operator'] ) {
466
467 case '=':
468 $flag = $date->format( 'Y-m-d' ) == $condition['operand_val_1'] ? true : false;
469 break;
470
471 case '<':
472 $operand = new DateTime( $condition['operand_val_1'] );
473 $flag = $operand < $date ? true : false;
474 break;
475
476 case '>':
477 $operand = new DateTime( $condition['operand_val_1'] );
478 $flag = $operand > $date ? true : false;
479 break;
480
481 case '<=':
482 $operand = new DateTime( $condition['operand_val_1'] );
483 $flag = $operand <= $date ? true : false;
484 break;
485
486 case '>=':
487 $operand = new DateTime( $condition['operand_val_1'] );
488 $flag = $operand >= $date ? true : false;
489 break;
490
491 case 'BETWEEN':
492 $operand1 = new DateTime( $condition['operand_val_1'] );
493 $operand2 = new DateTime( $condition['operand_val_2'] );
494 $flag = $operand1 <= $date && $operand2 >= $date ? true : false;
495 break;
496
497 default:
498 $flag = true;
499 }
500
501 return $flag;
502 }
503
504 /**
505 * Return default value for custom field of this type
506 *
507 * @param WPSC_Custom_Field $cf - custom field object.
508 * @return mixed
509 */
510 public static function get_default_value( $cf ) {
511
512 $now = new DateTime();
513 return $now->format( 'Y-m-d H:i:s' );
514 }
515
516 /**
517 * Check and return custom field value for new ticket to be created.
518 * This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields.
519 * Ignore phpcs nonce issue as we already checked where it is called from.
520 *
521 * @param array $data - Array of values to to stored in ticket in an insert function.
522 * @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types.
523 * @param boolean $is_my_profile - Whether it or not it is created from my-profile. This function is used by create ticket as well as my-profile. Due to customer fields handling is done same way, this flag gives apportunity to identify where it being called.
524 * @return array
525 */
526 public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) {
527
528 $data['date_updated'] = self::get_default_value( $custom_fields[ self::$slug ][0] );
529 return $data;
530 }
531
532 /**
533 * Set create ticket data for rest api request
534 *
535 * @param array $data - create ticket data array.
536 * @param WP_REST_Request $request - rest request object.
537 * @param array $custom_fields - custom field objects indexed by unique custom field types.
538 * @return array
539 */
540 public static function set_rest_ticket_data( $data, $request, $custom_fields ) {
541
542 $data['date_updated'] = self::get_default_value( $custom_fields[ self::$slug ][0] );
543 return $data;
544 }
545
546 /**
547 * Return val field for meta query of this type of custom field
548 *
549 * @param array $condition - condition data.
550 * @return mixed
551 */
552 public static function get_meta_value( $condition ) {
553
554 $operator = $condition['operator'];
555 switch ( $operator ) {
556
557 case '=':
558 case '<':
559 case '<=':
560 case '>':
561 case '>=':
562 case 'today':
563 case 'yesterday':
564 case 'this-week':
565 case 'last-week':
566 case 'last-7-days':
567 case 'last-30-days':
568 case 'this-month':
569 case 'last-month':
570 return $condition['operand_val_1'];
571
572 case 'BETWEEN':
573 if (
574 ! ( isset( $condition['operand_val_1'] ) && preg_match( '/^(\d{4})-\d{2}-(\d{2})$/', $condition['operand_val_1'] ) ) ||
575 ! ( isset( $condition['operand_val_2'] ) && preg_match( '/^(\d{4})-\d{2}-(\d{2})$/', $condition['operand_val_2'] ) )
576 ) {
577 return false;
578 }
579
580 return array(
581 'operand_val_1' => $condition['operand_val_1'],
582 'operand_val_2' => $condition['operand_val_2'],
583 );
584 }
585 return false;
586 }
587
588 /**
589 * Return data for this custom field while creating duplicate ticket
590 *
591 * @param WPSC_Custom_Field $cf - custom field object.
592 * @param WPSC_Ticket $ticket - ticket object.
593 * @return mixed
594 */
595 public static function get_duplicate_ticket_data( $cf, $ticket ) {
596
597 return ( new DateTime() )->format( 'Y-m-d H:i:s' );
598 }
599
600 /**
601 * Print edit custom field properties
602 *
603 * @param WPSC_Custom_Fields $cf - custom field object.
604 * @param string $field_class - class name of field category.
605 * @return void
606 */
607 public static function get_edit_custom_field_properties( $cf, $field_class ) {
608 ?>
609
610 <div data-type="date-format" data-required="false" class="wpsc-input-group date-format">
611 <div class="label-container">
612 <label for=""><?php esc_attr_e( 'Display as', 'supportcandy' ); ?></label>
613 </div>
614 <select name="date_display_as">
615 <option <?php selected( $cf->date_display_as, 'date' ); ?> value="date"><?php esc_attr_e( 'Date Format', 'supportcandy' ); ?></option>
616 <option <?php selected( $cf->date_display_as, 'diff' ); ?> value="diff"><?php esc_attr_e( 'Date Difference (e.g. 1 hour ago)', 'supportcandy' ); ?></option>
617 </select>
618 </div>
619
620 <div data-type="date-format" data-required="false" class="wpsc-input-group date-format">
621 <div class="label-container">
622 <label for=""><?php esc_attr_e( 'Date format', 'supportcandy' ); ?></label>
623 </div>
624 <input type="text" name="date_format" value="<?php echo esc_attr( $cf->date_format ); ?>" autocomplete="off" />
625 </div>
626 <?php
627
628 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
629 ?>
630 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
631 <div class="label-container">
632 <label for="">
633 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
634 </label>
635 </div>
636 <input type="number" name="tl_width" value="<?php echo esc_attr( intval( $cf->tl_width ) ); ?>" autocomplete="off">
637 </div>
638 <?php
639 endif;
640 }
641
642 /**
643 * Set custom field properties. Can be used by add/edit custom field.
644 * Ignore phpcs nonce issue as we already checked where it is called from.
645 *
646 * @param WPSC_Custom_Field $cf - custom field object.
647 * @param string $field_class - class of field category.
648 * @return void
649 */
650 public static function set_cf_properties( $cf, $field_class ) {
651
652 // date display as.
653 $cf->date_display_as = isset( $_POST['date_display_as'] ) ? sanitize_text_field( wp_unslash( $_POST['date_display_as'] ) ) : 'date'; // phpcs:ignore
654
655 // date format.
656 $cf->date_format = isset( $_POST['date_format'] ) ? sanitize_text_field( wp_unslash( $_POST['date_format'] ) ) : ''; // phpcs:ignore
657
658 // tl_width!
659 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) {
660 $tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore
661 $cf->tl_width = $tl_width ? $tl_width : 100;
662 }
663
664 // save!
665 $cf->save();
666 }
667
668 /**
669 * Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc.
670 *
671 * @param WPSC_Custom_Field $cf - custom field object.
672 * @param WPSC_Ticket $ticket - ticket object.
673 * @param string $module - module name.
674 * @return string
675 */
676 public static function get_ticket_field_val( $cf, $ticket, $module = '' ) {
677
678 $general_settings = get_option( 'wpsc-gs-general' );
679 $format = $cf->date_format ? $cf->date_format : $general_settings['default-date-format'];
680 $date = $ticket->{$cf->slug};
681 $value = is_object( $date ) ? wp_date( $format, $date->setTimezone( wp_timezone() )->getTimestamp() ) : '';
682
683 return apply_filters( 'wpsc_ticket_field_val_date_updated', $value, $cf, $ticket, $module );
684 }
685
686 /**
687 * Print ticket value for given custom field on ticket list
688 *
689 * @param WPSC_Custom_Field $cf - custom field object.
690 * @param WPSC_Ticket $ticket - ticket object.
691 * @return void
692 */
693 public static function print_tl_ticket_field_val( $cf, $ticket ) {
694
695 $now = new DateTime();
696 $date = $ticket->{$cf->slug};
697 $date_str = self::get_ticket_field_val( $cf, $ticket );
698 $diff_str = WPSC_Functions::date_interval_highest_unit_ago( $date->diff( $now ) );
699 if ( $cf->date_display_as == 'date' ) {
700 ?>
701 <span title="<?php echo esc_attr( $diff_str ); ?>"><?php echo esc_attr( $date_str ); ?></span>
702 <?php
703 } else {
704 ?>
705 <span title="<?php echo esc_attr( $date_str ); ?>"><?php echo esc_attr( $diff_str ); ?></span>
706 <?php
707 }
708 }
709 }
710 endif;
711
712 WPSC_DF_Date_Updated::init();
713