public static function get_sql($userid, $capability) {
        // Get a tree of capability permission at various contexts for current user.
        $root = self::get_tree($userid, $capability);

        // The root node always has permission false. If there are no child nodes then the user
        // cannot access anything.
        if (!$root->children) {
            return [false, false];
        }

        // Get SQL to limit contexts based on the permission tree.
        return self::create_sql($root);

    }