PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.5
Yatra – Travel Booking & Tour Operator Software v3.0.5
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 / AccountPageHandler.php

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

94 lines 2.3 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\Routing\UrlParser;
8 use Yatra\Services\SettingsService;
9
10 /**
11 * Account Page Handler
12 *
13 * Handles account page requests
14 */
15 class AccountPageHandler extends BasePageHandler
16 {
17 /**
18 * Handle account 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 $page = (string) ($route_data['page'] ?? 'dashboard');
26 $base = (string) ($route_data['base'] ?? SettingsService::getAccountBase());
27
28 if (!$this->isValidAccountPage($page)) {
29 return false;
30 }
31
32 $tab = $this->accountPageToReactTab($page);
33 $path = UrlParser::getCleanRequestPath();
34 if ($path !== $base && str_starts_with($path, $base . '/')) {
35 wp_safe_redirect(add_query_arg('tab', $tab, home_url('/' . $base . '/')));
36 exit;
37 }
38
39 $currentTab = isset($_GET['tab']) ? sanitize_key((string) $_GET['tab']) : '';
40 if ($currentTab !== '' && $currentTab !== $tab) {
41 wp_safe_redirect(add_query_arg('tab', $tab));
42 exit;
43 }
44
45 $this->setupPageEnvironment('singular', [
46 'title' => __('My Account', 'yatra'),
47 'post_type' => 'page',
48 'post_name' => $base,
49 ]);
50
51 $this->setQueryVars([
52 'yatra_account_page' => $page,
53 ]);
54
55 $GLOBALS['yatra_loading_react_account_page'] = true;
56
57 return $this->selectTemplate('account-page', null, 'account');
58 }
59
60 /**
61 * @return list<string>
62 */
63 private function validAccountPages(): array
64 {
65 return [
66 'dashboard',
67 'profile',
68 'bookings',
69 'payments',
70 'documents',
71 'saved-trips',
72 'wishlist',
73 'settings',
74 ];
75 }
76
77 private function isValidAccountPage(string $page): bool
78 {
79 return in_array($page, $this->validAccountPages(), true);
80 }
81
82 private function accountPageToReactTab(string $page): string
83 {
84 switch ($page) {
85 case 'wishlist':
86 return 'saved-trips';
87 case 'settings':
88 return 'profile';
89 default:
90 return $page;
91 }
92 }
93 }
94