/** * Function to handle the course_updated-event * * @param object $eventdata - the event's data */ function course_updated_handler($eventdata) { global $CFG; //check if the course is relevant if (record_exists('mumiemodule', 'course', $eventdata->id)) { event_logoutput("course_updated_handler called \n", $eventdata); $class = new object(); $class->syncid = 'moodle-' . $CFG->prefix . 'course-' . $eventdata->id; $class->name = $eventdata->fullname; $class->description = $eventdata->summary; $class->semester = 'moodle-' . $CFG->prefix . 'course_categories-' . $eventdata->category; //perhaps the course has been put into another category, so we better check if MUMIE knows $semester = new object(); $semester->syncid = $eventdata->category; $semester->name = get_field('course_categories', 'name', 'id', $eventdata->category); $semester->description = 'a Moodle-category as semester'; if (!check_semester($semester)) { $js = new JapsSynchronise(); insert_semester_for_mumie($semester, $js); change_class_for_mumie($class, $js); } else { //lecturers can not be changed here change_class_for_mumie($class); } } 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); } } } } }