/** * Function to handle the group_user_added-event * * @param object $eventdata - the event's data */ function group_user_added_handler($eventdata) { global $CFG; //check if this group is relevant $group = groups_get_group($eventdata->groupid); $courseid = $group->courseid; //if(record_exists('mumiemodule_students', 'groupid', $eventdata->groupid)){ //BUT WE SHOULD BETTER CHECK IF THE WHOLE COURSE IS RELEVANT if (record_exists('mumiemodule', 'course', $courseid)) { event_logoutput("group_user_added_handler called \n", $eventdata); //check if current user might be tutor or not //$context = get_context_instance(CONTEXT_GROUP, $eventdata->groupid); $context = get_context_instance(CONTEXT_COURSE, $group->courseid); if (has_capability('mod/mumiemodule:tutorize', $context, $eventdata->userid)) { //this is a tutor //groups must not have more than one tutor in this activity! //REMOVE AFTER MUMIE-DB CHANGE $fields = 'u.id'; //$groupcontext = get_context_instance(CONTEXT_GROUP, $eventdata->groupid); $grouptutors = get_users_by_capability($context, 'mod/mumiemodule:tutorize', $fields, '', '', '', $eventdata->groupid); if (count($grouptutors) > 1) { $removed = groups_remove_member($eventdata->groupid, $eventdata->userid); error(get_string('toomuchtutorssingle', 'mumiemodule'), "../group/members.php?group=" . $eventdata->groupid); break; } //REMOVE TILL HERE if (!has_capability('mod/mumiemodule:teachcourse', $context, $eventdata->userid)) { //so this is really just a tutor, lecturers are already known in mumie //perhaps the tutor is already known in MUMIE $tutortocheck = new object(); $tutortocheck->syncid = 'moodle-' . $CFG . 'user-' . $eventdata->userid; $tutorexists = check_tutor($tutortocheck); $islecturer = check_lecturer($tutortocheck); if (!$tutorexists && !$islecturer) { $newuser = get_record('user', 'id', $eventdata->userid); send_single_user_to_mumie($newuser); } } //start creating the tutorial-object $tutorial = new object(); $tutorial->syncid = 'moodle-' . $CFG->prefix . 'groups-' . $eventdata->groupid; $tutorial->name = $name->name; $tutorial->description = $group->description; $tutorial->tutor = 'moodle-' . $CFG->prefix . 'user-' . $eventdata->userid; $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 //a student must not be in more than one group in this activity $studentsgroups = groups_get_all_groups($courseid, $eventdata->userid); if (count($studentsgroups) > 1) { $removed = groups_remove_member($eventdata->groupid, $eventdata->userid); error(get_string('justonegroupsingle', 'mumiemodule'), "../group/members.php?group=" . $eventdata->groupid); break; } $mumiemodules = get_records('mumiemodule', 'course', $courseid); //variable to keep in mind whether there are more than one mumiemodules in this course $morethanone = false; foreach ($mumiemodules as $mumiemodule) { mumiemodule_students_subscribe($eventdata->userid, $mumiemodule->id, $group, $morethanone); $morethanone = true; } } } } else { //ACHTUNG: dies könnte eine nachträglich eingefügte gruppe sein!!!!!!!!!!!!!!!!!!!!!!!!!! } return true; }
/** * Function to insert all neccesarry information out of a new MUMIE-module into MUMIE * * @param object $insert - big object with all information */ function insert_all_for_mumie($insert) { global $CFG; global $COURSE; $js = new JapsSynchronise(); //first we insert the new semester if MUMIE does not know it yet $semesterexists = check_semester($insert->semester); if (!$semesterexists) { insert_semester_for_mumie($insert->semester, $js); } //now we insert the new class $newclass = new object(); $newclass->syncid = $insert->syncid; $newclass->name = $insert->name; $newclass->description = $insert->description; $newclass->semester = $insert->semester->syncid; $newclass->lecturers = ''; //let's be sure to have all lecturers as users in the MUMIE DB if ($insert->lecturers) { foreach ($insert->lecturers as $lecturer) { //perhaps the lecturer is already in the MUMIE $lecturerexists = check_lecturer($lecturer); if (!$lecturerexists) { insert_user_for_mumie($lecturer, $js); } $newclass->lecturers .= $lecturer->syncid . ' '; } } $newclass->mumie_course_id = $insert->mumie_course_id; insert_class_for_mumie($newclass, $js); //next is the tutorials if ($insert->tutorials) { foreach ($insert->tutorials as $tutorial) { //we should make sure that the tutor is a user in the Mumie DB if ($tutorial->tutor) { //perhaps the tutor is already in the MUMIE $tutorexists = check_tutor($tutorial->tutor); $tutor_is_lecturer = check_lecturer($tutorial->tutor); if (!$tutorexists && !$tutor_is_lecturer) { insert_user_for_mumie($tutorial->tutor, $js); } $tutorial->tutor = $tutorial->tutor->syncid; } else { //no tutor => insert dummy $tutorial->tutor = 'moodle-dummy_tutor'; } $tutorial->classid = $insert->syncid; insert_tutorial_for_mumie($tutorial, $js); if ($tutorial->students) { foreach ($tutorial->students as $student) { //perhaps MUMIE already knows this student so we first check $studentexists = check_student($student); if (!$studentexists) { insert_user_for_mumie($student, $js); } add_user_to_mumie_tutorial($student->syncid, $tutorial->syncid, $js); } } } } }