Hello everyone,
the short version of my question:
In Moodle 3.1, if I change the role of a currently logged in user via a php script that changes the corresponding database entry in mdl_role_assignments, the change won't be activated without the user logging out and back in. Is there a way to make this change active without a relog?
Further infos:
I'm using a plugin where I'm guiding users through different steps on my moodle page.
I'm using html blocks to display different information depending on the progress of the users. During this process the user has to enter a wiki twice and i want the block on that wiki page to look differently depending on if the user entered for the first or the second time. The only way I found out to individualize blocks like that is by editing the permissions of the block so only certain roles can view it. What i then tried to do was duplicate the student role and have one block visible only for students, the other block visible only for the duplicated role. After a student leaves the wiki, a php script changes his role to the duplicated one, so the next time he enters the wiki, he views the second block instead of the first. However, this change only works after the user has logged out and logged back in, but I dont want users to relog at this point.
Thanks in advance and I appreciate any help you can give me
Kind Regards,
Daniel
Don't directly change mdl_role_assignments. Use the role_assign and role_unassign API defined in accesslib.php. Then the update will take effect immediately.
Now I feel kind of stupid not to have come up with that myself.
It's all working now, thanks a lot for your help.