English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  System  >  Visualization  >  Before List Query

apply_filters_ref_array( 'vikappointments_before_list_query_{$page}', bool $status, mixed &$query, JView $view )

Fires before executing the main query of a list page.


Description

This hook is triggered before executing the query used to retrieve a list of records. It is possible to manipulate here the query in order to change its default functionalities, for example by selecting more columns and tables or by adding/removing certain restrictions.

The dynamic portion of the hook name, $page, refers to the name of the page executing the query. This means that, for example, the services page will trigger an hook called vikappointments_before_list_query_services.

IMPORTANT NOTE: not all the pages trigger this hook. Before to start coding a plugin, you should make sure that the query of the page supports that hook, by checking whether the onBeforeListQuery() method is used. This can be done by accessing the page at the path:

/wp-content/plugins/vikappointments/admin/views/{$page}/view.html.php
(back-end pages) 

Parameters

$status

(bool)  True on success, false otherwise.

&$query

(mixed)  Either a query string or a query builder instance.

$page

(JView)  The page instance.


Example

The example below includes within the query the possibility of filtering the appointments by service ID, which it is assumed to be set inside the request.

/**
 * Trigger hook to allow the plugins to manipulate the query used to retrieve
 * a standard list of records.
 *
 * @param  bool   $status  True on success, false otherwise.
 * @param  mixed  &$query  The query string or a query builder object.
 * @param  mixed  $view    The current view instance.
 */
add_filter('vikappointments_before_list_query_reservations', function($status, &$query, $view)
{
    // get service ID from request or from the user state
    $app = JFactory::getApplication();

    $id_service = $app->getUserStateFromRequest(
        // get cache signature to keep the filter set in request
        $view->getPoolName() . '.service',
        // get key of the filter set in request
        'id_service',
        // define a default value when the filter is missing
        0,
        // set the type of the filter
        'uint'
    );

    if ($id_service)
    {
        // extend the query with a new condition
        $query->where($query->qn('r.id_service') . ' = ' . $id_service);
    }

    return $status;
}, 10, 3);

Changelog

Version Description
1.0 Introduced.
Last Update: 2023-12-15
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information