Example #1
0
/**
 * Function to handle the category_deleted-event
 * 
 * @param object $eventdata - the event's data
 */
function category_deleted_handler($eventdata)
{
    global $CFG;
    $isinteresting = false;
    //we assume that this is not relevant - check!
    //if there is no class with an instance of mumiemodule in the parent category, then we can be sure that this event is not interesting
    //but if there is at least one, we can not be sure - so we better try to send all information
    if ($cat_classes = get_courses($semester->parent, 'c.id')) {
        foreach ($cat_classes as $cat_class) {
            if (record_exists('mumiemodule', 'course', $cat_class->id)) {
                $isinteresting = true;
                break;
            }
        }
    }
    if ($isinteresting) {
        event_logoutput("category_deleted_handler called \n", $eventdata);
        $js = new JapsSynchronise();
        $deletedsem = new object();
        $deletedsem->syncid = 'moodle-' . $CFG->prefix . 'course_categories-' . $eventdata->id;
        $deletedsem->parent = 'moodle-' . $CFG->prefix . 'course_categories-' . $eventdata->parent;
        //we try to insert the parent-category as a new semester into MUMIE
        $cat = get_record('course_categories', 'id', $eventdata->parent, '', '', '', '', 'name');
        $newsemester = new object();
        $newsemester->syncid = $deletedsem->parent;
        $newsemester->name = $cat->name;
        $newsemester->description = 'a Moodle-category as semester';
        insert_semester_for_mumie($newsemester, $js);
        //the courses were moved from the deleted category into the parent category
        //so we have to change them before deleting the category
        if ($cat_classes = get_courses($semester->parent, $fields = 'c.id')) {
            //TODO: isn't this deprecated???
            foreach ($cat_classes as $cat_class) {
                if (record_exists('mumiemodule', 'course', $cat_class->id)) {
                    $classtochange = new object();
                    $classtochange->syncid = 'moodle-' . $CFG->prefix . 'course-' . $cat_class->id;
                    $classtochange->semester = $deletedsem->parent;
                    change_class_for_mumie($classtochange, $js);
                }
            }
        }
        //delete_semester_for_mumie($deletedsem);
    }
    return true;
}
Example #2
0
/**
 * 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);
                }
            }
        }
    }
}