PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / customfields / rules / country.php
vikappointments / site / helpers / libraries / customfields / rules Last commit date
address.php 3 days ago city.php 3 days ago company.php 3 days ago country.php 3 days ago email.php 3 days ago index.html 3 days ago nominative.php 3 days ago pec.php 3 days ago phone.php 3 days ago ssn.php 3 days ago state.php 3 days ago vatnum.php 3 days ago zip.php 3 days ago
country.php
91 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 custom field country rule dispatcher.
16 *
17 * @since 1.7.8
18 */
19 class VAPCustomFieldRuleCountry extends VAPCustomFieldRule
20 {
21 /**
22 * Returns the name of the rule.
23 *
24 * @return string
25 */
26 public function getName()
27 {
28 return JText::translate('VAPMANAGECUSTOMER5');
29 }
30
31 /**
32 * Dispatches the field rule.
33 *
34 * @param mixed $value The value of the field set in request.
35 * @param array &$args The array data to fill-in in case of
36 * specific rules (name, e-mail, etc...).
37 * @param mixed $field The custom field object.
38 *
39 * @return void
40 */
41 public function dispatch($value, &$args, $field)
42 {
43 $db = JFactory::getDbo();
44
45 $query = $db->getQuery(true)
46 ->select($db->qn('country_2_code'))
47 ->from($db->qn('#__vikappointments_countries'))
48 ->where($db->qn('published') . ' = 1')
49 ->andWhere([
50 $db->qn('country_2_code') . ' = ' . $db->q($value),
51 $db->qn('country_name') . ' = ' . $db->q($value),
52 ], 'OR');
53
54 $db->setQuery($query, 0, 1);
55 $countryCode = $db->loadResult();
56
57 // in case of multiple fields with country rule, use only the first specified one
58 if ($countryCode && empty($args['country_code']))
59 {
60 // fill country column with field value
61 $args['country_code'] = $countryCode;
62 }
63 }
64
65 /**
66 * Renders the field rule.
67 *
68 * @param array &$data An array of display data.
69 * @param mixed $field The custom field object.
70 *
71 * @return string The HTML that will be used in place of the layout
72 * defined by the field. Omit this value to keep using
73 * the default HTML of the field.
74 */
75 public function render(&$data, $field)
76 {
77 // in case of select field, auto-fill the options with the supported countries
78 if ($field->get('type') === 'select')
79 {
80 // iterate published countries
81 foreach (VAPLocations::getCountries('country_name') as $country)
82 {
83 // use the country alpha-2 code as option value
84 $data['options'][] = JHtml::fetch('select.option', $country['country_2_code'], $country['country_name']);
85 }
86 }
87
88 return '';
89 }
90 }
91