| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_DF_Date_Closed' ) ) : |
| 7 |
|
| 8 |
final class WPSC_DF_Date_Closed { |
| 9 |
|
| 10 |
/** |
| 11 |
* Slug for this custom field type |
| 12 |
* |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
public static $slug = 'df_date_closed'; |
| 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 NULL DEFAULT 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 |
|
| 168 |
/** |
| 169 |
* Load current class to reference classes |
| 170 |
* |
| 171 |
* @param array $classes - Associative array of class names indexed by its slug. |
| 172 |
* @return array |
| 173 |
*/ |
| 174 |
public static function load_ref_class( $classes ) { |
| 175 |
|
| 176 |
$classes[ self::$slug ] = array( |
| 177 |
'class' => __CLASS__, |
| 178 |
'save-key' => 'id', |
| 179 |
); |
| 180 |
return $classes; |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Print operators for ticket form filter |
| 185 |
* |
| 186 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 187 |
* @param array $filter - Existing filters (if any). |
| 188 |
* @return void |
| 189 |
*/ |
| 190 |
public static function get_operators( $cf, $filter = array() ) { |
| 191 |
?> |
| 192 |
|
| 193 |
<div class="item conditional"> |
| 194 |
<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' ) ); ?>');"> |
| 195 |
<option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option> |
| 196 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option> |
| 197 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '<' ); ?> value="<"><?php esc_attr_e( 'Less than', 'supportcandy' ); ?></option> |
| 198 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '<=' ); ?> value="<="><?php esc_attr_e( 'Less than or equals', 'supportcandy' ); ?></option> |
| 199 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '>' ); ?> value=">"><?php esc_attr_e( 'Greater than', 'supportcandy' ); ?></option> |
| 200 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '>=' ); ?> value=">="><?php esc_attr_e( 'Greater than or equals', 'supportcandy' ); ?></option> |
| 201 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'BETWEEN' ); ?> value="BETWEEN"><?php esc_attr_e( 'Between', 'supportcandy' ); ?></option> |
| 202 |
</select> |
| 203 |
</div> |
| 204 |
<?php |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Print operators for ticket form filter |
| 209 |
* |
| 210 |
* @param string $operator - condition operator on which operands should be returned. |
| 211 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 212 |
* @param array $filter - Exising functions (if any). |
| 213 |
* @return void |
| 214 |
*/ |
| 215 |
public static function get_operands( $operator, $cf, $filter = array() ) { |
| 216 |
|
| 217 |
$unique_id = uniqid( 'wpsc_' ); |
| 218 |
$is_between = $operator == 'BETWEEN' ? true : false; |
| 219 |
$operand_val_1 = isset( $filter['operand_val_1'] ) ? $filter['operand_val_1'] : ''; |
| 220 |
$operand_val_2 = isset( $filter['operand_val_2'] ) ? $filter['operand_val_2'] : ''; |
| 221 |
?> |
| 222 |
|
| 223 |
<div class="item conditional operand <?php echo ! $is_between ? 'single' : ''; ?>"> |
| 224 |
<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 ); ?>"> |
| 225 |
</div> |
| 226 |
<script> |
| 227 |
jQuery('.operand_val_1.<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 228 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 229 |
}); |
| 230 |
</script> |
| 231 |
<?php |
| 232 |
|
| 233 |
if ( $is_between ) { |
| 234 |
?> |
| 235 |
<div class="item conditional operand"> |
| 236 |
<input type="text" class="operand_val_2 <?php echo esc_attr( $unique_id ); ?>" placeholder="<?php esc_attr_e( 'To date', 'supportcandy' ); ?>" value=""> |
| 237 |
</div> |
| 238 |
<script> |
| 239 |
jQuery('.operand_val_1.<?php echo esc_attr( $unique_id ); ?>').change(function() { |
| 240 |
var fromDate = jQuery(this).val().trim(); |
| 241 |
jQuery('.operand_val_2.<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 242 |
minDate: fromDate, |
| 243 |
defaultDate: fromDate, |
| 244 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 245 |
}); |
| 246 |
}); |
| 247 |
<?php |
| 248 |
if ( $operand_val_2 ) { |
| 249 |
?> |
| 250 |
jQuery('.operand_val_2.<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 251 |
minDate: '<?php echo esc_attr( $operand_val_1 ); ?>', |
| 252 |
defaultDate: '<?php echo esc_attr( $operand_val_2 ); ?>', |
| 253 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 254 |
}); |
| 255 |
<?php |
| 256 |
} |
| 257 |
?> |
| 258 |
</script> |
| 259 |
<?php |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* Parse filter and return sql query to be merged in ticket model query builder |
| 265 |
* |
| 266 |
* @param WPSC_Custom_Field $cf - custom field of this type. |
| 267 |
* @param mixed $compare - comparison operator. |
| 268 |
* @param mixed $val - value to compare. |
| 269 |
* @return string |
| 270 |
*/ |
| 271 |
public static function parse_filter( $cf, $compare, $val ) { |
| 272 |
|
| 273 |
$str = ''; |
| 274 |
|
| 275 |
switch ( $compare ) { |
| 276 |
|
| 277 |
case '=': |
| 278 |
$from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' ); |
| 279 |
$to = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' ); |
| 280 |
$str = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\''; |
| 281 |
break; |
| 282 |
|
| 283 |
case '<': |
| 284 |
$from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' ); |
| 285 |
$str = 't.' . $cf->slug . $compare . '\'' . esc_sql( $from ) . '\''; |
| 286 |
break; |
| 287 |
|
| 288 |
case '>': |
| 289 |
$to = WPSC_Functions::get_utc_date_str( esc_sql( $val ) . ' 23:59:59' ); |
| 290 |
$str = 't.' . $cf->slug . $compare . '\'' . esc_sql( $to ) . '\''; |
| 291 |
break; |
| 292 |
|
| 293 |
case '<=': |
| 294 |
$from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' ); |
| 295 |
$to = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' ); |
| 296 |
$arr = array( |
| 297 |
't.' . $cf->slug . $compare . '\'' . esc_sql( $from ) . '\'', |
| 298 |
't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'', |
| 299 |
); |
| 300 |
$str = '(' . implode( ' OR ', $arr ) . ')'; |
| 301 |
break; |
| 302 |
|
| 303 |
case '>=': |
| 304 |
$from = WPSC_Functions::get_utc_date_str( esc_sql( $val ) . ' 00:00:00' ); |
| 305 |
$to = WPSC_Functions::get_utc_date_str( esc_sql( $val ) . ' 23:59:59' ); |
| 306 |
$arr = array( |
| 307 |
't.' . $cf->slug . $compare . '\'' . esc_sql( $to ) . '\'', |
| 308 |
't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'', |
| 309 |
); |
| 310 |
$str = '(' . implode( ' OR ', $arr ) . ')'; |
| 311 |
break; |
| 312 |
|
| 313 |
case 'BETWEEN': |
| 314 |
$from = $val['operand_val_1']; |
| 315 |
$to = $val['operand_val_2']; |
| 316 |
if ( preg_match( '/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/', $from ) ) { |
| 317 |
$from = WPSC_Functions::get_utc_date_str( $val['operand_val_1'] ); |
| 318 |
$to = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] ); |
| 319 |
} else { |
| 320 |
$from = WPSC_Functions::get_utc_date_str( $val['operand_val_1'] . ' 00:00:00' ); |
| 321 |
$to = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] . ' 23:59:59' ); |
| 322 |
} |
| 323 |
$str = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\''; |
| 324 |
break; |
| 325 |
|
| 326 |
default: |
| 327 |
$str = '1=1'; |
| 328 |
} |
| 329 |
|
| 330 |
return $str; |
| 331 |
} |
| 332 |
|
| 333 |
/** |
| 334 |
* Return orderby string |
| 335 |
* |
| 336 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 337 |
* @return string |
| 338 |
*/ |
| 339 |
public static function get_orderby_string( $cf ) { |
| 340 |
|
| 341 |
return 't.' . $cf->slug; |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* Check ticket condition |
| 346 |
* |
| 347 |
* @param array $condition - array with condition data. |
| 348 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 349 |
* @param WPSC_Ticket $ticket - ticket object. |
| 350 |
* @return boolean |
| 351 |
*/ |
| 352 |
public static function is_valid_ticket_condition( $condition, $cf, $ticket ) { |
| 353 |
|
| 354 |
$flag = true; |
| 355 |
$date = $ticket->{$cf->slug}; |
| 356 |
if ( ! is_object( $date ) ) { |
| 357 |
return false; |
| 358 |
} |
| 359 |
|
| 360 |
$date->setTimezone( wp_timezone() ); |
| 361 |
|
| 362 |
switch ( $condition['operator'] ) { |
| 363 |
|
| 364 |
case '=': |
| 365 |
$flag = $date->format( 'Y-m-d' ) == $condition['operand_val_1'] ? true : false; |
| 366 |
break; |
| 367 |
|
| 368 |
case '<': |
| 369 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 370 |
$flag = $operand < $date ? true : false; |
| 371 |
break; |
| 372 |
|
| 373 |
case '>': |
| 374 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 375 |
$flag = $operand > $date ? true : false; |
| 376 |
break; |
| 377 |
|
| 378 |
case '<=': |
| 379 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 380 |
$flag = $operand <= $date ? true : false; |
| 381 |
break; |
| 382 |
|
| 383 |
case '>=': |
| 384 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 385 |
$flag = $operand >= $date ? true : false; |
| 386 |
break; |
| 387 |
|
| 388 |
case 'BETWEEN': |
| 389 |
$operand1 = new DateTime( $condition['operand_val_1'] ); |
| 390 |
$operand2 = new DateTime( $condition['operand_val_2'] ); |
| 391 |
$flag = $operand1 <= $date && $operand2 >= $date ? true : false; |
| 392 |
break; |
| 393 |
|
| 394 |
default: |
| 395 |
$flag = true; |
| 396 |
} |
| 397 |
|
| 398 |
return $flag; |
| 399 |
} |
| 400 |
|
| 401 |
/** |
| 402 |
* Return default value for custom field of this type |
| 403 |
* |
| 404 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 405 |
* @return mixed |
| 406 |
*/ |
| 407 |
public static function get_default_value( $cf ) { |
| 408 |
|
| 409 |
return ''; |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* Return val field for meta query of this type of custom field |
| 414 |
* |
| 415 |
* @param array $condition - condition data. |
| 416 |
* @return mixed |
| 417 |
*/ |
| 418 |
public static function get_meta_value( $condition ) { |
| 419 |
|
| 420 |
$operator = $condition['operator']; |
| 421 |
switch ( $operator ) { |
| 422 |
|
| 423 |
case '=': |
| 424 |
case '<': |
| 425 |
case '<=': |
| 426 |
case '>': |
| 427 |
case '>=': |
| 428 |
return $condition['operand_val_1']; |
| 429 |
|
| 430 |
case 'BETWEEN': |
| 431 |
if ( |
| 432 |
! ( isset( $condition['operand_val_1'] ) && preg_match( '/^(\d{4})-\d{2}-(\d{2})$/', $condition['operand_val_1'] ) ) || |
| 433 |
! ( isset( $condition['operand_val_2'] ) && preg_match( '/^(\d{4})-\d{2}-(\d{2})$/', $condition['operand_val_2'] ) ) |
| 434 |
) { |
| 435 |
return false; |
| 436 |
} |
| 437 |
|
| 438 |
return array( |
| 439 |
'operand_val_1' => $condition['operand_val_1'], |
| 440 |
'operand_val_2' => $condition['operand_val_2'], |
| 441 |
); |
| 442 |
} |
| 443 |
return false; |
| 444 |
} |
| 445 |
|
| 446 |
/** |
| 447 |
* Print edit custom field properties |
| 448 |
* |
| 449 |
* @param WPSC_Custom_Fields $cf - custom field object. |
| 450 |
* @param string $field_class - class name of field category. |
| 451 |
* @return void |
| 452 |
*/ |
| 453 |
public static function get_edit_custom_field_properties( $cf, $field_class ) { |
| 454 |
?> |
| 455 |
|
| 456 |
<div data-type="date-format" data-required="false" class="wpsc-input-group date-format"> |
| 457 |
<div class="label-container"> |
| 458 |
<label for=""><?php esc_attr_e( 'Display as', 'supportcandy' ); ?></label> |
| 459 |
</div> |
| 460 |
<select name="date_display_as"> |
| 461 |
<option <?php selected( $cf->date_display_as, 'date' ); ?> value="date"><?php esc_attr_e( 'Date Format', 'supportcandy' ); ?></option> |
| 462 |
<option <?php selected( $cf->date_display_as, 'diff' ); ?> value="diff"><?php esc_attr_e( 'Date Difference (e.g. 1 hour ago)', 'supportcandy' ); ?></option> |
| 463 |
</select> |
| 464 |
</div> |
| 465 |
|
| 466 |
<div data-type="date-format" data-required="false" class="wpsc-input-group date-format"> |
| 467 |
<div class="label-container"> |
| 468 |
<label for=""><?php esc_attr_e( 'Date format', 'supportcandy' ); ?></label> |
| 469 |
</div> |
| 470 |
<input type="text" name="date_format" value="<?php echo esc_attr( $cf->date_format ); ?>" autocomplete="off" /> |
| 471 |
</div> |
| 472 |
<?php |
| 473 |
|
| 474 |
if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) : |
| 475 |
?> |
| 476 |
<div data-type="number" data-required="false" class="wpsc-input-group tl_width"> |
| 477 |
<div class="label-container"> |
| 478 |
<label for=""> |
| 479 |
<?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?> |
| 480 |
</label> |
| 481 |
</div> |
| 482 |
<input type="number" name="tl_width" value="<?php echo esc_attr( intval( $cf->tl_width ) ); ?>" autocomplete="off"> |
| 483 |
</div> |
| 484 |
<?php |
| 485 |
endif; |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* Set custom field properties. Can be used by add/edit custom field. |
| 490 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 491 |
* |
| 492 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 493 |
* @param string $field_class - class of field category. |
| 494 |
* @return void |
| 495 |
*/ |
| 496 |
public static function set_cf_properties( $cf, $field_class ) { |
| 497 |
|
| 498 |
// date display as. |
| 499 |
$cf->date_display_as = isset( $_POST['date_display_as'] ) ? sanitize_text_field( wp_unslash( $_POST['date_display_as'] ) ) : 'date'; // phpcs:ignore |
| 500 |
|
| 501 |
// date format. |
| 502 |
$cf->date_format = isset( $_POST['date_format'] ) ? sanitize_text_field( wp_unslash( $_POST['date_format'] ) ) : ''; // phpcs:ignore |
| 503 |
|
| 504 |
// tl_width! |
| 505 |
if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) { |
| 506 |
$tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore |
| 507 |
$cf->tl_width = $tl_width ? $tl_width : 100; |
| 508 |
} |
| 509 |
|
| 510 |
// save! |
| 511 |
$cf->save(); |
| 512 |
} |
| 513 |
|
| 514 |
/** |
| 515 |
* Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc. |
| 516 |
* |
| 517 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 518 |
* @param WPSC_Ticket $ticket - ticket object. |
| 519 |
* @param string $module - module name. |
| 520 |
* @return string |
| 521 |
*/ |
| 522 |
public static function get_ticket_field_val( $cf, $ticket, $module = '' ) { |
| 523 |
|
| 524 |
$general_settings = get_option( 'wpsc-gs-general' ); |
| 525 |
$format = $cf->date_format ? $cf->date_format : $general_settings['default-date-format']; |
| 526 |
$date = $ticket->{$cf->slug}; |
| 527 |
$value = is_object( $date ) ? wp_date( $format, $date->setTimezone( wp_timezone() )->getTimestamp() ) : ''; |
| 528 |
|
| 529 |
return apply_filters( 'wpsc_ticket_field_val_date_closed', $value, $cf, $ticket, $module ); |
| 530 |
} |
| 531 |
|
| 532 |
/** |
| 533 |
* Print ticket value for given custom field on ticket list |
| 534 |
* |
| 535 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 536 |
* @param WPSC_Ticket $ticket - ticket object. |
| 537 |
* @return void |
| 538 |
*/ |
| 539 |
public static function print_tl_ticket_field_val( $cf, $ticket ) { |
| 540 |
|
| 541 |
$date = $ticket->{$cf->slug}; |
| 542 |
if ( ! is_object( $date ) ) { |
| 543 |
return; |
| 544 |
} |
| 545 |
|
| 546 |
$now = new DateTime(); |
| 547 |
$date_str = self::get_ticket_field_val( $cf, $ticket ); |
| 548 |
$diff_str = WPSC_Functions::date_interval_highest_unit_ago( $date->diff( $now ) ); |
| 549 |
if ( $cf->date_display_as == 'date' ) { |
| 550 |
?> |
| 551 |
<span title="<?php echo esc_attr( $diff_str ); ?>"><?php echo esc_attr( $date_str ); ?></span> |
| 552 |
<?php |
| 553 |
} else { |
| 554 |
?> |
| 555 |
<span title="<?php echo esc_attr( $date_str ); ?>"><?php echo esc_attr( $diff_str ); ?></span> |
| 556 |
<?php |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
/** |
| 561 |
* Print ticket value for given custom field on widget |
| 562 |
* |
| 563 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 564 |
* @param WPSC_Ticket $ticket - ticket object. |
| 565 |
* @return void |
| 566 |
*/ |
| 567 |
public static function print_widget_ticket_field_val( $cf, $ticket ) { |
| 568 |
|
| 569 |
self::print_tl_ticket_field_val( $cf, $ticket ); |
| 570 |
} |
| 571 |
} |
| 572 |
endif; |
| 573 |
|
| 574 |
WPSC_DF_Date_Closed::init(); |
| 575 |
|