-
Notifications
You must be signed in to change notification settings - Fork 17
Hook Framework
Andy Martin edited this page Jun 19, 2014
·
3 revisions
REDCap custom hooks are introduced by the inclusion of a single file as defined in the Control Center:
In this file you can enable hooks as specified by the hooks API in your current REDCap version (e.g. see https://your-redcap/redcap_v5.11.2/Plugins/index.php) for details.
I have included a sample file called redcap_hooks.php in this repository that shows how the included features are being added.
In addition to this 'root-level' file. I've also created a folder hierarchy:
- hooks (a folder for all things hook-related. I guess you could even move the redcap_hooks.php file in here)
- global (this is a place for code that is included for all hook events - such as for all survey hooks)
- resources (this is where static code for hooks is kept. The majority of the features on this github should belong in this resources page)
- pidXXXX (project-specific folders for hooks. Inside this folder you include a project-specific hook as named in the main redcap_hooks file.)
Using the redcap_survey_page method as an example, you can see how the redcap_hooks.php file tries calling a global hook first and then a project-specific hook.
function redcap_survey_page($project_id, $record, $instrument, $event_id, $group_id, $survey_hash, $response_id)
{
// Check for a global script that applies to all projects
$global_handler_script = dirname(__FILE__) . "/hooks/global/redcap_survey_page.php";
if (file_exists($global_handler_script)) include $global_handler_script;
// Check for a project-specific script
$project_handler_script = dirname(__FILE__) . "/hooks/pid{$project_id}/redcap_survey_page.php";
if (file_exists($project_handler_script)) include $project_handler_script;
}