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: