/**
 * Populates a standar user record
 * @param  stdClass $user    The user record to be populated
 * @param  stdClass $context The LTI context
 * @param  stdClass $tool    The tool object
 */
function local_ltiprovider_populate($user, $context, $tool)
{
    global $CFG;
    $user->firstname = isset($context->info['lis_person_name_given']) ? $context->info['lis_person_name_given'] : $context->info['user_id'];
    $user->lastname = isset($context->info['lis_person_name_family']) ? $context->info['lis_person_name_family'] : $context->info['context_id'];
    $user->email = clean_param($context->getUserEmail(), PARAM_EMAIL);
    $user->city = !empty($tool->city) ? $tool->city : "";
    $user->country = !empty($tool->country) ? $tool->country : "";
    $user->institution = !empty($tool->institution) ? $tool->institution : "";
    $user->timezone = !empty($tool->timezone) ? $tool->timezone : "";
    $user->maildisplay = !empty($tool->maildisplay) ? $tool->maildisplay : "";
    $user->mnethostid = $CFG->mnet_localhost_id;
    $user->confirmed = 1;
    $user->timecreated = time();
    $user->timemodified = time();
    $user->lang = $tool->lang;
    if (!$user->lang and isset($_POST['launch_presentation_locale'])) {
        $user->lang = optional_param('launch_presentation_locale', '', PARAM_LANG);
    }
    if (!$user->lang) {
        // TODO: This should be changed for detect the course lang
        $user->lang = current_language();
    }
}