Code Change Detection
apply_filters( 'vikrestaurants_after_save_rescodeorder', bool $status, array $src, bool $is_new, JTable $table )
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
- $status
-
(bool) True on success, false otherwise.
- $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.
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 boolean $status True on success, false otherwise.
* @param array $src The saved properties of the table.
* @param boolean $is_new True in case of insert, false in case of update.
* @param JTable $table The table instance.
*/
add_filter('vikrestaurants_after_save_rescodeorder', function($status, $src, $is_new, $table)
{
if (!$is_new)
{
// ignore updates
return $status;
}
// 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 $status;
}
if ($code->rule !== 'completed')
{
// observe only status codes with "completed" rule (delivered or picked)
return $status;
}
// recover the reservation/order details
if ($src['group'] == 1)
{
// load restaurant reservation
$order = VREOrderFactory::getReservation($src['id_order']);
}
else if ($src['group'] == 2)
{
// load take-away order
$order = VREOrderFactory::getOrder($src['id_order']);
}
/**
* @todo do something here
*/
return true;
}, 10, 4);
Changelog
Version | Description |
---|---|
1.0 | Introduced. |