PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / customfields / rules / phone.php
vikappointments / site / helpers / libraries / customfields / rules Last commit date
address.php 1 month ago city.php 1 month ago company.php 1 month ago country.php 1 month ago email.php 1 month ago index.html 1 month ago nominative.php 1 month ago pec.php 1 month ago phone.php 1 month ago ssn.php 1 month ago state.php 1 month ago vatnum.php 1 month ago zip.php 1 month ago
phone.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 phone number rule dispatcher.
16 *
17 * @since 1.7
18 */
19 class VAPCustomFieldRulePhone 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('VAPCUSTFIELDRULE3');
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 // in case of multiple fields with phone rule, use only
44 // the first specified one
45 if (empty($args['purchaser_phone']))
46 {
47 // fill phone column with field value
48 $args['purchaser_phone'] = $value;
49
50 $input = JFactory::getApplication()->input;
51
52 // get dial code
53 $dial = $input->get($field->getID() . '_dialcode', null, 'string');
54
55 if ($dial)
56 {
57 // register dial code
58 $args['purchaser_prefix'] = $dial;
59 }
60
61 // get country code
62 $country = $input->get($field->getID() . '_country', null, 'string');
63
64 if ($country)
65 {
66 // register country code
67 $args['purchaser_country'] = $country;
68 }
69 }
70 }
71
72 /**
73 * Renders the field rule.
74 *
75 * @param array &$data An array of display data.
76 * @param mixed $field The custom field object.
77 *
78 * @return string The HTML that will be used in place of the layout
79 * defined by the field. Omit this value to keep using
80 * the default HTML of the field.
81 */
82 public function render(&$data, $field)
83 {
84 // use a different layout for fields with phone number rule
85 $field->set('layout', 'tel');
86
87 // inject class name
88 $data['class'] = (empty($data['class']) ? '' : $data['class'] . ' ') . 'phone-field';
89 }
90 }
91