conversion.php
1 month ago
customer.php
1 month ago
customfields.php
1 month ago
index.html
1 month ago
locations.php
1 month ago
orderstatus.php
1 month ago
restrictions.php
1 month ago
specialrates.php
1 month ago
statistics.php
1 month ago
subscriptions.php
1 month ago
locations.php
132 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * VikAppointments locations (countries, states and cities) class handler. |
| 16 | * |
| 17 | * @since 1.6 |
| 18 | */ |
| 19 | abstract class VAPLocations |
| 20 | { |
| 21 | /** |
| 22 | * Returns the list of supported countries. |
| 23 | * |
| 24 | * @param mixed $orderby The ordering column or an array with column and direction. |
| 25 | * |
| 26 | * @return array The countries list. |
| 27 | */ |
| 28 | public static function getCountries($orderby = 'id') |
| 29 | { |
| 30 | if (is_scalar($orderby)) |
| 31 | { |
| 32 | $orderby = array($orderby, 'ASC'); |
| 33 | } |
| 34 | |
| 35 | $dbo = JFactory::getDbo(); |
| 36 | |
| 37 | $q = $dbo->getQuery(true) |
| 38 | ->select('*') |
| 39 | ->from($dbo->qn('#__vikappointments_countries')) |
| 40 | ->where($dbo->qn('published') . ' = 1') |
| 41 | ->order($dbo->qn($orderby[0]) . ' ' . $orderby[1]); |
| 42 | |
| 43 | $dbo->setQuery($q); |
| 44 | return $dbo->loadAssocList(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the published country that match the given 2 letters code. |
| 49 | * |
| 50 | * @param string $country_2_code The 2 letters code (ISO 3166). |
| 51 | * |
| 52 | * @return mixed The country details on success, false otherwise. |
| 53 | */ |
| 54 | public static function getCountryFromCode($country_2_code) |
| 55 | { |
| 56 | $dbo = JFactory::getDbo(); |
| 57 | |
| 58 | $q = $dbo->getQuery(true) |
| 59 | ->select('*') |
| 60 | ->from($dbo->qn('#__vikappointments_countries')) |
| 61 | ->where($dbo->qn('published') . ' = 1') |
| 62 | ->where($dbo->qn('country_2_code') . ' = ' . $dbo->q($country_2_code)); |
| 63 | |
| 64 | $dbo->setQuery($q, 0, 1); |
| 65 | return $dbo->loadAssoc() ?? false; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the list of supported states that belong to the given country. |
| 70 | * |
| 71 | * @param integer $id_country The country ID. |
| 72 | * @param mixed $orderby The ordering column or an array with column and direction. |
| 73 | * |
| 74 | * @return array The states list. |
| 75 | */ |
| 76 | public static function getStates($id_country, $orderby = 'id') |
| 77 | { |
| 78 | if (is_scalar($orderby)) |
| 79 | { |
| 80 | $orderby = array($orderby, 'ASC'); |
| 81 | } |
| 82 | |
| 83 | $dbo = JFactory::getDbo(); |
| 84 | |
| 85 | $q = $dbo->getQuery(true) |
| 86 | ->select('*') |
| 87 | ->from($dbo->qn('#__vikappointments_states')) |
| 88 | ->where($dbo->qn('published') . ' = 1') |
| 89 | ->order($dbo->qn($orderby[0]) . ' ' . $orderby[1]); |
| 90 | |
| 91 | if ($id_country) |
| 92 | { |
| 93 | $q->where($dbo->qn('id_country') . ' = ' . (int) $id_country); |
| 94 | } |
| 95 | |
| 96 | $dbo->setQuery($q); |
| 97 | return $dbo->loadAssocList(); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns the list of supported cities that belong to the given state. |
| 102 | * |
| 103 | * @param integer $id_state The state ID. |
| 104 | * @param mixed $orderby The ordering column or an array with column and direction. |
| 105 | * |
| 106 | * @return array The cities list. |
| 107 | */ |
| 108 | public static function getCities($id_state, $orderby = 'id') |
| 109 | { |
| 110 | if (is_scalar($orderby)) |
| 111 | { |
| 112 | $orderby = array($orderby, 'ASC'); |
| 113 | } |
| 114 | |
| 115 | $dbo = JFactory::getDbo(); |
| 116 | |
| 117 | $q = $dbo->getQuery(true) |
| 118 | ->select('*') |
| 119 | ->from($dbo->qn('#__vikappointments_cities')) |
| 120 | ->where($dbo->qn('published') . ' = 1') |
| 121 | ->order($dbo->qn($orderby[0]) . ' ' . $orderby[1]); |
| 122 | |
| 123 | if ($id_state) |
| 124 | { |
| 125 | $q->where($dbo->qn('id_state') . ' = ' . (int) $id_state); |
| 126 | } |
| 127 | |
| 128 | $dbo->setQuery($q); |
| 129 | return $dbo->loadAssocList(); |
| 130 | } |
| 131 | } |
| 132 |