summaryrefslogtreecommitdiffstats
path: root/extensions/BugmailFilter/lib/FakeField.pm
blob: e9f8b180855d5ee38edf804cfade82b31d7e7ae8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::BugmailFilter::FakeField;

use 5.10.1;
use strict;
use warnings;

use Bugzilla::Extension::BugmailFilter::Constants;

# object

sub new {
    my ($class, $params) = @_;
    return bless($params, $class);
}

sub name        { $_[0]->{name} }
sub description { $_[0]->{description} }

# static methods

sub fake_fields {
    my $cache = Bugzilla->request_cache->{bugmail_filter};
    if (!$cache->{fake_fields}) {
        my @fields;
        foreach my $rh (@{ FAKE_FIELD_NAMES() }) {
            push @fields, Bugzilla::Extension::BugmailFilter::FakeField->new($rh);
        }
        $cache->{fake_fields} = \@fields;
    }
    return $cache->{fake_fields};
}

sub tracking_flag_fields {
    my $cache = Bugzilla->request_cache->{bugmail_filter};
    if (!$cache->{tracking_flag_fields}) {
        require Bugzilla::Extension::TrackingFlags::Constants;
        my @fields;
        my $tracking_types = Bugzilla::Extension::TrackingFlags::Constants::FLAG_TYPES();
        foreach my $tracking_type (@$tracking_types) {
            push @fields, Bugzilla::Extension::BugmailFilter::FakeField->new({
                name        => 'tracking.' . $tracking_type->{name},
                description => $tracking_type->{description},
                sortkey     => $tracking_type->{sortkey},
            });
        }
        $cache->{tracking_flag_fields} = \@fields;
    }
    return $cache->{tracking_flag_fields};
}

1;