Skip to content

3.1) Hooks: Implementation

Marco Cesarato edited this page May 20, 2019 · 6 revisions

Hooks/Plugins Implementation

For write hooks you can use plugins/custom folder or edit manually the examples on plugins/actions.hooks.php or plugins/filters.hooks.php

Remember to name file like this pattern: [FILENAME].hooks.php or it will not be included automatically (else you can include it manually)

Tips

You can use this code for have a database instance and the current user authenticated row:

$user = Auth::getUser(); // User row
$db = API::getDatabase('dataset'); // You can specify dataset. Return PDO Object

Hooks list

https://github.com/marcocesarato/Database-Web-API/wiki/3.2)-Hooks:-List

Most important hooks

Hook Type Description Params Return
sql_restriction Filter Add restriction on where conditions for each query (string) $restriction (string) $table (string) $permission String
can_read Filter Return if can get/select (bool) $permission = true Bool
can_write Filter Return if can post/insert (bool) $permission = true Bool
can_edit Filter Return if can put/update (bool) $permission = true Bool
can_delete Filter Return if can delete (bool) $permission = true Bool
on_read Filter Result content returned on get/read (array) $data (string) $table Array
on_write Filter Result content returned on post/write (array) $data (string) $table Array
on_edit Filter Result content returned on put/edit (array) $data (string) $table Array
on_delete Filter Get result content returned on delete (array) $data (string) $table Array

Hooks detail

  • Filter: sql_restriction

    Options of $permission:

    case 'READ':
    case 'EDIT':
    case 'DELETE':

    Return

    // All denied
    $sql = "'1' = '0'";
    // All allowed
    $sql = "'1' = '1'";

    Examples:

    // Only Created
    $sql = 'created_by = '.$user['id'];
    // Only Team
    $sql = 'created_by IN ('.implode(',',$teams_ids).')';
Clone this wiki locally