view.html.php
121 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 user profile view. |
| 16 | * |
| 17 | * @since 1.4 |
| 18 | */ |
| 19 | class VikAppointmentsViewuserprofile extends JViewVAP |
| 20 | { |
| 21 | /** |
| 22 | * VikAppointments view display method. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | function display($tpl = null) |
| 27 | { |
| 28 | $app = JFactory::getApplication(); |
| 29 | $user = JFactory::getUser(); |
| 30 | |
| 31 | $this->itemid = $app->input->getInt('Itemid', 0); |
| 32 | |
| 33 | if ($user->guest) |
| 34 | { |
| 35 | // not logged in, back to all orders view |
| 36 | $app->redirect(JRoute::rewrite('index.php?option=com_vikappointments&view=allorders', false)); |
| 37 | exit; |
| 38 | } |
| 39 | |
| 40 | // get customer details |
| 41 | $this->customer = VikAppointments::getCustomer(); |
| 42 | |
| 43 | if (!$this->customer) |
| 44 | { |
| 45 | // create new empty customer object |
| 46 | $this->customer = new stdClass; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Use default country code for country dropdown. |
| 51 | * |
| 52 | * @since 1.6.3 |
| 53 | */ |
| 54 | if (empty($this->customer->country_code)) |
| 55 | { |
| 56 | VAPLoader::import('libraries.customfields.loader'); |
| 57 | // $langtag is NULL to auto-detect the current lang tag; |
| 58 | // $default is FALSE to avoid obtainining a default value (US). |
| 59 | $this->customer->country_code = VAPCustomFieldsLoader::getDefaultCountryCode($langtag = null, $default = false); |
| 60 | } |
| 61 | |
| 62 | // display the template |
| 63 | parent::display($tpl); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Checks whether the specified field should be displayed or not. |
| 68 | * |
| 69 | * @param string $field The field to check. |
| 70 | * |
| 71 | * @return boolean True whether it should be displayed, false otherwise. |
| 72 | * |
| 73 | * @since 1.7 |
| 74 | */ |
| 75 | function shouldDisplayField($field) |
| 76 | { |
| 77 | static $allowed = null; |
| 78 | |
| 79 | if (is_null($allowed)) |
| 80 | { |
| 81 | // define the default list of allowed fields |
| 82 | $allowed = array( |
| 83 | 'avatar' => true, |
| 84 | 'country' => true, |
| 85 | 'state' => true, |
| 86 | 'city' => true, |
| 87 | 'address' => true, |
| 88 | 'address2' => true, |
| 89 | 'zip' => true, |
| 90 | 'company' => true, |
| 91 | 'vatnum' => true, |
| 92 | 'ssn' => true, |
| 93 | 'pec' => true, |
| 94 | ); |
| 95 | |
| 96 | /** |
| 97 | * Trigger hook to toggle the visibility of certain fields. |
| 98 | * In example, by using the code below, the user profile |
| 99 | * won't display the SSN field anymore. |
| 100 | * |
| 101 | * $allowed['ssn'] = false; |
| 102 | * |
| 103 | * The following fields cannot be disabled: name, mail, phone. |
| 104 | * |
| 105 | * Assigning new attributes to the array will have no effect. |
| 106 | * |
| 107 | * @param array &$allowed An array of allowed fields. |
| 108 | * @param object $customer The customer details. |
| 109 | * |
| 110 | * @return void |
| 111 | * |
| 112 | * @since 1.7 |
| 113 | */ |
| 114 | VAPFactory::getEventDispatcher()->trigger('onToggleUserProfileFields', array(&$allowed, $this->customer)); |
| 115 | } |
| 116 | |
| 117 | // check whether the specified field is allowed or not |
| 118 | return !empty($allowed[$field]); |
| 119 | } |
| 120 | } |
| 121 |