PluginProbe
Yatra – Travel Booking & Tour Operator Software / 2.1.16
Yatra – Travel Booking & Tour Operator Software v2.1.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 2.0.10 All 83 releases
yatra / core / Tour / TourFactory.php

TourFactory.php in Yatra – Travel Booking & Tour Operator Software 2.1.16, at core/Tour/TourFactory.php

79 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yatra\Core\Tour;
4
5 class TourFactory
6 {
7 /**
8 * @param $tour_id : tour ID
9 *
10 * @return RegularTour
11 */
12 public function get_tour($tour_id)
13 {
14 $tour_id = $this->get_tour_id($tour_id);
15
16 if (!$tour_id) {
17 return false;
18 }
19
20 $tour_type = self::get_tour_type($tour_id);
21
22 $class = self::get_tour_classname($tour_id, $tour_type);
23
24 return new $class($tour_id);
25
26 }
27
28
29 public function get_tour_id($tour_id)
30 {
31 if ($tour_id instanceof \WP_Post) {
32 return $tour_id->ID;
33 }
34 return absint($tour_id);
35 }
36
37 public static function get_tour_type($tour_id)
38 {
39 $default = 'regular';
40
41 $tour_type = get_post_meta($tour_id, 'yatra_tour_meta_tour_type', true);
42
43 if ($tour_type == '') {
44
45 return $default;
46 }
47
48 $all_types = yatra_get_tour_types();
49
50 if (isset($all_types[$tour_type])) {
51
52 return $tour_type;
53 }
54 return $default;
55 }
56
57 public static function get_tour_classname($tour_id, $tour_type)
58 {
59 $classname = apply_filters('yatra_tour_class_name', self::get_classname_from_tour_type($tour_type), $tour_type, $tour_id);
60
61 if (!$classname || !class_exists($classname)) {
62
63 $classname = 'Yatra\\Core\\Tour\\RegularTour';
64 }
65
66 return $classname;
67 }
68
69 public static function get_classname_from_tour_type($tour_type)
70 {
71 $namespace = "Yatra\\Core\\Tour\\";
72
73 $tour_type = ucwords(str_replace('_', ' ', $tour_type));
74
75 $tour_type = preg_replace('/\s+/', '', $tour_type) . 'Tour';
76
77 return ($namespace . $tour_type);
78 }
79 }