original_string: public static function get($id, $strictness = MUST_EXIST, $alwaysreturnhidden = false, $user = null) {
          if (!$id) {
              // Top-level category.
              if ($alwaysreturnhidden || self::top()->is_uservisible()) {
                  return self::top();
              }
              if ($strictness == MUST_EXIST) {
                  throw new moodle_exception('cannotviewcategory');
              }
              return null;
          }
  
          // Try to get category from cache or retrieve from the DB.
          $coursecatrecordcache = cache::make('core', 'coursecatrecords');
          $coursecat = $coursecatrecordcache->get($id);
          if ($coursecat === false) {
              if ($records = self::get_records('cc.id = :id', array('id' => $id))) {
                  $record = reset($records);
                  $coursecat = new self($record);
                  // Store in cache.
                  $coursecatrecordcache->set($id, $coursecat);
              }
          }
  
          if (!$coursecat) {
              // Course category not found.
              if ($strictness == MUST_EXIST) {
                  throw new moodle_exception('unknowncategory');
              }
              $coursecat = null;
          } else if (!$alwaysreturnhidden && !$coursecat->is_uservisible($user)) {
              // Course category is found but user can not access it.
              if ($strictness == MUST_EXIST) {
                  throw new moodle_exception('cannotviewcategory');
              }
              $coursecat = null;
          }
          return $coursecat;
      }
code: public static function get($id, $strictness = MUST_EXIST, $alwaysreturnhidden = false, $user = null) {
          if (!$id) {
              // Top-level category.
              if ($alwaysreturnhidden || self::top()->is_uservisible()) {
                  return self::top();
              }
              if ($strictness == MUST_EXIST) {
                  throw new moodle_exception('cannotviewcategory');
              }
              return null;
          }
  
          // Try to get category from cache or retrieve from the DB.
          $coursecatrecordcache = cache::make('core', 'coursecatrecords');
          $coursecat = $coursecatrecordcache->get($id);
          if ($coursecat === false) {
              if ($records = self::get_records('cc.id = :id', array('id' => $id))) {
                  $record = reset($records);
                  $coursecat = new self($record);
                  // Store in cache.
                  $coursecatrecordcache->set($id, $coursecat);
              }
          }
  
          if (!$coursecat) {
              // Course category not found.
              if ($strictness == MUST_EXIST) {
                  throw new moodle_exception('unknowncategory');
              }
              $coursecat = null;
          } else if (!$alwaysreturnhidden && !$coursecat->is_uservisible($user)) {
              // Course category is found but user can not access it.
              if ($strictness == MUST_EXIST) {
                  throw new moodle_exception('cannotviewcategory');
              }
              $coursecat = null;
          }
          return $coursecat;
      }
code_tokens: public static function get ( $ id , $ strictness = MUST_EXIST , $ alwaysreturnhidden = false , $ user = null ) { if ( ! $ id ) { // Top-level category. if ( $ alwaysreturnhidden || self :: top ( ) -> is_uservisible ( ) ) { return self :: top ( ) ; } if ( $ strictness == MUST_EXIST ) { throw new moodle_exception ( 'cannotviewcategory' ) ; } return null ; } // Try to get category from cache or retrieve from the DB. $ coursecatrecordcache = cache :: make ( 'core' , 'coursecatrecords' ) ; $ coursecat = $ coursecatrecordcache -> get ( $ id ) ; if ( $ coursecat === false ) { if ( $ records = self :: get_records ( 'cc.id = :id' , array ( 'id' => $ id ) ) ) { $ record = reset ( $ records ) ; $ coursecat = new self ( $ record ) ; // Store in cache. $ coursecatrecordcache -> set ( $ id , $ coursecat ) ; } } if ( ! $ coursecat ) { // Course category not found. if ( $ strictness == MUST_EXIST ) { throw new moodle_exception ( 'unknowncategory' ) ; } $ coursecat = null ; } else if ( ! $ alwaysreturnhidden && ! $ coursecat -> is_uservisible ( $ user ) ) { // Course category is found but user can not access it. if ( $ strictness == MUST_EXIST ) { throw new moodle_exception ( 'cannotviewcategory' ) ; } $ coursecat = null ; } return $ coursecat ; }
docstring: Returns coursecat object for requested category
  
  If category is not visible to the given user, it is treated as non existing
  unless $alwaysreturnhidden is set to true
  
  If id is 0, the pseudo object for root category is returned (convenient
  for calling other functions such as get_children())
  
  @param int $id category id
  @param int $strictness whether to throw an exception (MUST_EXIST) or
  return null (IGNORE_MISSING) in case the category is not found or
  not visible to current user
  @param bool $alwaysreturnhidden set to true if you want an object to be
  returned even if this category is not visible to the current user
  (category is hidden and user does not have
  'moodle/category:viewhiddencategories' capability). Use with care!
  @param int|stdClass $user The user id or object. By default (null) checks the visibility to the current user.
  @return null|self
  @throws moodle_exception
docstring_tokens: Returns coursecat object for requested category