English (United Kingdom)

apply_filters_ref_array( 'vikrestaurants_before_build_map', bool $status, array &$data )

Fires before displaying the tables map.


Description

Trigger hook to allow the plugins to manipulate the display data that will be used by the layout that renders the map.

Any arguments injected within the $data array will then be accessible by the layouts used to display the map.


Parameters

$status

(bool)  True on success, false on failure.

&$data

(array)  An associative array containing the data to display.


Example

The example below injects a few settings within the configuration of the map. The new settings will be now accessible from any layouts. In addition, this script changes the border color for those tables that are not capable to host a reservation according to the search parameters. This way, it will be possible to easily distinct whether a table is already occupied or not.

/**
 * Trigger filter to allow the plugins to manipulate the display
 * data that will be used by the layout that renders the map.
 *
 * @param  boolean  $status  True on success, false on failure.
 * @param  array    &$data   The display data array.
 */
add_filter('vikrestaurants_before_build_map', function($status, &$data)
{
    try
    {
        // get current operator, if any
        $operator = VikRestaurants::getOperator();
    }
    catch (Exception $e)
    {
        // the user is not an operator
        $operator = null;
    }

    // make operator instance available for all layouts
    $data['options']->operator = $operator;
	
    // then scan the tables to use a different border color
    // between the tables occupied (red) and the tables
    // not capable to host the reservation (yellow)
    foreach ($data['tables'] as &$table)
    {
        if (!$table->getData('available'))
        {
            // table not available, check whether it is
            // already occupied or not capable
            if (!$table->getData('reservations'))
            {
                // No reservations assigned, not capable...
                // Use a different color.
                $table->stroke = '#EBBE10';
            }
        }
    }

    return $status;
}, 10, 2);

Changelog

Version Description
1.0 Introduced.
Last Update: 2021-03-27
Helpful?
See Also: