PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.8
Yatra – Travel Booking & Tour Operator Software v3.0.2.8
3.0.16 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 All 84 releases
yatra / app / Core / Handlers / ListingPageHandler.php

ListingPageHandler.php in Yatra – Travel Booking & Tour Operator Software 3.0.2.8, at app/Core/Handlers/ListingPageHandler.php

122 lines 4.7 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\Core\Handlers;
6
7 use Yatra\Core\Assets\ListingAssetManager;
8 use Yatra\Core\Template\TemplateRenderer;
9
10 /**
11 * Listing Page Handler
12 *
13 * Handles listing page requests (destinations, activities, categories)
14 */
15 class ListingPageHandler extends BasePageHandler
16 {
17 /**
18 * Handle listing page request
19 *
20 * @param array $route_data Route data from RouteMatcher
21 * @return bool True if handled successfully
22 */
23 public function handle(array $route_data): bool
24 {
25
26 $listing_type = $route_data['listing_type'];
27 $base = $route_data['base'];
28
29 // Determine template based on listing type
30 $template_map = [
31 'trip' => 'listing-trip',
32 'destination' => 'listing-destination',
33 'activity' => 'listing-activity',
34 'category' => 'listing-trip-category',
35 ];
36
37 if (!isset($template_map[$listing_type])) {
38 $this->logError("Unknown listing type: {$listing_type}");
39 return false;
40 }
41
42 $template = $template_map[$listing_type];
43 $template_path = TemplateRenderer::getTemplatePath($template);
44
45 if (!TemplateRenderer::templateExists($template)) {
46 $this->logError("Listing template not found: {$template}");
47 return false;
48 }
49
50 // Prevent 404 handling
51 $this->prevent404();
52
53 // Set up query vars for backward compatibility
54 $this->setQueryVars([
55 'yatra_page' => $base,
56 ]);
57
58 // Load trip data for trip listing pages
59 if ($listing_type === 'trip') {
60 $tripListingService = new \Yatra\Services\TripListingService();
61
62 // Pagination: route (pretty /trip/page/N/), query var, then ?paged= / ?page=
63 $page = max(1, (int) ($route_data['paged'] ?? (get_query_var('paged') ?: ($_GET['paged'] ?? $_GET['page'] ?? 1))));
64
65 $requestParams = [
66 'page' => $page,
67 'per_page' => \yatra_get_posts_per_page(),
68 's' => isset($_GET['s']) ? (string) wp_unslash($_GET['s']) : '',
69 'destination' => $_GET['destination'] ?? '',
70 'activity' => $_GET['activity'] ?? '',
71 'trip_category' => $_GET['trip_category'] ?? ($_GET['category'] ?? ''),
72 'price_min' => $_GET['price_min'] ?? '',
73 'price_max' => $_GET['price_max'] ?? '',
74 'budget' => $_GET['budget'] ?? '',
75 'duration_min' => $_GET['duration_min'] ?? '',
76 'duration_max' => $_GET['duration_max'] ?? '',
77 'duration' => $_GET['duration'] ?? '',
78 'rating_min' => $_GET['rating_min'] ?? '',
79 'rating' => $_GET['rating'] ?? [],
80 'difficulty' => $_GET['difficulty'] ?? [],
81 'categories' => $_GET['categories'] ?? [],
82 'destinations' => $_GET['destinations'] ?? [],
83 'activities' => $_GET['activities'] ?? [],
84 'trip_type' => $_GET['trip_type'] ?? '',
85 'special_offers' => $_GET['offers'] ?? ($_GET['special_offers'] ?? []),
86 'booking_options' => $_GET['booking'] ?? ($_GET['booking_options'] ?? []),
87 'age_suitability' => $_GET['age'] ?? ($_GET['age_suitability'] ?? []),
88 'accommodation' => $_GET['accommodation'] ?? [],
89 'included_services' => $_GET['services'] ?? ($_GET['included_services'] ?? []),
90 'sort' => $_GET['sort'] ?? '',
91 'attributes' => (isset($_GET['attributes']) && is_array($_GET['attributes'])) ? wp_unslash($_GET['attributes']) : [],
92 ];
93
94 // Get filtered trips
95 $tripData = $tripListingService->getFilteredTrips($requestParams);
96
97 $GLOBALS['yatra_trip_list'] = $tripData;
98 $GLOBALS['yatra_trip_listing_context'] = (new \Yatra\Services\TripListingPageContextFactory())->buildForTripArchive(
99 $tripData,
100 (string) ($_SERVER['REQUEST_URI'] ?? ''),
101 $GLOBALS['yatra_taxonomy_context'] ?? null,
102 $tripListingService->getFilterData()
103 );
104 }
105
106 // SEO meta, canonical, and JSON-LD are handled by {@see \Yatra\Managers\SEOManager} + {@see \Yatra\Services\SEOService}.
107
108 // Create asset manager and render template
109 $asset_manager = new ListingAssetManager($listing_type);
110
111 if (!TemplateRenderer::render($template_path, [], $asset_manager)) {
112 $this->logError("Failed to render listing template for type: {$listing_type}");
113 return false;
114 }
115
116 $this->exit();
117
118 return true;
119 }
120
121 }
122