Italian (Italy)

apply_filters_ref_array( 'vikappointments_before_save_review', bool $save, mixed &$data, JTable $table )

Fires before saving a review.


Description

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

In case the $data argument specifies a id_service property/attribute, than the review will be published for a service, otherwise it will be published for an employee.

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

$save

(bool)  Use false to abort the saving process.

&$data

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

$table

(JTable)  The table instance that handles 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 reviews database table has been altered to support the modifydate column.

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

    // retrieve MODIFY DATE from request
    $modifydate = $input->get('modifydate', null, 'string');

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

    return $save;
}, 10, 3);

Changelog

Version Description
1.2.0

Added $save and $table arguments.

Removed $isNew argument.

1.0.0 Introduced.
Ultimo aggiornamento: 2021-10-04
Utile?
Potrebbe interessarti:
This site uses cookies. By continuing to browse you accept their use. Further information