protected static function validate_lesson($lessonid) {
        global $DB, $USER;

        // Request and permission validation.
        $lessonrecord = $DB->get_record('lesson', array('id' => $lessonid), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($lessonrecord, 'lesson');

        $lesson = new lesson($lessonrecord, $cm, $course);
        $lesson->update_effective_access($USER->id);

        $context = $lesson->context;
        self::validate_context($context);

        return array($lesson, $course, $cm, $context, $lessonrecord);
    }