/** * Adds students to the mumiemodule * * @param integer $userid - the ID of the user * @param integer $mumiemodule - the ID of the mumiemodule * @param bool $morethanone - true if there is at least one more mumiemodule-instance within this course * @param object $mumie_group - the group in which to subscribe */ function mumiemodule_students_subscribe($userid, $mumiemoduleid, $mumie_group, $morethanone = false) { global $CFG; global $COURSE; if (record_exists("mumiemodule_students", "mumiemodule", $mumiemoduleid, "userid", $userid, "group", $mumie_group->id)) { return true; } $ins = new object(); $ins->mumiemodule = $mumiemoduleid; $ins->userid = $userid; $ins->groupid = $mumie_group->id; $ins->timemodified = time(); //does the MUMIE already know the user? $studenttocheck = new object(); $studenttocheck->syncid = 'moodle-' . $CFG->prefix . 'user-' . $userid; $userexists = check_student($studenttocheck); //now we can insert the user into DB $newid = insert_record("mumiemodule_students", $ins); if ($newid) { if (!$morethanone && !$userexists) { //MUMIE does not know this user yet $newuser = get_record('user', 'id', $userid); send_single_user_to_mumie($newuser); } $group_sync_id = 'moodle-' . $CFG->prefix . 'groups-' . $mumie_group->id; $user_sync_id = 'moodle-' . $CFG->prefix . 'user-' . $newuser->id; add_user_to_mumie_tutorial($user_sync_id, $group_sync_id); } return $newid; }
/** * 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); } } } } }