Enrol by user profile fields

Enrolment ::: enrol_attributes
Maintained by Nicolas Dunand
This plugin allows users to be enrolled according to any value stored in their user profile.
Latest release:
1415 sites
557 downloads
132 fans
Current versions available: 6

This plugin allows users to be enrolled according to any value stored in their user profile. If you use an external authentication scheme (LDAP, Shibboleth), you can store values in hidden user fields of the users' Moodle profile, and then use these values to automatically enrol users if some courses.

Screenshots

Screenshot #0

Contributors

Nicolas Dunand (Lead maintainer)
CSE Université de Lausanne: Supporting institution
Please login to view contributors details and/or to contact them

Comments RSS

Comments

  • Lynn Danzig
    Tue, 18 July 2017, 5:18 PM
    Hi
    Thanks for a great plugin.

    I am having trouble working out why I am not able to enrol based on a user profile I have set up.

    I have created a custom profile field and successfully updated records of 20 users with a particular value I want to use for enrolment.

    I can find these users by filtering on the field and value in Browse users in site admin.

    When I go to a course, I can select the enrolment method and it brings up the correct field and I can enter the value.

    There is no error message but in the enrolment data box it shows 0 users have been enrolled with this method.

    I am logged in as admin so permissions should not be an issue.

    I was able to enrol a cohort, so it should not be to do with course or user expiry (I am working on a dev site).

    Any suggestions?

    Many thanks
    Lynn
  • Nicolas Dunand
    Tue, 18 July 2017, 5:35 PM
    Hi Lynn,

    Thanks for your message. What happens if, after having saved your rule, you display it and click the "Force enrolments" button?
  • ray cheng
    Wed, 19 July 2017, 1:39 AM
    Hi, First of all, thanks for sharing this plugin.

    I installed moodle 3.3 version using mysql 5.6.36 and I have install this plugin.

    I have added 2 other fields (named field1 & fields) in user profile. However, when I selected the "Enrol by user profile" (in Users > Enrolment Methods) , the error showed as below

    customtext1=line 112 of /enrol/attributes/edit.php: call to debugging()

    Notice: Trying to get property of non-object in /var/www/html/moodle/enrol/attributes/lib.php on line 128
    fieldsandrules= Array ( [customuserfields] => Array ( [1] => field1 [2] => field2 ) [rules] => )
    line 114 of /enrol/attributes/edit.php: call to debugging()

    Warning: Invalid argument supplied for foreach() in /var/www/html/moodle/enrol/attributes/lib.php on line 149
    arraysql= Array ( [select] => [where] => [params] => Array egg )
    line 116 of /enrol/attributes/edit.php: call to debugging()
    sqlquery= SELECT DISTINCT u.id FROM {user} u WHERE
    line 119 of /enrol/attributes/edit.php: call to debugging()

    Debug info: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    SELECT DISTINCT u.id FROM mdl_user u WHERE
    [array (
    )]
    Error code: dmlreadexception

    Stack trace:
    line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown
    line 1175 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
    line 120 of /enrol/attributes/edit.php: call to mysqli_native_moodle_database->get_records_sql()

    Hope anyone can help. Thanks in advance.
  • Nicolas Dunand
    Wed, 19 July 2017, 2:23 PM
    HI Ray,

    Thanks for reporting this problem. First, can you confirm you have the latest version of this plugin ?

    Then, does this error appear as you're trying to create a new enrolment method ? Or when displaying an existing one ?
  • ray cheng
    Wed, 19 July 2017, 10:13 PM
    Hi Nicolas,

    Thanks for your prompt reply.

    My installed plugin version is 2017050100. And the error appears when displaying an existing one.
  • Nicolas Dunand
    Thu, 20 July 2017, 4:33 PM
    Hi Ray,
    This looks like what would happen is the rule set is completely empty (see "customtext1=" at the beginning of your debugging messages). There should be something there, not just nothing. Have you set up a rule ? If you reload the page with JavaScript turned off, you should see the code (JSON) for the rule, e.g. "{"rules":[{"param":"paramname","value":"somevalue"}]}". is that the case?
  • Francesco Di Pascasio
    Thu, 27 July 2017, 10:04 PM
    Hi Nicolas,

    I've installed your -really very useful, thank you very much indeed!- plugin on Moodle 3.2.1+ (Build: 20170223) and got it working on a development site here at La Sapienza University in Rome.

    Nevertheless at the bottom of the edit page (/enrol/attributes/edit.php?courseid=XYZ&id=ZX) I read:

    customtext1= stdClass Object ( [rules] => Array ( [0] => stdClass Object ( [param] => CODCDL [value] => 14493 ) [1] => stdClass Object ( [param] => CODCDL [value] => 14494 [cond_op] => or ) ) )
    line 112 of /enrol/attributes/edit.php: call to debugging()

    fieldsandrules= Array ( [customuserfields] => Array ( [2] => CODCDL ) [rules] => Array ( [0] => stdClass Object ( [param] => CODCDL [value] => 14493 ) [1] => stdClass Object ( [param] => CODCDL [value] => 14494 [cond_op] => or ) ) )
    line 114 of /enrol/attributes/edit.php: call to debugging()

    arraysql= Array ( [select] => RIGHT JOIN {user_info_data} d1 ON d1.userid = u.id AND d1.fieldid = 2 RIGHT JOIN {user_info_data} d2 ON d2.userid = u.id AND d2.fieldid = 2 [where] => (d1.data = ? OR d1.data LIKE ? COLLATE utf8_bin ESCAPE '\\' OR d1.data LIKE ? COLLATE utf8_bin ESCAPE '\\' OR d1.data LIKE ? COLLATE utf8_bin ESCAPE '\\') OR (d2.data = ? OR d2.data LIKE ? COLLATE utf8_bin ESCAPE '\\' OR d2.data LIKE ? COLLATE utf8_bin ESCAPE '\\' OR d2.data LIKE ? COLLATE utf8_bin ESCAPE '\\') [params] => Array ( [0] => 14493 [1] => %;14493 [2] => 14493;% [3] => %;14493;% [4] => 14494 [5] => %;14494 [6] => 14494;% [7] => %;14494;% ) )
    line 116 of /enrol/attributes/edit.php: call to debugging()

    sqlquery= SELECT DISTINCT u.id FROM {user} u RIGHT JOIN {user_info_data} d1 ON d1.userid = u.id AND d1.fieldid = 2 RIGHT JOIN {user_info_data} d2 ON d2.userid = u.id AND d2.fieldid = 2 WHERE (d1.data = ? OR d1.data LIKE ? COLLATE utf8_bin ESCAPE '\\' OR d1.data LIKE ? COLLATE utf8_bin ESCAPE '\\' OR d1.data LIKE ? COLLATE utf8_bin ESCAPE '\\') OR (d2.data = ? OR d2.data LIKE ? COLLATE utf8_bin ESCAPE '\\' OR d2.data LIKE ? COLLATE utf8_bin ESCAPE '\\' OR d2.data LIKE ? COLLATE utf8_bin ESCAPE '\\')
    line 119 of /enrol/attributes/edit.php: call to debugging()

    countusers= 0
    line 121 of /enrol/attributes/edit.php: call to debugging()

    If I disable Javascript I see in the rule box:

    {"rules":[{"param":"CODCDL","value":"14493"},{"param":"CODCDL","value":"14494","cond_op":"or"}]}

    As I miss the meaning and wonder if it is dangerous, any suggestion is really appreciated.

    Thank you for your time.

    Have a wonderful day.

    Ciao,

    Francesco
  • Nicolas Dunand
    Thu, 27 July 2017, 10:27 PM
    Ciao Francesco and thanks for your concern. This only displays if your site has debugging activated (and on display) OR if you are an administrator.
  • Francesco Di Pascasio
    Thu, 27 July 2017, 10:47 PM
    Ciao Nicolas, so I guess I don't have to worry about it... thanks again and Grazie for your excellent work.
  • King Hernandez
    Sat, 29 July 2017, 6:46 PM
    I did all the chances and possibilities to have this plugin fixed on my system. But I never had the result to get this plugin work properly. I did reinstall the Enrolment Plugin on my system, have the other enrolment plugins reviewed, and eventually put this Plugin on the top of the Enrollment Stack.
  • Oguzhan Ahiskali
    Wed, 9 Aug 2017, 2:33 AM
    I want to teach those who are unequal.

    Please help me!
  • Sandeep Nehra
    Tue, 15 Aug 2017, 2:03 PM
    We are using Moodle 3.3 and want to use existing profile fields to enroll users like department, team and others instead of custom user fields. How I can do that?
  • Rolf Petersen
    Sun, 3 Sept 2017, 12:11 AM
    Hello, this sounds to be a usefull Plugin for me. BUT I cannot get that work. Using M3.3 on Win-Server Installation is without failure. I can setup Default-role for example. I Activated this enrolement-Plugin but it does nor show up in enrolement-methods for any cours I have. Have restarted my moodle already with no effect. What may be wrong??? Thanks! Rolf
  • Daniel Celestino
    Sat, 7 Oct 2017, 12:25 AM
    Hi nicolas,
    I´m testing your plugin and i´m having a problem that I cound not revolve.
    When a user signs up (using no authentication method), i cannot access the course that I have previously configure for the custom field. I have to log off and log on an when I log in again, I can access to the course. If I click "force enrollment" while the user is logging in, refresh the page and it´s works. But, I need that after the user "sign up", the user has access to the course.
    Do you know how to resolve it?
    Thanks!
  • Franky Vallori
    Fri, 13 Oct 2017, 4:43 PM
    Hi Nicolas,
    I'm Francesco...I've a Moodle 3.1.6...I've installed the plugin version 2.4.2.
    The installation has been successful.
    The problem is that the "Enrol by user profile fields" method does not appear in Enrolment Methods, even if it is enabled between plugins.
    Do you know how to resolve it?
    Thanks!
Please login to post comments