Beispiel #1
0
/**
 * Update all PM information for the provided user
 *
 * @param int $mdluserid the id of the Moodle user we want to migrate
 * @return boolean true on success, otherwise false
 */
function pm_update_user_information($mdluserid)
{
    $status = true;
    //create the PM user if necessary, regardless of time modified
    $status = pm_migrate_moodle_users(false, 0, $mdluserid) && $status;
    //sync enrolments and pass ones with sufficient grades and passed LOs
    $status = pm_update_student_progress($mdluserid) && $status;
    $pmuserid = pm_get_crlmuserid($mdluserid);
    if ($pmuserid != false) {
        //delete orphaned class - Moodle course associations the user is enrolled in
        $status = pmclass::check_for_moodle_courses($pmuserid) && $status;
        //fail users who took to long to complete classes
        $status = pm_update_student_enrolment($pmuserid) && $status;
    }
    return $status;
}
 /**
  * Validate that the pm_update_student_progress method respects its userid parameter, i.e. can run only for a specific user.
  * @param array $userids List of moodle user ids to test with.
  * @param array $itemgrades List of grade item grades to test with.
  * @dataProvider dataprovider_updatestudentprogress
  */
 public function test_pmupdatestudentprogressrespectsuseridparameter($userids, $itemgrades)
 {
     global $DB;
     // Set up data.
     $this->fixture_moodleenrol($userids, $itemgrades);
     // Perform the sync for the first user.
     pm_update_student_progress(100);
     // We should have one passed student in the PM class instance and that student should be the first user.
     $completedenrolments = $DB->get_records(student::TABLE, array('completestatusid' => STUSTATUS_PASSED, 'userid' => 103));
     $this->assertEquals(1, count($completedenrolments));
     $enrolment = reset($completedenrolments);
     $this->assertEquals(103, $enrolment->userid);
     $this->assertEquals(100, $enrolment->grade);
     // We should have one passed learning objective for the first user.
     $completedelements = $DB->get_records(student_grade::TABLE, array('locked' => 1, 'userid' => 103));
     $this->assertEquals(1, count($completedelements));
     $element = reset($completedelements);
     $this->assertEquals(103, $element->userid);
     $this->assertEquals(100, $element->grade);
 }