public function onBeforeBuildMap( array &$data ) : void

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

&$data

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

Return Value

None.


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   array  &$data  The display data array.
 *
 * @return  void
 */
public function onBeforeBuildMap(&$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';
            }
        }
    }
}

Changelog

Version Description
1.8 Introduced.
Last Update: 2023-12-29 14:15
Helpful?
See Also: