'Construct an OptionsWidget for the fact layer
@param options: the report options
@param get_vars: the GET vars if the request (as dict)
@param widget_id: the HTML element ID for the widget'

def layer_options(self, options=None, get_vars=None, widget_id=None):

    resource = self.resource
    all_methods = S3PivotTableFact.METHODS
    layers = None
    methods = None
    if options:
        if ('methods' in options):
            methods = options['methods']
        if ('fact' in options):
            layers = options['fact']
    if (not layers):
        layers = resource.get_config('list_fields')
    if (not layers):
        layers = [f.name for f in resource.readable_fields()]
    if (not methods):
        methods = all_methods
    T = current.T
    RECORDS = T('Records')
    mname = S3PivotTableFact._get_method_label
    def layer_label(rfield, method):
        '    Helper    to    construct    a    layer    label    '
        mlabel = mname(method)
        flabel = (rfield.label if (rfield.label != 'Id') else RECORDS)
        return (T('%s    (%s)') % (flabel, mlabel))
    prefix = resource.prefix_selector
    layer_opts = []
    for option in layers:
        if isinstance(option, tuple):
            (title, layer) = option
        else:
            (title, layer) = (None, option)
        try:
            facts = S3PivotTableFact.parse(layer)
        except SyntaxError:
            continue
        if (len(facts) > 1):
            labels = []
            expressions = []
            for fact in facts:
                if (not title):
                    rfield = resource.resolve_selector(fact.selector)
                    labels.append(fact.get_label(rfield, layers))
                expressions.append(('%s(%s)' % (fact.method, fact.selector)))
            if (not title):
                title = '    /    '.join(labels)
            layer_opts.append((','.join(expressions), title))
            continue
        else:
            fact = facts[0]
        label = (fact.label or title)
        if fact.default_method:
            (s, m) = (fact.selector, None)
        else:
            (s, m) = (fact.selector, fact.method)
        selector = prefix(s)
        rfield = resource.resolve_selector(selector)
        if ((not rfield.field) and (not rfield.virtual)):
            continue
        if ((m is None) and label):
            rfield.label = label
        if (m is None):
            is_amount = None
            ftype = rfield.ftype
            if (ftype == 'integer'):
                is_amount = True
                requires = rfield.requires
                if (not isinstance(requires, (list, tuple))):
                    requires = [requires]
                for r in requires:
                    if (isinstance(r, IS_IN_SET) or (isinstance(r, IS_EMPTY_OR) and isinstance(r.other, IS_IN_SET))):
                        is_amount = False
            elif (ftype == 'double'):
                is_amount = True
            elif ((ftype[:9] == 'reference') or (ftype[:5] == 'list:') or (ftype in ('id', 'string', 'text'))):
                is_amount = False
            if (ftype in ('datetime', 'date', 'time')):
                mopts = ['min', 'max', 'list']
            elif (is_amount is None):
                mopts = ['sum', 'min', 'max', 'avg', 'count', 'list']
            elif is_amount:
                mopts = ['sum', 'min', 'max', 'avg']
            else:
                mopts = ['count', 'list']
            for method in mopts:
                if (method in methods):
                    label = layer_label(rfield, method)
                    layer_opts.append((('%s(%s)' % (method, selector)), label))
        else:
            if (label is None):
                label = layer_label(rfield, m)
            layer_opts.append((('%s(%s)' % (m, selector)), label))
    if (get_vars and ('fact' in get_vars)):
        layer = get_vars['fact']
    else:
        layer = ''
    if layer:
        match = LAYER.match(layer)
        if (match is None):
            layer = ''
        else:
            (selector, method) = (match.group(2), match.group(1))
            selector = prefix(selector)
            layer = ('%s(%s)' % (method, selector))
    if (len(layer_opts) == 1):
        default = layer_opts[0]
        widget = TAG[''](default[1], INPUT(_type='hidden', _id=widget_id, _name=widget_id, _value=default[0], _class='pt-fact-single-option'))
    else:
        dummy_field = Storage(name='fact', requires=IS_IN_SET(layer_opts))
        widget = OptionsWidget.widget(dummy_field, layer, _id=widget_id, _name='fact', _class='pt-fact')
    return widget
