protected static function validate_feedback($feedbackid, $courseid = 0) {
        global $DB, $USER;

        // Request and permission validation.
        $feedback = $DB->get_record('feedback', array('id' => $feedbackid), '*', MUST_EXIST);
        list($feedbackcourse, $cm) = get_course_and_cm_from_instance($feedback, 'feedback');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        // Set default completion course.
        $completioncourse = (object) array('id' => 0);
        if ($feedbackcourse->id == SITEID && $courseid) {
            $completioncourse = get_course($courseid);
            self::validate_context(context_course::instance($courseid));

            $feedbackcompletion = new mod_feedback_completion($feedback, $cm, $courseid);
            if (!$feedbackcompletion->check_course_is_mapped()) {
                throw new moodle_exception('cannotaccess', 'mod_feedback');
            }
        }

        return array($feedback, $feedbackcourse, $cm, $context, $completioncourse);
    }
protected static function validate_feedback($feedbackid, $courseid = 0) {
        global $DB, $USER;

        // Request and permission validation.
        $feedback = $DB->get_record('feedback', array('id' => $feedbackid), '*', MUST_EXIST);
        list($feedbackcourse, $cm) = get_course_and_cm_from_instance($feedback, 'feedback');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        // Set default completion course.
        $completioncourse = (object) array('id' => 0);
        if ($feedbackcourse->id == SITEID && $courseid) {
            $completioncourse = get_course($courseid);
            self::validate_context(context_course::instance($courseid));

            $feedbackcompletion = new mod_feedback_completion($feedback, $cm, $courseid);
            if (!$feedbackcompletion->check_course_is_mapped()) {
                throw new moodle_exception('cannotaccess', 'mod_feedback');
            }
        }

        return array($feedback, $feedbackcourse, $cm, $context, $completioncourse);
    }
protected static function validate_feedback ( $ feedbackid , $ courseid = 0 ) { global $ DB , $ USER ; // Request and permission validation. $ feedback = $ DB -> get_record ( 'feedback' , array ( 'id' => $ feedbackid ) , '*' , MUST_EXIST ) ; list ( $ feedbackcourse , $ cm ) = get_course_and_cm_from_instance ( $ feedback , 'feedback' ) ; $ context = context_module :: instance ( $ cm -> id ) ; self :: validate_context ( $ context ) ; // Set default completion course. $ completioncourse = ( object ) array ( 'id' => 0 ) ; if ( $ feedbackcourse -> id == SITEID && $ courseid ) { $ completioncourse = get_course ( $ courseid ) ; self :: validate_context ( context_course :: instance ( $ courseid ) ) ; $ feedbackcompletion = new mod_feedback_completion ( $ feedback , $ cm , $ courseid ) ; if ( ! $ feedbackcompletion -> check_course_is_mapped ( ) ) { throw new moodle_exception ( 'cannotaccess' , 'mod_feedback' ) ; } } return array ( $ feedback , $ feedbackcourse , $ cm , $ context , $ completioncourse ) ; }
Utility function for validating a feedback.

@param int $feedbackid feedback instance id
@param int $courseid courseid course where user completes the feedback (for site feedbacks only)
@return array containing the feedback, feedback course, context, course module and the course where is being completed.
@throws moodle_exception
@since  Moodle 3.3
Utility function for validating a feedback .