public function onAfterBuildTimeline(mixed $timeline) : bool

Fires after constructing the object wrapping the timeline.


Description

Fires an event to manipulate the timeline without having to create a new parser. Does not trigger in case the timeline building returned an invalid instance.

NOTE: throw an exception to prompt a message to the front-end user to explain why the timeline is not visible.


Parameters

$timeline

(VAPAvailabilityTimeline)  The timeline wrapper.

Return Value

Boolean. False to prevent the timeline from showing.


Example

The example below explains how to work with the timeline object.

/**
 * Fire an event to manipulate the timeline without having to create a new parser.
 * DO NOT trigger in case the timeline building returned an invalid instance.
 * 
 * Throw an exception to display an error message to the front-end user.
 *
 * @param   VAPAvailabilityTimeline  $timeline  The timeline object.
 * 
 * @return  bool  Return false to prevent the timeline building.
 */
public function onAfterBuildTimeline($timeline)
{
    // iterate all the times by using the iterator interface
    foreach ($timeline as $level) {
        foreach ($level as $time) {
            // look for available times only
            if ($time->isAvailable() == false) {
                continue;
            }

            if ($time->checkin('G') % 2 === 0) {
                // in case of even hour, turn off the availability
                $time->setStatus(0);
            } else {
                // in case of odd hour, double the price
                $time->setPrice($time->price * 2);
            }
        }
    }

    return true;
}

Changelog

Version Description
1.7.5 Introduced.
Last Update: 2024-05-14 13:46
Helpful?
See Also: