original_string: public static function instance($cmid, $strictness = MUST_EXIST) {
          global $DB;
  
          if ($context = context::cache_get(CONTEXT_MODULE, $cmid)) {
              return $context;
          }
  
          if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_MODULE, 'instanceid' => $cmid))) {
              if ($cm = $DB->get_record('course_modules', array('id' => $cmid), 'id,course', $strictness)) {
                  $parentcontext = context_course::instance($cm->course);
                  $record = context::insert_context_record(CONTEXT_MODULE, $cm->id, $parentcontext->path);
              }
          }
  
          if ($record) {
              $context = new context_module($record);
              context::cache_add($context);
              return $context;
          }
  
          return false;
      }
code: public static function instance($cmid, $strictness = MUST_EXIST) {
          global $DB;
  
          if ($context = context::cache_get(CONTEXT_MODULE, $cmid)) {
              return $context;
          }
  
          if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_MODULE, 'instanceid' => $cmid))) {
              if ($cm = $DB->get_record('course_modules', array('id' => $cmid), 'id,course', $strictness)) {
                  $parentcontext = context_course::instance($cm->course);
                  $record = context::insert_context_record(CONTEXT_MODULE, $cm->id, $parentcontext->path);
              }
          }
  
          if ($record) {
              $context = new context_module($record);
              context::cache_add($context);
              return $context;
          }
  
          return false;
      }
code_tokens: public static function instance ( $ cmid , $ strictness = MUST_EXIST ) { global $ DB ; if ( $ context = context :: cache_get ( CONTEXT_MODULE , $ cmid ) ) { return $ context ; } if ( ! $ record = $ DB -> get_record ( 'context' , array ( 'contextlevel' => CONTEXT_MODULE , 'instanceid' => $ cmid ) ) ) { if ( $ cm = $ DB -> get_record ( 'course_modules' , array ( 'id' => $ cmid ) , 'id,course' , $ strictness ) ) { $ parentcontext = context_course :: instance ( $ cm -> course ) ; $ record = context :: insert_context_record ( CONTEXT_MODULE , $ cm -> id , $ parentcontext -> path ) ; } } if ( $ record ) { $ context = new context_module ( $ record ) ; context :: cache_add ( $ context ) ; return $ context ; } return false ; }
docstring: Returns module context instance.
  
  @static
  @param int $cmid id of the record from {course_modules} table; pass cmid there, NOT id in the instance column
  @param int $strictness
  @return context_module context instance
docstring_tokens: Returns module context instance .