Purposes
With this tool you can assign/unassign several roles (of the same type) to one single user.
For example you can enrol one student in twelve courses.
Note that that is also a way to view all the different roles (of the same type) of one single user.
It only works in three types of context: system, coursecategory, course.
In system category context you can assign a type of role to the selected user for any category or course.
In course category context you can assign a type of role to the selected user for the current category, its subcategories and the relevant courses (this last one is the initial need in my university).
In course context you can assign a type of role to the selected user for the blocks, modules, etc.
This feature is restricted to users with the role:assign capability for the context.
Downloading
From https://sourcesup.cru.fr/projects/moodleum/
- assignoneuser.php
- assignoneuser.html
- accesslib_assignoneuser_get_child_contexts.diff
- accesslib_assignoneuser_get_user_roles .diff
For plugging into Moodle:
- tabs_assignoneuser.diff
Installing
1) Put the files assignoneuser.php and assignoneuser.html into the admin/roles directory.
2) As specified in the file libaccess_assignoneuser_get_child_contexts.diff, modify three parts of the function get_child_contexts of the lib/accesslib.php library, for adding a new boolean argument lowest_children_are_courses
3) As specified in the file accesslib_assignoneuser_get_user_roles .diff, modify two parts of the function get_user_roles of the lib/accesslib.php library for adding a new boolean argument checkchildcontexts
4) Add the three lines below (in bold) in your lang file(s) role.php:
$string['assignglobalroles'] = 'Assign global roles';
$string['assignrolesoneuser'] = 'Assign roles to one user';
$string['blog:create'] = 'Create new blog entries';
...
$string['errorexistsroleshortname'] = 'Role name already exists';
$string['existingcontexts'] = 'Existing contexts';
$string['existingusers'] = '$a existing users';
...
$string['permissions'] = 'Permissions';
$string['potentialcontexts'] = 'Potential contexts';
$string['potentialusers'] = '$a potential users';
Trying
Launch this URL: http://[YourSite]/admin/roles/assignoneuser.php?contextid=1 (if "1" is the id of your system context)
Using
- select one user for viewing his current contexts and his potential contexts
- select one or more of the potential contexts (e.g. some courses) and click on the 'left' arrow for assigning him to these contexts for the selected role
- select one or more of his current contexts and click on the 'right' arrow for unassigning him from these contexts for the selected role
Plugging into Moodle
For example, you could add the tab 'assignoneuser' to the common script admin/roles/tabs.php, preferably between the tab 'assign' and the tab 'override', as specified in the file tabs_assignoneuser.diff .
Thus you will be able to use this tool as you use the other roles tools.
To do
- changing the get_context_instance_by_id function for adding the full path of the categorie because some categories have the same name
- sorting the contexts as a tree, not alphabetically
- for better plugging, add a link to this tool from 'Site Administration' menu (under 'Assign global roles' choice)
Full documentation
http://sourcesup.cru.fr/docman/view.php/342/3005/assignoneuser.pdf
Thanks
To Joseph Rézeau, for testing