public function onBuildServicesListQuery(mixed &$queryarray $filters) : void

Fires while loading the services to display.


Description

Trigger hook to manipulate at runtime the query used to load the items to display under the Services 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 options to filter the services.

  • id_group - takes only the services assigned to the specified group.

Example

None.


Example

The example below joins the services 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.
 *
 * @return  void
 */
public function onBuildServicesListQuery(&$query, $filters)
{
    $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_service') . ' = ' . $dbo->qn('s.id'));
    // avoid duplicates
    $query->group($dbo->qn('s.id'));
}

Changelog

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