PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | admin/helpers/src/state/helper.php +48 -20 1.6.7 → 1.8.16 View file →
@@ -42,9 +42,13 @@
42 42 return $state_2_code;
43 43 }
44 44
45 45 // make sure this province exists
46 - $q = "SELECT * FROM `#__vikbooking_states` WHERE `id_country`=" . $id_country . " AND `state_2_code`=" . $dbo->quote($state_2_code);
46 + $q = $dbo->getQuery(true)
47 + ->select('*')
48 + ->from($dbo->qn('#__vikbooking_states'))
49 + ->where($dbo->qn('id_country') . ' = ' . (int) $id_country)
50 + ->where($dbo->qn('state_2_code') . ' = ' . $dbo->q($state_2_code));
47 51 $dbo->setQuery($q, 0, 1);
48 52 $dbo->execute();
49 53 if (!$dbo->getNumRows()) {
50 54 // no records found
@@ -58,9 +62,9 @@
58 62
59 63 /**
60 64 * Attempts to find the country ID from the given identifier.
61 65 *
62 - * @param string $country country identifier (name or 2/3-char code).
66 + * @param string $country country identifier (id, name or 2/3-char code).
63 67 *
64 68 * @return int country ID found or null.
65 69 */
66 70 public static function getCountryId($country)
@@ -67,18 +71,21 @@
67 71 {
68 72 $dbo = JFactory::getDbo();
69 73
70 74 if (is_numeric($country)) {
71 - $q = "SELECT `id` FROM `#__vikbooking_countries` WHERE `id`=" . (int)$country;
75 + $q = $dbo->getQuery(true)
76 + ->select($dbo->qn('id'))
77 + ->from($dbo->qn('#__vikbooking_countries'))
78 + ->where($dbo->qn('id') . ' = ' . (int) $country);
79 +
72 80 $dbo->setQuery($q, 0, 1);
73 - $dbo->execute();
74 - if (!$dbo->getNumRows()) {
75 - // no records found for this country
76 - return null;
77 - }
81 +
78 82 return $dbo->loadResult();
79 83 }
80 84
85 + // no null values accepted
86 + $country = (string) $country;
87 +
81 88 // find country ID by name or code
82 89 $field_value = $country;
83 90 $field_name = $dbo->qn('country_name');
84 91 if (strlen($country) == 3) {
@@ -86,15 +93,14 @@
86 93 } elseif (strlen($country) == 2) {
87 94 $field_name = $dbo->qn('country_2_code');
88 95 }
89 96
90 - $q = "SELECT `id` FROM `#__vikbooking_countries` WHERE {$field_name}=" . $dbo->quote($field_value);
97 + $q = $dbo->getQuery(true)
98 + ->select($dbo->qn('id'))
99 + ->from($dbo->qn('#__vikbooking_countries'))
100 + ->where($field_name . ' = ' . $dbo->q($field_value));
101 +
91 102 $dbo->setQuery($q, 0, 1);
92 - $dbo->execute();
93 - if (!$dbo->getNumRows()) {
94 - // country not found
95 - return null;
96 - }
97 103
98 104 return $dbo->loadResult();
99 105 }
100 106
@@ -108,15 +114,37 @@
108 114 public static function getCountryStates($id_country)
109 115 {
110 116 $dbo = JFactory::getDbo();
111 117
112 - $q = "SELECT * FROM `#__vikbooking_states` WHERE `id_country`=" . (int)$id_country;
118 + $q = $dbo->getQuery(true)
119 + ->select('*')
120 + ->from($dbo->qn('#__vikbooking_states'))
121 + ->where($dbo->qn('id_country') . ' = ' . (int) $id_country);
122 +
113 123 $dbo->setQuery($q);
114 - $dbo->execute();
115 - if (!$dbo->getNumRows()) {
116 - // no records found for this country
117 - return [];
118 - }
119 124
120 125 return $dbo->loadAssocList();
126 + }
127 +
128 + /**
129 + * Returns the country record from the given ID.
130 + *
131 + * @param int $id_country The country record ID.
132 + *
133 + * @return ?array Associative record or null.
134 + *
135 + * @since 1.17.2 (J) - 1.7.2 (WP)
136 + */
137 + public static function getCountryData($id_country)
138 + {
139 + $dbo = JFactory::getDbo();
140 +
141 + $q = $dbo->getQuery(true)
142 + ->select('*')
143 + ->from($dbo->qn('#__vikbooking_countries'))
144 + ->where($dbo->qn('id') . ' = ' . (int) $id_country);
145 +
146 + $dbo->setQuery($q);
147 +
148 + return $dbo->loadAssoc();
121 149 }
122 150 }