PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.2
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.2
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-customer-name.php

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

407 lines 10.7 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_Customer_Name' ) ) :
7
8 final class WPSC_DF_Customer_Name {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'df_customer_name';
16
17 /**
18 * Set whether this custom field type is of type date
19 *
20 * @var boolean
21 */
22 public static $is_date = false;
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 field type is system default (no fields can be created from it).
33 *
34 * @var boolean
35 */
36 public static $is_default = true;
37
38 /**
39 * Set whether this field type has extra information that can be used in ticket form, edit custom fields, etc.
40 *
41 * @var boolean
42 */
43 public static $has_extra_info = true;
44
45 /**
46 * Set whether this custom field type can accept personal info.
47 *
48 * @var boolean
49 */
50 public static $has_personal_info = true;
51
52 /**
53 * Set whether this custom field type has multiple values
54 *
55 * @var boolean
56 */
57 public static $has_multiple_val = false;
58
59 /**
60 * Set whether this custom field type has reference to other class
61 *
62 * @var boolean
63 */
64 public static $has_ref = false;
65
66 /**
67 * 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.
68 *
69 * @var string
70 */
71 public static $ref_class = '';
72
73 /**
74 * Data type for column created in customer table
75 *
76 * @var string
77 */
78 public static $data_type = 'VARCHAR(200) NOT NULL';
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 = true;
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 = false;
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 available for ticket list sorting
117 *
118 * @var boolean
119 */
120 public static $is_sort = true;
121
122 /**
123 * Set whether fields created from this custom field type can be auto-filled
124 *
125 * @var boolean
126 */
127 public static $is_auto_fill = false;
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 = true;
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 // TFF!
168 add_action( 'wpsc_js_validate_ticket_form', array( __CLASS__, 'js_validate_ticket_form' ) );
169
170 // Set custom field type.
171 add_filter( 'wpsc_default_cf_types', array( __CLASS__, 'default_cf_types' ), 4 );
172 }
173
174 /**
175 * Load current class to reference classes
176 *
177 * @param array $classes - Associative array of class names indexed by its slug.
178 * @return array
179 */
180 public static function load_ref_class( $classes ) {
181
182 $classes[ self::$slug ] = array(
183 'class' => __CLASS__,
184 'save-key' => 'id',
185 );
186 return $classes;
187 }
188
189 /**
190 * Add default custom field type to list
191 *
192 * @param array $default_cf_types - default custom field types array.
193 * @return array
194 */
195 public static function default_cf_types( $default_cf_types ) {
196 $default_cf_types[ self::$slug ] = array(
197 'label' => esc_attr__( 'Customer Name', 'supportcandy' ),
198 'class' => __CLASS__,
199 );
200 return $default_cf_types;
201 }
202
203 /**
204 * Print ticket form field
205 *
206 * @param WPSC_Custom_Field $cf - Custom field object.
207 * @param array $tff - Array of ticket form field settings for this field.
208 * @return string
209 */
210 public static function print_tff( $cf, $tff ) {
211
212 $current_user = WPSC_Current_User::$current_user;
213 ob_start();
214 if ( ! $current_user->is_customer ) {?>
215
216 <div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>">
217 <div class="wpsc-tff-label">
218 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
219 <?php
220 if ( $tff['is-required'] ) {
221 ?>
222 <span class="required-indicator">*</span>
223 <?php
224 }
225 ?>
226 </div>
227 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
228 <input
229 type="text"
230 class="<?php echo esc_attr( $cf->slug ); ?>"
231 name="<?php echo esc_attr( $cf->slug ); ?>"
232 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
233 autocomplete="off"/>
234 </div>
235 <?php
236
237 } else {
238 ?>
239
240 <input
241 type="hidden"
242 class="<?php echo esc_attr( $cf->slug ); ?>"
243 name="<?php echo esc_attr( $cf->slug ); ?>"
244 value="<?php echo esc_attr( $current_user->customer->name ); ?>"/>
245 <?php
246 }
247 return ob_get_clean();
248 }
249
250 /**
251 * Validate this type field in create ticket
252 *
253 * @return void
254 */
255 public static function js_validate_ticket_form() {
256 ?>
257
258 case '<?php echo esc_attr( self::$slug ); ?>':
259 var val = customField.find('input').first().val().trim();
260 if (isRequired && !val) {
261 isValid = false;
262 }
263 break;
264 <?php
265 echo PHP_EOL;
266 }
267
268 /**
269 * Return custom field value in $_POST
270 * Ignore phpcs nonce issue as we already checked where it is called from.
271 *
272 * @param string $slug - Custom field slug.
273 * @param mixed $cf - Custom field object or false.
274 * @return mixed
275 */
276 public static function get_tff_value( $slug, $cf = false ) {
277
278 return isset( $_POST[ $slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $slug ] ) ) : ''; // phpcs:ignore
279 }
280
281 /**
282 * Return slug string to be used in where condition of ticket model for this type of field
283 *
284 * @param WPSC_Custom_Field $cf - custom field object.
285 * @return string
286 */
287 public static function get_sql_slug( $cf ) {
288
289 return 'c.' . $cf->slug;
290 }
291
292 /**
293 * Print edit custom field properties
294 *
295 * @param WPSC_Custom_Fields $cf - custom field object.
296 * @param string $field_class - class name of field category.
297 * @return void
298 */
299 public static function get_edit_custom_field_properties( $cf, $field_class ) {
300
301 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
302 ?>
303 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
304 <div class="label-container">
305 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
306 </div>
307 <input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" />
308 </div>
309 <?php
310 endif;
311
312 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) :
313 ?>
314 <div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text">
315 <div class="label-container">
316 <label for="">
317 <?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?>
318 </label>
319 </div>
320 <input type="text" name="placeholder_text" value="<?php echo esc_attr( $cf->placeholder_text ); ?>" autocomplete="off">
321 </div>
322 <?php
323 endif;
324
325 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
326 ?>
327 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
328 <div class="label-container">
329 <label for="">
330 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
331 </label>
332 </div>
333 <input type="number" name="tl_width" value="<?php echo esc_attr( intval( $cf->tl_width ) ); ?>" autocomplete="off">
334 </div>
335 <?php
336 endif;
337 }
338
339 /**
340 * Set custom field properties. Can be used by add/edit custom field.
341 * Ignore phpcs nonce issue as we already checked where it is called from.
342 *
343 * @param WPSC_Custom_Field $cf - custom field object.
344 * @param string $field_class - class of field category.
345 * @return void
346 */
347 public static function set_cf_properties( $cf, $field_class ) {
348
349 // extra info.
350 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) {
351 $cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore
352 }
353
354 // placeholder!
355 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) {
356 $cf->placeholder_text = isset( $_POST['placeholder_text'] ) ? sanitize_text_field( wp_unslash( $_POST['placeholder_text'] ) ) : ''; // phpcs:ignore
357 }
358
359 // tl_width!
360 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) {
361 $tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore
362 $cf->tl_width = $tl_width ? $tl_width : 100;
363 }
364
365 // save!
366 $cf->save();
367 }
368
369 /**
370 * Return orderby string
371 *
372 * @param WPSC_Custom_Field $cf - custom field object.
373 * @return string
374 */
375 public static function get_orderby_string( $cf ) {
376
377 return 'c.' . $cf->slug;
378 }
379
380 /**
381 * Returns printable customer value for custom field. Can be used in export tickets, replace macros etc.
382 *
383 * @param WPSC_Custom_Field $cf - custom field object.
384 * @param WPSC_Customer $customer - customer object.
385 * @return string
386 */
387 public static function get_customer_field_val( $cf, $customer ) {
388
389 return $customer->name;
390 }
391
392 /**
393 * Print customer value for given custom field on ticket list
394 *
395 * @param WPSC_Custom_Field $cf - custom field object.
396 * @param WPSC_Customer $customer - customer object.
397 * @return void
398 */
399 public static function print_tl_customer_field_val( $cf, $customer ) {
400
401 echo esc_attr( self::get_customer_field_val( $cf, $customer ) );
402 }
403 }
404 endif;
405
406 WPSC_DF_Customer_Name::init();
407