/** * Function to handle the password_changed-event * * @param object $eventdata - the event's data */ function password_changed_handler($eventdata) { global $CFG; event_logoutput("password_changed_handler called \n", $eventdata); //check if the user is relevant for MUMIE if (record_exists('mumiemodule_students', 'userid', $eventdata->user->id)) { $changeduser = get_mumie_user($eventdata->user); change_user_for_mumie($changeduser); } return true; }
function create_the_big_one($mumiemodule) { global $CFG; global $USER; global $COURSE; //first the semester $semester_id = 'moodle-' . $CFG->prefix . 'course_categories-' . $COURSE->category; $semester_name = get_field('course_categories', 'name', 'id', $COURSE->category); //TODO: replace this hack by api-method when available $semester_description = 'a Moodle-category as semester'; $semester = new Semester($semester_id, $semester_name, $semester_description); //lets get the lecturers $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); $fields = 'u.id, u.username, u.password, u.firstname, u.lastname'; $lecturers = null; $roleid = get_field('role', 'id', 'shortname', 'editingteacher'); if ($mumie_users = get_role_users($roleid, $context, true, $fields)) { $lecturers = array(); foreach ($mumie_users as $mumie_user) { $newuser = get_mumie_user($mumie_user); $lecturer = new Lecturer($newuser->syncid, $newuser->loginname, $newuser->passwordencrypted, $newuser->firstname, $newuser->surname, $newuser->matrnumber); array_push($lecturers, $lecturer); } } //now the class $class_id = 'moodle-' . $CFG->prefix . 'course-' . $COURSE->id; $class_name = $COURSE->fullname; $class_description = $COURSE->summary; //and now we have the tutorials: $tutorials = null; if ($mumie_groups = groups_get_all_groups($COURSE->id)) { $tutorials = array(); foreach ($mumie_groups as $mumie_group) { $tutor = null; $tutorial_id = 'moodle-' . $CFG->prefix . 'groups-' . $mumie_group->id; $tutorial_name = $mumie_group->name; $tutorial_description = $mumie_group->description; //$context = get_context_instance(CONTEXT_GROUP, $mumie_group->id); //no more group_contexts in moodle $group_users = get_users_by_capability($context, 'mod/mumiemodule:tutorize', $fields, '', '', '', $mumie_group->id); foreach ($group_users as $group_user) { //zur sicherheit, da sonst alle tutoren in jeder gruppe: if (groups_is_member($mumie_group->id, $group_user->id)) { $newuser = get_mumie_user($group_user); $tutor = new Tutor($newuser->syncid, $newuser->loginname, $newuser->passwordencrypted, $newuser->firstname, $newuser->surname, $newuser->matrnumber); break; //so just the first tutor will be inserted } } //the students within this tutorial: $students = null; if ($group_users = get_users_by_capability($context, 'mod/mumiemodule:participate', $fields)) { $students = array(); foreach ($group_users as $group_user) { if (groups_is_member($mumie_group->id, $group_user->id)) { $newuser = get_mumie_user($group_user); $student = new Student($newuser->syncid, $newuser->loginname, $newuser->passwordencrypted, $newuser->firstname, $newuser->surname, $newuser->matrnumber); array_push($students, $student); } } } //for the transfer_classes: $tutorial = new Tutorial($tutorial_id, $tutorial_name, $tutorial_description, $tutor, $students); array_push($tutorials, $tutorial); } } //don't forget the MUMIE-course $mumie_course_id = $mumiemodule->mumie_course_id; $mumie_class = new MumieClass($class_id, $class_name, $class_description, $semester, $lecturers, $tutorials, $mumie_course_id); return $mumie_class; }