Hi,
I developped a local plugin to enrol users automatically in groups when they are enrolled in a course.
I created the function "local_groupautoplus_user_enrolled($eventdata)" and I got details from Object $evendata
Example 1 : when an user is enrolled via a cohort :
Object $evendata
[id] => 382935
[status] => 0
[enrolid] => 10855
[userid] => 622
[timestart] => 0
[timeend] => 0
[modifierid] => 193
[timecreated] => 1413565732
[timemodified] => 1413565732
[enrol] => cohort
[courseid] => 3218
Example 2 : when an user is enrolled manually :
Object $evendata
[id] => 382934
[status] => 0
[enrolid] => 397
[userid] => 42
[timestart] => 1413496800
[timeend] => 0
[modifierid] => 193
[timecreated] => 1413565569
[timemodified] => 1413565569
[enrol] => manual
[courseid] => 3218
I need to get the roleid defined for this user when enrolled :
> for example 1, it is easy : I got the roleid in table enrol : "SELECT roleid FROM enrol where id = $evendata->enrolid"
> for example 2, it is more complicated : if I use the same request, I got a roleid which is the "default roleid" for the "manual enrolments" method, not the real role assigned.
To find it, I have to get it from the table role_assignments
The problem is : when I want to get the roleid from role_assignments, I have got this error :
Can not find data record in database table role_assignments.
Debug info: SELECT roleid FROM {role_assignments} WHERE contextid = ? AND userid = ?
[array (
0 => 130111,
1 => '42',
)]
Error code: invalidrecord
The fact is : the table role_assignments is filled AFTER that the function "local_groupautoplus_user_enrolled($eventdata)" is called ...
How can I get the real roleid which is not in the Object $evendata ... ?