/** * This function gets run whenever a role is assigned to a user in a context * * @param integer $userid * @param object $context * @return bool */ function mumiemodule_role_unassign($userid, $context) { //TODO: return-werte bearbeiten global $CFG; //it is not possible to check if this had been a teacher before removal //but we can check if this user was NOT a student in a group in this course if ($context->contextlevel == CONTEXT_COURSE) { if ($groups = groups_get_all_groups($context->instanceid, $userid)) { foreach ($groups as $group) { if (groups_is_member($group->id, $userid)) { //so this is a tutor or student $mumiemodules = get_records('mumiemodule', 'course', $context->instanceid); //list of all mumiemodules in the course $mumiemodules = array_values($mumiemodules); if (!record_exists('mumiemodule_students', 'userid', $userid, 'mumiemodule', $mumiemodules[0]->id)) { //so this was no student //the user had been a tutor - we have to change the tutorial $tutorial = new object(); $tutorial->syncid = 'moodle-' . $CFG->prefix . 'group-' . $group->id; $tutorial->tutor = 'moodle-dummy_tutor'; change_tutorial_for_mumie($tutorial); //the user could have been a tutor but could also been a teacher - so try: return mumiemodule_remove_teacher_subscriptions($userid, $context); } else { //this had been a student that is still in a MUMIE-tutorial $user_sync_id = 'moodle-' . $CFG->prefix . 'user-' . $userid; $group_sync_id = 'moodle-' . $CFG->prefix . 'group-' . $group->id; remove_user_from_mumie_tutorial($user_sync_id, $group_sync_id); //and now the student has to be removed from all mumiemodules in this course foreach ($mumiemodules as $mumiemodule) { mumiemodule_students_unsubscribe($userid, $mumiemodule, $group->id); } } } } } else { //this user could have been nearly any role - so try: return mumiemodule_remove_teacher_subscriptions($userid, $context); } } //for any other context we try to remove teachers: return mumiemodule_remove_teacher_subscriptions($userid, $context); }
/** * Function to handle the group_user_removed-event * * @param object $eventdata - the event's data */ function group_user_removed_handler($eventdata) { global $CFG; //check if this group is relevant $group = groups_get_group($eventdata->groupid); $courseid = $group->courseid; $context = get_context_instance(CONTEXT_COURSE, $courseid); if (record_exists('mumiemodule_students', 'groupid', $eventdata->groupid)) { event_logoutput("group_user_removed_handler called \n", $eventdata); //check if removed user might be tutor or not if (has_capability('mod/mumiemodule:tutorize', $context, $eventdata->userid)) { //while MUMIE-DB is not changed we insert the Dummy-Tutor: $tutorial = new object(); $tutorial->syncid = 'moodle-' . $CFG->prefix . 'groups-' . $eventdata->groupid; $tutorial->name = $eventdata->name; $tutorial->description = $group->description; $tutorial->tutor = 'moodle-dummy_tutor'; $tutorial->classid = 'moodle-' . $CFG->prefix . 'course-' . $courseid; change_tutorial_for_mumie($tutorial); } else { if (has_capability('mod/mumiemodule:participate', $context, $eventdata->userid)) { //this is a student $userid = 'moodle-' . $CFG->prefix . 'user-' . $eventdata->userid; $tutorialid = 'moodle-' . $CFG->prefix . 'groups-' . $eventdata->groupid; remove_user_from_mumie_tutorial($userid, $tutorialid); //a user must be part in exactly one tutorial per course - so the user has to be removed from the modules of this course $mumiemodules = get_records('mumiemodule', 'course', $courseid); foreach ($mumiemodules as $mumiemodule) { mumiemodule_students_unsubscribe($eventdata->userid, $mumiemodule->id, $eventdata->groupid); } } } } return true; }