Пример #1
0
 /**
  * Validate that the sync from course role assignment to class instance enrolment works
  */
 public function test_enrolled_course_user_syncstoclass()
 {
     global $CFG, $DB;
     require_once elispm::lib('lib.php');
     // Set up import data.
     $this->load_csv_data();
     // Make sure the context is set up.
     $crsctx = context_course::instance(100);
     // Set up our test role.
     $roleid = create_role('gradedrole', 'gradedrole', 'gradedrole');
     set_config('gradebookroles', $roleid);
     // Create role assignments.
     role_assign($roleid, 100, $crsctx->id);
     // Attempt the sync.
     $sync = new \local_elisprogram\moodle\synchronize();
     $sync->synchronize_moodle_class_grades();
     // Make sure the student record was created.
     $student = student::find();
     $this->assertTrue($student->valid());
     // Make sure the student has the right class id.
     $student = $student->current();
     $this->assertEquals(100, $student->classid);
 }
Пример #2
0
/**
 * Get all of the data from Moodle and update the curriculum system.
 * This should do the following:
 *      - Get all Moodle courses connected with classes.
 *      - Get all users in each Moodle course.
 *      - Get grade records from the class's course and completion elements.
 *      - For each user:
 *          - Check if they have an enrolment record in CM, and add if not.
 *          - Update grade information in the enrollment and grade tables in CM.
 *
 * @param int $muserid  optional user to update, default(0) updates all users
 */
function pm_update_student_progress($muserid = 0)
{
    global $CFG;
    require_once $CFG->dirroot . '/grade/lib.php';
    require_once $CFG->dirroot . '/grade/querylib.php';
    /// Get all grades in all relevant courses for all relevant users.
    require_once elispm::lib('data/classmoodlecourse.class.php');
    require_once elispm::lib('data/student.class.php');
    require_once elispm::lib('data/pmclass.class.php');
    require_once elispm::lib('data/course.class.php');
    /// Start with the Moodle classes...
    if ($muserid == 0) {
        if (in_cron()) {
            mtrace("Synchronizing Moodle class grades<br />\n");
        }
    }
    $sync = new \local_elisprogram\moodle\synchronize();
    $sync->synchronize_moodle_class_grades($muserid);
    flush();
    // sleep(1);
    /// Now we need to check all of the student and grade records again, since data may have come from sources
    /// other than Moodle.
    if ($muserid == 0) {
        //running for all users
        if (in_cron()) {
            mtrace("Updating all class grade completions.<br />\n");
        }
        pm_update_enrolment_status();
    } else {
        //attempting to run for a particular user
        $pmuserid = pm_get_crlmuserid($muserid);
        if ($pmuserid != false) {
            //user has a matching PM user
            pm_update_enrolment_status($pmuserid);
        }
    }
    return true;
}
 /**
  * Test the grade synchronisation when there are duplicate course_module.idnumber values present.
  */
 public function test_sync_with_duplicate_course_module_idnumbers()
 {
     global $CFG, $DB;
     $this->load_csv_data();
     $olddebug = null;
     $olddebugdisplay = null;
     // Developer debugging must be enabled and displayed for this test to work.
     if ($CFG->debug < DEBUG_DEVELOPER) {
         $olddebug = $CFG->debug;
         $CFG->debug = DEBUG_DEVELOPER;
     }
     if ($CFG->debugdisplay == false) {
         $olddebugdisplay = false;
         $CFG->debugdisplay = true;
     }
     // Set up grade item and completion item.
     $itemid = $this->create_grade_item('duplicateidnumber');
     $this->create_grade_grade($itemid, 100, 75);
     $completionid = $this->create_course_completion('duplicateidnumber');
     // Insert a couple duplicate course_module 'idnumber' balues but for different course ID values.
     $cmobj = new \stdClass();
     $cmobj->course = 1000;
     $cmobj->module = 20;
     $cmobj->instance = 100;
     $cmobj->section = 1;
     $cmobj->idnumber = 'duplicateidnumber';
     $DB->insert_record('course_modules', $cmobj);
     $cmobj->course = 2000;
     $DB->insert_record('course_modules', $cmobj);
     // Using an output buffer here because the following function will throw a debugging error if more than one record is found.
     ob_start();
     $sync = new \local_elisprogram\moodle\synchronize();
     $sync->synchronize_moodle_class_grades();
     $buffer = ob_get_contents();
     ob_end_clean();
     $this->assertEquals('', $buffer);
     // Restore old values if we modified them in this test.
     if ($olddebug != null) {
         $CFG->debug = $olddebug;
     }
     if ($olddebugdisplay != null) {
         $CFG->debugdisplay = $olddebugdisplay;
     }
 }