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);
    }
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);
    }
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 ) ; }
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
Checks if current user has access to the category