How to update a variable in user's session?

How to update a variable in user's session?

by Dimitar Ivanov -
Number of replies: 4

Is there a way (API?) to update a variable in a user's session?

Or to force Moodle to re-initialize the user's session with new data from the database?

I am changing a user's  theme from an event observer and I want the user to see the change, without having to log in again.






Average of ratings: -
In reply to Dimitar Ivanov

Re: How to update a variable in user's session?

by Yousuf Tafhim -
Did you try with the "Allow user theme" option enabled on Site administration->Appearance->Themes->Theme settings and then check how that works?
In reply to Yousuf Tafhim

Re: How to update a variable in user's session?

by Dimitar Ivanov -

Thank you Yousuf, I have it enabled but it's not what I really want.


Here is a scenario with 'Allow user themes' setting enabled, that I want to be able to do.

1) In one browser login with User 1

2) In another browser, while User 1 is logged in, login with User 2 that has admin privileges

3) Edit User 1's profile from the User 2 browser, and change his "Theme"

4) Refresh the page in the  User 1 browser


What I want, is User 1 to see the new theme at step 4, without having to logout and login again.

I ask if there is a way to 'hint' Moodle, to update User 1's $USER->theme variable because it has changed.


I am using database sessions, and I was thinking to try and edit the user's sessdata in mdl_sessions, but I'm not really sure if that's the proper way and if it would actually work.



In reply to Dimitar Ivanov

Re: How to update a variable in user's session?

by Yousuf Tafhim -

You will have to code it as a separate functionality for this