diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index c8e031d6c2a..a5697b50ee5 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -1205,4 +1205,26 @@ EOD; return $user; } + + /** + * Create a new last access record for a given user in a course. + * + * @param \stdClass $user The user + * @param \stdClass $course The course the user accessed + * @param int $timestamp The timestamp for when the user last accessed the course + * @return \stdClass The user_lastaccess record + */ + public function create_user_course_lastaccess(\stdClass $user, \stdClass $course, int $timestamp): \stdClass { + global $DB; + + $record = [ + 'userid' => $user->id, + 'courseid' => $course->id, + 'timeaccess' => $timestamp, + ]; + + $recordid = $DB->insert_record('user_lastaccess', $record); + + return $DB->get_record('user_lastaccess', ['id' => $recordid], '*', MUST_EXIST); + } }