-
Notifications
You must be signed in to change notification settings - Fork 26
3.1) Hooks: Implementation
Marco Cesarato edited this page Apr 11, 2019
·
6 revisions
For write hooks you can use hooks/custom
folder or edit manually the examples on hooks/actions.hooks.php
or hooks/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)
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
https://github.com/marcocesarato/Database-Web-API/wiki/3.2)-Hooks:-List
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 |
-
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).')';