/** * 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; }
/** * Validate that the pm_update_enrolment_status method respects its userid parameter, i.e. it can run only for a specific user. * NOTE: this unit test does not test all cases because that should be specifically tested for $pmclass->update_enrolment_status * * @param array $enrolments A list of class enrolment records we are processing * @param array $classgraded A list of learning objective grades we are processing * @dataProvider dataprovider_updatedelegation */ public function test_pmupdateenrolmentstatusrespectsuseridparameter($enrolments, $classgraded) { global $DB; // Necessary data. $this->load_csv_data(); foreach ($enrolments as $key => $enrolment) { // Create student enrolment. $record = new student($enrolment); $record->save(); } foreach ($classgraded as $lograde) { // Create learning objective grade. $record = new student_grade($lograde); $record->save(); } // Pass the appropriate student. pm_update_enrolment_status(2); // We should have one passed student in the PM class instance, and that student should be the second user. $enrolments = $DB->get_records(student::TABLE, array('completestatusid' => STUSTATUS_PASSED)); $this->assertEquals(1, count($enrolments)); $enrolment = reset($enrolments); $this->assertEquals(100, $enrolment->classid); $this->assertEquals(2, $enrolment->userid); $this->assertEquals(100, $enrolment->grade); }
/** * Test enrolment functions using an invalid class ID. */ public function test_enrolment_with_invalid_classid() { global $CFG, $DB; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elispm::lib('lib.php'); $this->load_csv_data(); $enrolment = new stdClass(); $enrolment->classid = 1000; // Invalid class ID. $enrolment->userid = 103; $enrolment->enrolmenttime = time(); $enrolment->completetime = 0; $enrolment->endtime = 0; $enrolment->completestatusid = 0; $enrolment->grade = 0; $enrolment->credits = 0.0; $enrolment->locked = 0; // Directly insert the record to bypass 'student' class validation on the classid. $this->assertGreaterThan(0, $DB->insert_record(student::TABLE, $enrolment)); // Attempt to update status before the required learning objective is satisfied. // ELIS-4955 -- This should ignore the bad data and proceed without error. pm_update_enrolment_status(); // Validate that the enrolment is still in progress. $sturecord = new student(100); $this->assertEquals(STUSTATUS_NOTCOMPLETE, $sturecord->completestatusid); $this->assertEquals(0, $sturecord->locked); // Satisfy the required learning objective. $graderecord = new student_grade(1); $graderecord->grade = 80; $graderecord->save(); // Attempt to update status now that the required learning objective is satisfied. pm_update_enrolment_status(); // Validate that the enrolment is passed. $sturecord = new student(100); $this->assertEquals(STUSTATUS_PASSED, $sturecord->completestatusid); $this->assertEquals(1, $sturecord->locked); }
$ce_check = array(); if ($rs = get_recordset_sql($sql)) { while ($completion = rs_fetch_next_record($rs)) { $dangling_total++; $completion->locked = 1; // Make sure a timemodified value is set, just in case if ($completion->timemodified == 0) { $completion->timemodified = $timenow; } if (update_record(GRDTABLE, $completion)) { $dangling_fixed++; } } rs_close($rs); } */ $a = new stdClass(); $a->fixed = $dangling_fixed; $a->total = $dangling_total; mtrace(' >>> ' . get_string('health_dangling_fixed_counts', 'local_elisprogram', $a)); if ($dangling_fixed > 0) { // Make a note that class grades are being recalculated mtrace(' >>> ' . get_string('health_dangling_recalculate', 'local_elisprogram'), ''); pm_update_enrolment_status(); mtrace(get_string('done', 'local_elisprogram') . '!'); }