public function onBuildEmployeesListQuery(mixed &$queryarray $filters, array &$options) : void

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

&$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.

Return Value

None.


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   mixed  &$query    Either a query builder or a query string.
 * @param   array  $filters   An array of filters.
 * @param   array  &$options  An array of options.
 *
 * @return  void
 */
public function onBuildEmployeesListQuery(&$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;
}

Changelog

VersionDescription
1.7 Introduced.
Last Update: 2021-10-10 11:21
Helpful?
See Also: