PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.6
Yatra – Travel Booking & Tour Operator Software v3.0.2.6
3.0.15 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 All 83 releases
yatra / app / Shortcodes / TripShortcode.php

TripShortcode.php in Yatra – Travel Booking & Tour Operator Software 3.0.2.6, at app/Shortcodes/TripShortcode.php

135 lines 4.0 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\Shortcodes;
6
7 /**
8 * Trip Shortcode
9 *
10 * Displays trips with various filtering options using trip-listing-card.php template
11 */
12 class TripShortcode extends BaseShortcode
13 {
14 public function __construct()
15 {
16 parent::__construct('yatra_tour', [
17 'order' => 'asc',
18 'featured' => '0',
19 'per_page' => '10',
20 'category' => '',
21 'destination' => '',
22 'activity' => '',
23 'difficulty' => '',
24 'price_min' => '',
25 'price_max' => '',
26 'duration_min' => '',
27 'duration_max' => '',
28 'search' => '',
29 'columns' => '3',
30 'show_pagination' => 'yes',
31 'title' => 'Our Trips'
32 ]);
33 }
34
35 /**
36 * Register the shortcode
37 */
38 public function register(): void
39 {
40 // Register both shortcode tags
41 add_shortcode('yatra_tour', [$this, 'render']);
42 add_shortcode('yatra_trip', [$this, 'render']);
43 }
44
45 /**
46 * Render the trip shortcode content
47 */
48 protected function renderContent(array $atts): string
49 {
50 // Use the shared BlockDataService method
51 return \Yatra\Services\BlockDataService::renderTrip($atts);
52 }
53
54 /**
55 * Get trips using Yatra's service
56 */
57 public function getTrips(array $atts): array
58 {
59 try {
60 $tripService = new \Yatra\Services\TripService();
61
62 // Get current page from query string or attributes (for AJAX)
63 $current_page = isset($atts['current_page']) ? (int) $atts['current_page'] : (isset($_GET['trip_page']) ? (int) $_GET['trip_page'] : 1);
64 // Use per_page parameter only
65 $per_page = (int) $atts['per_page'];
66 $offset = ($current_page - 1) * $per_page;
67
68 // Start with very basic arguments to ensure we get trips
69 $args = [
70 'limit' => $per_page,
71 'offset' => $offset,
72 'order_by' => 'created_at',
73 'order' => $atts['order'] === 'asc' ? 'ASC' : 'DESC'
74 ];
75
76 // Add featured filter if requested
77 if ($atts['featured'] === '1') {
78 $args['where']['is_featured'] = 1;
79 }
80
81 // Get total count for pagination
82 $count_args = $args;
83 unset($count_args['limit']);
84 unset($count_args['offset']);
85 $total_trips = $tripService->count($count_args);
86
87 // Get trips using the service
88 $trips_data = $tripService->getActiveTrips($args);
89
90
91
92 $trips = [];
93 foreach ($trips_data as $tripData) {
94 // Convert to Trip model
95 $trip = \Yatra\Models\Trip::fromStdClass($tripData);
96
97 // Add basic data needed for the card
98 // Note: bookings_count and reviews will be added later
99 // For now, we'll set default values to ensure basic functionality
100 $trip->bookings_count = 0;
101 $trip->reviews = [];
102
103 $trips[] = $trip;
104 }
105
106 // Calculate pagination data
107 $max_pages = $per_page > 0 ? ceil($total_trips / $per_page) : 1;
108
109 return [
110 'trips' => $trips,
111 'max_pages' => $max_pages,
112 'current_page' => $current_page,
113 'total_found' => $total_trips,
114 'debug_info' => [
115 'args_used' => $args,
116 'raw_count' => count($trips_data)
117 ]
118 ];
119
120 } catch (\Exception $e) {
121 if (defined('WP_DEBUG') && WP_DEBUG) {
122 error_log('Yatra TripShortcode Error: ' . $e->getMessage());
123 }
124
125 return [
126 'trips' => [],
127 'max_pages' => 1,
128 'current_page' => 1,
129 'total_found' => 0
130 ];
131 }
132 }
133
134 }
135