public function onAfterSaveRescodeorder( array $src, bool $is_new, JTable $table ) : void

Fires after saving a new status code.


Description

This hook is triggered after creating or updating a status code for a restaurant reservation and/or a take-away order. External plugins can use this hook to perform further actions every time the status code of a reservation/order changes.

It is possible to fetch the details of the selected status code by using the code below:

$code = JHtml::_('vikrestaurants.rescode', $src['id_rescode'], $src['group'], $src['id_order']);

The $code variable can be an object or NULL, in case the requested code does not exist. The object holds all the following information:

  • code - the name of the status code;
  • icon - the icon of the status code;
  • notes - the notes of the status code;
  • type - the ID of the group (1 for restaurant reservations, 2 for take-away orders, 3 for food);
  • rule - the rule to trigger when the status code gets selected;
  • createdby - the user ID that saved the status code;
  • createdon - the UNIX timestamp when the status code was created.


Parameters

$src

(array)  The properties of the table that have been saved.

$is_new

(bool)  True in case of insert, false in case of update.

$table

(JTable)  The table instance.

Return Value

None.


Example

The following example explains how to observe every status change (for take-away orders) in search of a "delivered" status code.

/**
 * Trigger event to allow the plugins to make something after saving a status code
 * for a restaurant reservation or a take-away order.
 *
 * @param   array   $src     The saved properties of the table.
 * @param   bool    $is_new  True in case of insert, false in case of update.
 * @param   JTable  $table   The table instance.
 *
 * @return  void
 */
public function onAfterSaveRescodeorder($src, $is_new, $table)
{
    if (!$is_new) {
        // ignore updates
        return;
    }

    // recover the details of the status code
    $code = JHtml::_('vikrestaurants.rescode', $src['id_rescode'], $src['group'], $src['id_order']);

    if (!$code) {
    	// code not found
    	return;
    }

    if ($code->rule !== 'completed') {
        // observe only status codes with "completed" rule (delivered or picked)
        return;
    }

    // recover the reservation/order details
    if ($src['group'] == 1) {
        // load restaurant reservation
        $order = VREOrderFactory::getReservation($src['id_order']);
    } elseif ($src['group'] == 2) {
        // load take-away order
        $order = VREOrderFactory::getOrder($src['id_order']);
    }

    /**
     * @todo do something here
     */
}

Changelog

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