original_string: public static function instance($categoryid, $strictness = MUST_EXIST) {
          global $DB;
  
          if ($context = context::cache_get(CONTEXT_COURSECAT, $categoryid)) {
              return $context;
          }
  
          if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSECAT, 'instanceid' => $categoryid))) {
              if ($category = $DB->get_record('course_categories', array('id' => $categoryid), 'id,parent', $strictness)) {
                  if ($category->parent) {
                      $parentcontext = context_coursecat::instance($category->parent);
                      $record = context::insert_context_record(CONTEXT_COURSECAT, $category->id, $parentcontext->path);
                  } else {
                      $record = context::insert_context_record(CONTEXT_COURSECAT, $category->id, '/'.SYSCONTEXTID, 0);
                  }
              }
          }
  
          if ($record) {
              $context = new context_coursecat($record);
              context::cache_add($context);
              return $context;
          }
  
          return false;
      }
code: public static function instance($categoryid, $strictness = MUST_EXIST) {
          global $DB;
  
          if ($context = context::cache_get(CONTEXT_COURSECAT, $categoryid)) {
              return $context;
          }
  
          if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSECAT, 'instanceid' => $categoryid))) {
              if ($category = $DB->get_record('course_categories', array('id' => $categoryid), 'id,parent', $strictness)) {
                  if ($category->parent) {
                      $parentcontext = context_coursecat::instance($category->parent);
                      $record = context::insert_context_record(CONTEXT_COURSECAT, $category->id, $parentcontext->path);
                  } else {
                      $record = context::insert_context_record(CONTEXT_COURSECAT, $category->id, '/'.SYSCONTEXTID, 0);
                  }
              }
          }
  
          if ($record) {
              $context = new context_coursecat($record);
              context::cache_add($context);
              return $context;
          }
  
          return false;
      }
code_tokens: public static function instance ( $ categoryid , $ strictness = MUST_EXIST ) { global $ DB ; if ( $ context = context :: cache_get ( CONTEXT_COURSECAT , $ categoryid ) ) { return $ context ; } if ( ! $ record = $ DB -> get_record ( 'context' , array ( 'contextlevel' => CONTEXT_COURSECAT , 'instanceid' => $ categoryid ) ) ) { if ( $ category = $ DB -> get_record ( 'course_categories' , array ( 'id' => $ categoryid ) , 'id,parent' , $ strictness ) ) { if ( $ category -> parent ) { $ parentcontext = context_coursecat :: instance ( $ category -> parent ) ; $ record = context :: insert_context_record ( CONTEXT_COURSECAT , $ category -> id , $ parentcontext -> path ) ; } else { $ record = context :: insert_context_record ( CONTEXT_COURSECAT , $ category -> id , '/' . SYSCONTEXTID , 0 ) ; } } } if ( $ record ) { $ context = new context_coursecat ( $ record ) ; context :: cache_add ( $ context ) ; return $ context ; } return false ; }
docstring: Returns course category context instance.
  
  @static
  @param int $categoryid id from {course_categories} table
  @param int $strictness
  @return context_coursecat context instance
docstring_tokens: Returns course category context instance .