English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Customer  >  Load Details

apply_filters_ref_array( 'vikappointments_load_customer_details', bool $status, mixed &$query, int $id )

Fires while fetching the customer details.


Description

Every time the system needs to access the full details of a customer, the following code is used:

VikAppointments::getCustomer($id);

This methods always triggers an hook that can be used to extend the query to load at runtime further information of the customer, which may be stored in a different database table.

Notice that the query is always limited to 1 element, so it is not suggested to join here tables that may fetch several rows. It is needed to rely on vikappointments_setup_customer_details hook for this purpose.


Parameters

$status

(bool)  True on success, false otherwise.

&$query

(mixed)  Either a query builder object or a string.

$id

(int|null)  The ID of the customer to load. NULL when the system needs to load the details of the currently logged-in user.


Example

/**
 * External plugins can attach to this hook in order to manipulate
 * the query at runtime, in example to include additional properties.
 *
 * @param  boolean  $status  True on success, false otherwise.
 * @param  mixed    &$query  A query builder instance.
 * @param  integer  $id      The ID of the customer.
 */
add_filter('vikappointments_load_customer_details', function($status, &$query, $id)
{
    $dbo = JFactory::getDbo();

    // select some columns
    $query->select($dbo->qn(['tpt.column1', 'tpt.column2']));
    // join services to a third-party table
    $query->leftjoin($dbo->qn('#__myplugin_third_party_table', 'tpt') . ' ON ' . $dbo->qn('tpt.id_customer') . ' = ' . $dbo->qn('c.id'));
    // avoid duplicates
    $query->group($dbo->qn('c.id'));

    return $status;
}, 10, 3);

Changelog

Version Description
1.2 Introduced.
Last Update: 2021-08-05
Helpful?
See Also:

This website uses cookies

This website uses cookies and similar technologies. Some of these technologies are necessary for the proper functioning of the website (Essential). Other technologies are used to evaluate user behavior (Analysis), to integrate external media or for advertising purposes. If you agree, these technologies are activated. For details, please refer to the privacy policy. From this same page you can also update/revoke your consent. If you do not give your consent, only cookies with essential functions will be activated.

We use technologies from the USA on our website. If you give your consent, you therefore consent at the same time to your data being transferred to the USA. We would like to point out that the USA does not have a level of data protection comparable to that of the EU and that any US company can be obliged by state authorities to hand over your data without you having any effective legal protection against this.