English (United Kingdom)

apply_filters_ref_array( 'vikappointments_build_employees_list_query', bool $status, mixed &$queryarray $filters, array &$options )

Fires while loading the employees to display.


Description

Trigger hook to manipulate at runtime the query used to load the items to display under the Employees List page in the front-end.

Third party plugins can extend the query by applying further conditions or selecting additional data.


Parameters

$status

(bool)  True on success, false otherwise.

&$query

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

$filters

(array)  An array of conditions to filter the employees.

  • employee_group - takes only the employees assigned to the specified group;
  • group - takes only the employees that offer at least a service assigned to the specified group;
  • service - takes only the employees that offer the specified service;
  • price - takes only the employees that offer a service with a price between the specified range (in the format 50:300);
  • country - takes only the employees that work on the specified country;
  • state - takes only the employees that work on the specified state/province;
  • city - takes only the employees that work on the specified city;
  • zip - takes only the employees that work on the specified ZIP code;
  • nearby - takes only the employees that work on within the specified radius, with a center equals to the current position of the user ($filters['base_coord']) and a radius equals to the specified distance ($filters['distance']);
  • id_location - takes only the employees that work on the specified location.

The array might report additional attributes to filter the employees based on their custom fields.

&$options

(array)  An array of query options.

  • start - the query offset to handle the pagination;
  • limit - the maximum number of employees to display per page;
  • ordering - the identifier used to sort the employees.

Example

The example below joins the employees table to a third-party table to access further data.

/**
 * Trigger hook to manipulate the query at runtime. Third party plugins
 * can extend the query by applying further conditions or selecting
 * additional data.
 *
 * @param  boolean  $status    True on success, false otherwise.
 * @param  mixed    &$query    Either a query builder or a query string.
 * @param  array    $filters   An array of filters.
 * @param  array    &$options  An array of options.
 */
add_filter('vikappointments_build_employees_list_query', function($status, &$query, $filters, &$options)
{
    $dbo = JFactory::getDbo();

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

	// ignore list limit and display all the existing employees
    $options['limit'] = null;

    return true;
}, 10, 4);

Changelog

Version Description
1.2 Introduced.
Last Update: 2021-07-30
Helpful?
See Also:
This site uses cookies. By continuing to browse you accept their use. Further information