Reputation: 3091
I am new to Moodle and I am working on an old application, here are the specs:
$version = 2016120502.05;
$release = '3.2.2+ (Build: 20170407)';
$branch = '32';
My ultimate goal is to be able to create a generator class to create dummy data for some PHPUnit unit tests. (https://docs.moodle.org/dev/Writing_PHPUnit_tests) I found that there is a prebuilt one for creating courses and users. But I need to be able to also mark them complete in the course with their grades.
I was looking at this https://docs.moodle.org/dev/Gradebook_API which might be at least part of what I need. However, there are lots of tables in the system, and I'm not confident that this is what I need.
Here is my code up until this last point:
// Create user;
$this->user = $this->getDataGenerator()->create_user();
// Create courses.
$courseCount = 0;
$courses = [];
while ($courseCount < 5) {
$courses[] = $this->getDataGenerator()->create_course();
$courseCount++;
}
/** @var \myGlobal_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('myGlobal_generator');
// Create curriculum.
$this->curriculum = $generator->createCurriculum($courses);
// Now we need to set a user to have completed each one
// of the courses and set their grades for each as well.
Upvotes: 0
Views: 1069
Reputation: 453
Notice that grading and completion tracking are not necessarily related things. For example, you can mark activities and courses as completed without any grading involved, like so:
$cmassign = get_coursemodule_from_id('assign', $cmid);
$completion = new completion_info($course);
$completion->update_state($cmassign, COMPLETION_COMPLETE, $user->id);
$ccompletion = new completion_completion(['course' => $course->id, 'userid' => $user->id]);
$ccompletion->mark_complete();
If you really need to test/generate data with grading and grade-based completion you may need to code it along this lines:
grade_update
.$completion->internal_get_state
)Upvotes: 1