academic-moodle-cooperation / moodle-mod_offlinequiz

The Offline Quiz activity allows the creation of multiple choice tests with questions from the question bank of a Moodle course, which are handed out to students in printed form. After completion, the answer forms are scanned and can be automatically evaluated online directly in Moodle.
https://academic-moodle-cooperation.org/mod_offlinequiz/
GNU General Public License v3.0
31 stars 58 forks source link

Custom profile fields as ID-Number #30

Open inceddy opened 7 years ago

inceddy commented 7 years ago

It would be a nice feature to use custom profile fields as ID source. Updating the settingslib.php is simple

// Require more user functions
require_once($CFG->dirroot . '/user/profile/lib.php');
// ... Extend user object
profile_load_custom_fields($testuser); 
// ... Test for profile fields in if-clause and extend settings with a new field 'ID_profile' to indecate field location
    if (isset($testuser->{$field}) || (isset($testuser->profile) && isset($testuser->profile[$field]))) {
        set_config('ID_digits', $digits, 'offlinequiz');
        set_config('ID_prefix', $prefix, 'offlinequiz');
        set_config('ID_postfix', $postfix, 'offlinequiz');
        set_config('ID_field', $field, 'offlinequiz');
        set_config('ID_profile', isset($testuser->profile) && isset($testuser->profile[$field]), 'offlinequiz');
        return true;
}

Add new resolver function in locallib.php

function offlinequiz_get_userid($user, $ID_field = null)
{
    if (null === $ID_field) {
      $settings = get_config('offlinequiz');
      $ID_field = $settings['ID_field'];
    }

    if (isset($user->{$ID_field})) {
        return $user->{$ID_field};
    }

    // Load profile fields if missing
    if (!isset($user->profile)) {
        global $CFG;
        require_once($CFG->dirroot . '/user/profile/lib.php');
        profile_load_custom_fields($user); 
    }

    if (isset($user->profile[$ID_field])) {
      return $user->profile[$ID_field];
    }

    throw new \Exception('Offlinequiz: User ID-Field not found');
}

The more tricky part is to update all the DB statements. Have you ever thougt about this feature?

univietw commented 7 years ago

Nobody wanted to have this future yet, at least that I know of. We will put it on a list. If you provide a patch or it, I would integrate it and provide it for the next Release 3.3 :) If you have any questions regarding some of the database queries, don't hesitate to ask.

kaspot commented 6 years ago

This feature request is in our Triage: #4273

cborn commented 6 years ago

Is it possible to find out when this feature will be available? I need this feature, as well!

nuria2c commented 6 years ago

The formula to define user identification does not allow entering an id with the variable tag. Our user IDs have between 4 and 7 digits. We can not use the plugin for this limitation. When you load the response forms, you do not load those corresponding to users with an ID of less than 7 digits. Would you possibly introduce this improvement?

giovannidamaro commented 5 years ago

The formula to define user identification does not allow entering an id with the variable tag. Our user IDs have between 4 and 7 digits. We can not use the plugin for this limitation. When you load the response forms, you do not load those corresponding to users with an ID of less than 7 digits. Would you possibly introduce this improvement?

We have the same problem. Our students have a 15-digit identification code that also contains points (.) and therefore the plugin cannot be used. This unfortunately is a big problem. Do any of you have a solution?

LisaE14 commented 4 years ago

Once we need 7 digits and once we need 8 digits. We would be happy if the useridentification setting can be defined per course or quiz.

foxlapinou commented 6 months ago

We would also be very interested to be able to use Moodle custom profile field for the user identification.

About being able to define user identification by activity, i've just created issue 240.

R2D2byBest commented 2 months ago

Hi all,

I've adapted the code to use a custom field in the profile. I need to figure out how to share it easily.

Regards