public function onBeforeSaveReservation(mixed &$data, JTable $table) : bool

Fires before saving an appointment.


Description

This hook is triggered before creating or updating an appointment record. It can be used to bind the data that are going to be saved within the database.

TIP: in case of failure while saving the record, it is possible to throw an exception to abort the saving process and return a readable error message. The same can be accomplished by registering an error to the table and returning false.

// throw an exception
throw new Exception('Missing required field', 404);
// or register the error
$table->setError('Missing required field');
return false;

Parameters

&$data

(array|object)  Either an array or an object specifying the appointment properties to bind.

$table

(JTable)  The table instance that handles the saving process.

Return Value

Boolean. Use false to abort the saving process.


Example

The following example is used to save a new property that is not supported by default. It is assumed that the appointments database table has been altered to support the id_meeting column.

/**
 * Trigger hook to allow the plugins to bind the object that
 * is going to be saved.
 *
 * @param   mixed    &$data  The array/object to bind.
 * @param   JTable   $table  The table instance.
 *
 * @return  boolean  False to abort the saving process.
 */
public function onBeforeSaveReservation(&$data, $table)
{
    $input = JFactory::getApplication()->input;

    // retrieve ID_MEETING from request
    $id_meeting = $input->get('id_meeting', null, 'string');

    // make sure the meeting ID was set
    if (!is_null($id_meeting))
    {
        // bind array with id_meeting to include it within the UPDATE/INSERT query
        $data['id_meeting'] = $id_meeting;
    }

    return true;
}

Changelog

VersionDescription
1.7.0 Added $table argument.
Accepted a return value to stop the saving process.
1.6.4 Introduced.
Last Update: 2021-10-05 16:42
Helpful?
See Also: