コード例 #1
0
 /**
  * Test merging two users where one has submitted an assignment and the other
  * has no.
  */
 public function test_mergenonconflictingassigngrades()
 {
     global $DB;
     $this->setUser($this->editingteachers[0]);
     $assign = $this->create_instance();
     $this->setUser($this->teachers[0]);
     // Give a grade to student 1.
     $data = new stdClass();
     $data->grade = '75.0';
     $assign->testable_apply_grade_to_user($data, $this->students[1]->id, 0);
     // Check initial state - student 0 has no grade, student 1 has 75.00.
     $this->assertEquals(false, $assign->testable_is_graded($this->students[0]->id));
     $this->assertEquals(true, $assign->testable_is_graded($this->students[1]->id));
     $this->assertEquals('75.00', $this->get_user_assign_grade($this->students[1], $assign, $this->course));
     $this->assertEquals('-', $this->get_user_assign_grade($this->students[0], $assign, $this->course));
     // Merge student 1 into student 0.
     $mut = new MergeUserTool();
     $mut->merge($this->students[0]->id, $this->students[1]->id);
     // Student 0 should now have a grade of 75.00.
     $this->assertEquals(true, $assign->testable_is_graded($this->students[0]->id));
     $this->assertEquals('75.00', $this->get_user_assign_grade($this->students[0], $assign, $this->course));
     // Student 1 should now be suspended.
     $user_remove = $DB->get_record('user', array('id' => $this->students[1]->id));
     $this->assertEquals(1, $user_remove->suspended);
 }
コード例 #2
0
 /**
  * Enrol two users on one unique course each and one shared course
  * then merge them.
  */
 public function test_mergeenrolments()
 {
     global $DB;
     // Setup two users to merge.
     $user_remove = $this->getDataGenerator()->create_user();
     $user_keep = $this->getDataGenerator()->create_user();
     // Create three courses.
     $course1 = $this->getDataGenerator()->create_course();
     $course2 = $this->getDataGenerator()->create_course();
     $course3 = $this->getDataGenerator()->create_course();
     $maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $manual = enrol_get_plugin('manual');
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     // Enrol $user_remove on course 1 + 2 and $user_keep on course 2 + 3.
     $manual->enrol_user($maninstance1, $user_remove->id, $studentrole->id);
     $manual->enrol_user($maninstance2, $user_remove->id, $studentrole->id);
     $manual->enrol_user($maninstance2, $user_keep->id, $studentrole->id);
     $manual->enrol_user($maninstance3, $user_keep->id, $studentrole->id);
     // Check initial state of enrolments for $user_remove.
     $courses = enrol_get_all_users_courses($user_remove->id);
     ksort($courses);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course1->id, $course2->id), array_keys($courses));
     // Check initial state of enrolments for $user_keep.
     $courses = enrol_get_all_users_courses($user_keep->id);
     ksort($courses);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
     $mut = new MergeUserTool();
     list($success, $log, $logid) = $mut->merge($user_keep->id, $user_remove->id);
     // Check $user_remove is suspended.
     $user_remove = $DB->get_record('user', array('id' => $user_remove->id));
     $this->assertEquals(1, $user_remove->suspended);
     // Check $user_keep is now enrolled on all three courses.
     $courses = enrol_get_all_users_courses($user_keep->id);
     ksort($courses);
     $this->assertCount(3, $courses);
     $this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
 }
コード例 #3
0
 /**
  * Have two users attempt different quizes and then merge them.
  */
 public function test_mergenonconflictingquizattempts()
 {
     global $DB;
     $this->submit_quiz_attempt($this->quiz1, $this->user_keep, $this->get_fiftypercent_answers());
     $this->submit_quiz_attempt($this->quiz2, $this->user_remove, $this->get_hundredpercent_answers());
     $this->assertEquals('50.00', $this->get_user_quiz_grade($this->user_keep, $this->quiz1, $this->course1));
     $this->assertEquals('-', $this->get_user_quiz_grade($this->user_keep, $this->quiz2, $this->course2));
     $this->assertEquals('-', $this->get_user_quiz_grade($this->user_remove, $this->quiz1, $this->course1));
     $this->assertEquals('100.00', $this->get_user_quiz_grade($this->user_remove, $this->quiz2, $this->course2));
     set_config('quizattemptsaction', QuizAttemptsMerger::ACTION_RENUMBER, 'tool_mergeusers');
     $mut = new MergeUserTool();
     $mut->merge($this->user_keep->id, $this->user_remove->id);
     $this->assertEquals('50.00', $this->get_user_quiz_grade($this->user_keep, $this->quiz1, $this->course1));
     $this->assertEquals('100.00', $this->get_user_quiz_grade($this->user_keep, $this->quiz2, $this->course2));
     $user_remove = $DB->get_record('user', array('id' => $this->user_remove->id));
     $this->assertEquals(1, $user_remove->suspended);
 }
コード例 #4
0
$option = optional_param('option', NULL, PARAM_TEXT);
if (!$option) {
    if (optional_param('clearselection', false, PARAM_TEXT)) {
        $option = 'clearselection';
    } else {
        if (optional_param('mergeusers', false, PARAM_TEXT)) {
            $option = 'mergeusers';
        }
    }
}
// Define the form
$mergeuserform = new mergeuserform();
$renderer = $PAGE->get_renderer('tool_mergeusers');
$data = $mergeuserform->get_data();
//may abort execution if database not supported, for security
$mut = new MergeUserTool();
// Search tool for searching for users and verifying them
$mus = new MergeUserSearch();
// If there was a custom option submitted (by custom form) then use that option
// instead of main form's data
if (!empty($option)) {
    switch ($option) {
        // one or two users are selected: save them into session.
        case 'saveselection':
            //get and verify the userids from the selection form usig the verify_user function (second field is column)
            list($olduser, $oumessage) = $mus->verify_user(optional_param('olduser', NULL, PARAM_INT), 'id');
            list($newuser, $numessage) = $mus->verify_user(optional_param('newuser', NULL, PARAM_INT), 'id');
            if ($olduser === NULL && $newuser === NULL) {
                $renderer->mu_error(get_string('no_saveselection', 'tool_mergeusers'));
                exit;
                // end execution for error