original_string: public static function can_view_category($category, $user = null) {
          if (!$category->id) {
              return has_capability('moodle/category:viewcourselist', context_system::instance(), $user);
          }
          $context = context_coursecat::instance($category->id);
          if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', $context, $user)) {
              return false;
          }
          return has_capability('moodle/category:viewcourselist', $context, $user);
      }
code: public static function can_view_category($category, $user = null) {
          if (!$category->id) {
              return has_capability('moodle/category:viewcourselist', context_system::instance(), $user);
          }
          $context = context_coursecat::instance($category->id);
          if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', $context, $user)) {
              return false;
          }
          return has_capability('moodle/category:viewcourselist', $context, $user);
      }
code_tokens: public static function can_view_category ( $ category , $ user = null ) { if ( ! $ category -> id ) { return has_capability ( 'moodle/category:viewcourselist' , context_system :: instance ( ) , $ user ) ; } $ context = context_coursecat :: instance ( $ category -> id ) ; if ( ! $ category -> visible && ! has_capability ( 'moodle/category:viewhiddencategories' , $ context , $ user ) ) { return false ; } return has_capability ( 'moodle/category:viewcourselist' , $ context , $ user ) ; }
docstring: Checks if current user has access to the category
  
  @param stdClass|core_course_category $category
  @param int|stdClass $user The user id or object. By default (null) checks access for the current user.
  @return bool
docstring_tokens: Checks if current user has access to the category