public static function instance($courseid, $strictness = MUST_EXIST) {
        global $DB;

        if ($context = context::cache_get(CONTEXT_COURSE, $courseid)) {
            return $context;
        }

        if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $courseid))) {
            if ($course = $DB->get_record('course', array('id' => $courseid), 'id,category', $strictness)) {
                if ($course->category) {
                    $parentcontext = context_coursecat::instance($course->category);
                    $record = context::insert_context_record(CONTEXT_COURSE, $course->id, $parentcontext->path);
                } else {
                    $record = context::insert_context_record(CONTEXT_COURSE, $course->id, '/'.SYSCONTEXTID, 0);
                }
            }
        }

        if ($record) {
            $context = new context_course($record);
            context::cache_add($context);
            return $context;
        }

        return false;
    }
public static function instance($courseid, $strictness = MUST_EXIST) {
        global $DB;

        if ($context = context::cache_get(CONTEXT_COURSE, $courseid)) {
            return $context;
        }

        if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $courseid))) {
            if ($course = $DB->get_record('course', array('id' => $courseid), 'id,category', $strictness)) {
                if ($course->category) {
                    $parentcontext = context_coursecat::instance($course->category);
                    $record = context::insert_context_record(CONTEXT_COURSE, $course->id, $parentcontext->path);
                } else {
                    $record = context::insert_context_record(CONTEXT_COURSE, $course->id, '/'.SYSCONTEXTID, 0);
                }
            }
        }

        if ($record) {
            $context = new context_course($record);
            context::cache_add($context);
            return $context;
        }

        return false;
    }
public static function instance ( $ courseid , $ strictness = MUST_EXIST ) { global $ DB ; if ( $ context = context :: cache_get ( CONTEXT_COURSE , $ courseid ) ) { return $ context ; } if ( ! $ record = $ DB -> get_record ( 'context' , array ( 'contextlevel' => CONTEXT_COURSE , 'instanceid' => $ courseid ) ) ) { if ( $ course = $ DB -> get_record ( 'course' , array ( 'id' => $ courseid ) , 'id,category' , $ strictness ) ) { if ( $ course -> category ) { $ parentcontext = context_coursecat :: instance ( $ course -> category ) ; $ record = context :: insert_context_record ( CONTEXT_COURSE , $ course -> id , $ parentcontext -> path ) ; } else { $ record = context :: insert_context_record ( CONTEXT_COURSE , $ course -> id , '/' . SYSCONTEXTID , 0 ) ; } } } if ( $ record ) { $ context = new context_course ( $ record ) ; context :: cache_add ( $ context ) ; return $ context ; } return false ; }
Returns course context instance.

@static
@param int $courseid id from {course} table
@param int $strictness
@return context_course context instance
Returns course context instance .