Example #1
0
/**
 * Executes the user-defined callback with data for the given session
 * 
 * @throws ConfigurationSyntaxException if there was a problem executing the callback
 * @param Session $session the session "for whom" the callback is executed
 */
function executeCallback(Session $session)
{
    global $RESPONSE;
    // construct the data object that will be passed to the user
    $basset_variables = new BassetVariables($session);
    // prepare and execute user-defined callback
    if ($session->current_step->on_complete) {
        // the submission data from the latest round will also be passed to the user
        $input_data =& $session->currentRoundData();
        $submit_variables = (object) $input_data;
        // ... as an object
        // get the function file
        $function_file = $session->current_step->game->directory . Game::function_file;
        if (!file_exists($function_file)) {
            throw new ConfigurationSyntaxException("game missing function file (looked for {$function_file})");
        }
        include_once $function_file;
        // get the name of the callback function
        $user_function = $session->current_step->on_complete;
        // check that the function exists
        if (!function_exists($user_function)) {
            throw new ConfigurationSyntaxException("callback function {$user_function} does not exist");
        }
        // execute the callback
        $user_function($basset_variables, $submit_variables);
        // save variables after callback
        $basset_variables->save();
    }
    return TRUE;
}