protected static function validate_feedback_access($feedback, $course, $cm, $context, $checksubmit = false) {
        $feedbackcompletion = new mod_feedback_completion($feedback, $cm, $course->id);

        if (!$feedbackcompletion->can_complete()) {
            throw new required_capability_exception($context, 'mod/feedback:complete', 'nopermission', '');
        }

        if (!$feedbackcompletion->is_open()) {
            throw new moodle_exception('feedback_is_not_open', 'feedback');
        }

        if ($feedbackcompletion->is_empty()) {
            throw new moodle_exception('no_items_available_yet', 'feedback');
        }

        if ($checksubmit && !$feedbackcompletion->can_submit()) {
            throw new moodle_exception('this_feedback_is_already_submitted', 'feedback');
        }
        return $feedbackcompletion;
    }