public function onFormatTimeSelectOption( object $time, int $step, object $shift, int $group ) : string

Fires while formatting the text of the option belonging to the dropdown used to pick a time.


Description

This hook is triggered to let external plugins format the text to show within the options of the time dropdown.

Fires for each option within the time dropdown.


Parameters

$time

(object)  The object holding the details of the time option. The format property will report the default text that will be used in case of no manipulation.

$step

(int)  The minutes of interval between this time and the next one.

$shift

(object)  The object holding the details of the current working shift.

$group

(int)  The section to which the time refers, 1 for restaurant and 2 for take-away.

Return Value

String. The text to show for the given time option.


Example

The example below displays approximative times for the take-away availability dropdown. In example, instead of 8:00 pm, the system will display 8:00 pm - 8:20 pm.

/**
 * Trigger filter to let external plugins format the text to
 * show within the options of the time dropdown.
 *
 * @param   object  $time   The object holding the time details.
 * @param   int     $step   The minutes between this time and the next one.
 * @param   object  $shift  The object holding details of the current shift.
 * @param   int     $group  The section to which the times refer (1: restaurant, 2: take-away).
 *
 * @return  string  The text to display.
 */
public function onFormatTimeSelectOption($time, $step, $shift, $group)
{
    // observe only take-away times
    if ($group == 2) {
        // create delimiter time by adding the interval length
        $end = $time->hour * 60 + $time->min + $step;
        // get a readable time string
        $end = JHtml::_('vikrestaurants.min2time', $end);

        // create approx. text
        return $time->format . ' - ' . $end;
    }
}

Changelog

Version Description
1.8.4 Introduced.
Last Update: 2023-12-29 14:15
Helpful?