PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Ajax / DirectAttributeQuery.php

DirectAttributeQuery.php in Yatra – Travel Booking & Tour Operator Software trunk, at app/Ajax/DirectAttributeQuery.php

90 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Ajax;
6
7 use Yatra\Repositories\AttributeRepository;
8
9 /**
10 * Attribute Query AJAX Handler (admin fallback when REST cache shape differs).
11 */
12 class DirectAttributeQuery
13 {
14 private AttributeRepository $attributeRepository;
15
16 public function __construct()
17 {
18 $this->attributeRepository = new AttributeRepository();
19 add_action('wp_ajax_yatra_get_attribute_direct', [$this, 'handle']);
20 }
21
22 /**
23 * Handle AJAX request for attribute data
24 */
25 public function handle(): void
26 {
27 if (!wp_verify_nonce($_POST['nonce'] ?? '', 'yatra_admin_nonce')) {
28 wp_send_json_error(__('Your session has expired. Please refresh the page and try again.', 'yatra'));
29 }
30
31 $attributeId = (int) ($_POST['attribute_id'] ?? 0);
32
33 if ($attributeId <= 0) {
34 wp_send_json_error('Invalid attribute ID');
35 }
36
37 try {
38 $attribute = $this->attributeRepository->find($attributeId);
39
40 if (!$attribute) {
41 wp_send_json_error('Attribute not found');
42 }
43
44 $row = [
45 'id' => (int) $attribute->id,
46 'name' => (string) $attribute->name,
47 'slug' => (string) $attribute->slug,
48 'description' => (string) ($attribute->description ?? ''),
49 'status' => (string) ($attribute->status ?? 'draft'),
50 'icon' => null,
51 'created_at' => $attribute->created_at ?? null,
52 'updated_at' => $attribute->updated_at ?? null,
53 ];
54
55 if (!empty($attribute->icon)) {
56 $iconData = maybe_unserialize($attribute->icon);
57 if (is_array($iconData)) {
58 $row['icon'] = $iconData;
59 } else {
60 $row['icon'] = [
61 'type' => 'icon',
62 'value' => (string) $attribute->icon,
63 ];
64 }
65 }
66
67 if (!empty($attribute->metadata)) {
68 $metadata = json_decode((string) $attribute->metadata, true);
69 if (is_array($metadata)) {
70 $row['field_type'] = $metadata['field_type'] ?? 'text_field';
71 $row['field_options'] = $metadata['field_options'] ?? '';
72 $row['default_value'] = $metadata['default_value'] ?? '';
73 $row['placeholder'] = $metadata['placeholder'] ?? '';
74 $row['required'] = $metadata['required'] ?? false;
75 $row['validation_rules'] = $metadata['validation_rules'] ?? '';
76 $row['display_order'] = isset($metadata['display_order']) ? (int) $metadata['display_order'] : 0;
77 $row['show_on_frontend'] = $metadata['show_on_frontend'] ?? false;
78 $row['show_in_filters'] = $metadata['show_in_filters'] ?? false;
79 $row['filter_type'] = $metadata['filter_type'] ?? 'exact';
80 $row['searchable'] = $metadata['searchable'] ?? false;
81 }
82 }
83
84 wp_send_json_success($row);
85 } catch (\Exception $e) {
86 wp_send_json_error('Database query failed: ' . $e->getMessage());
87 }
88 }
89 }
90