/** * 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_deleted-event * * @param object $eventdata - the event's data */ function group_deleted_handler($eventdata) { global $CFG; global $COURSE; //check if this group is relevant if (record_exists('mumiemodule_students', 'groupid', $eventdata->group)) { event_logoutput("group_deleted_handler called \n", $eventdata); $tutorialid = 'moodle-' . $CFG->prefix . 'groups-' . $eventdata->group; //if there had been students in that group, remove //THIS PART OF CODE SHOULD BE REMOVED WHEN THE DELETE-SYNC-ORDER IS IMPLEMENTED IN MUMIE //MUMIE ITSELF SHOULD THEN HANDLE THOSE TUTORIAL-INTERNAL REMOVEMENTS $groupusers = get_records('mumiemodule_students', 'group', $eventdata->group, '', 'userid'); $js = new JapsSynchronise(); $fields = 'id, username, password, firstname, lastname'; foreach ($groupusers as $groupuser) { $userid = 'moodle-' . $CFG->prefix . 'user-' . $groupuser->id; remove_user_from_mumie_tutorial($userid, $tutorialid, $js); } //END OF CODE TO REMOVE //delete_tutorial_for_mumie($tutorialid); //TODO } return true; }