public function onBuildServiceSearchQuery(mixed &$queryarray &$options) : void

Fires while loading the service to display.


Description

Trigger hook to manipulate at runtime the query used to load the service to display under the Service Details 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.

&$options

(array)  An array of options.

  • id_service - the ID of the service to load;
  • id_employee - the ID of the employee assigned to the specified service.

Return Value

None.


Example

The example below auto-unpublishes the service with ID #5 when we currently are in Summer.

/**
 * 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  &$options  An array of options.
 *
 * @return  void
 */
public function onBuildServiceSearchQuery(&$query, &$options)
{
    // check if we are trying to fetch a specific service
    if ($options['id_service'] != 5)
    {
        return;
    }

    // get current month
    $mon = (int) JHtml::_('date', 'now', 'n');

    // check if we are in Summer
    if (in_array($mon, [6, 7, 8]))
    {
        // quick statement to always return no rows
        $query->where(0);
    }
}

Changelog

Version Description
1.7 Introduced.
Last Update: 2022-01-28 16:30
Helpful?
See Also: