Line 0
Link Here
|
|
|
1 |
package Koha::Object::ColumnSet; |
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
use Data::Dumper qw( Dumper ); |
20 |
|
21 |
use Koha::AllowList; |
22 |
|
23 |
=head1 NAME |
24 |
|
25 |
Koha::Object::ColumnSet |
26 |
|
27 |
=head1 API |
28 |
|
29 |
=head2 Class Methods |
30 |
|
31 |
=head3 new |
32 |
|
33 |
Constructor. |
34 |
|
35 |
=cut |
36 |
|
37 |
sub new { |
38 |
my ( $class, $params ) = @_; # parameter hash keys: rs, name |
39 |
my $self = bless( $params, $class ); |
40 |
$self->_get_column_set; |
41 |
return $self; |
42 |
} |
43 |
|
44 |
sub _get_column_set { |
45 |
my ( $self ) = @_; |
46 |
my $rs = $self->{rs} or return; |
47 |
my $name = $self->{name} or return; |
48 |
|
49 |
if( $rs->can('get_column_set') ) { |
50 |
if( my $list = $rs->get_column_set($name) ) { |
51 |
$self->{_list} = $list; |
52 |
$self->{_allowlist} = Koha::AllowList->new({ defaults => $list }); |
53 |
} |
54 |
} |
55 |
} |
56 |
|
57 |
=head3 apply_filter |
58 |
|
59 |
$set->apply_filter({ data => $data }); |
60 |
|
61 |
Apply column set filter to $data. |
62 |
If you did not pass $data, it will apply to the resultset data. |
63 |
|
64 |
=cut |
65 |
|
66 |
sub apply_filter { |
67 |
my ( $self, $params ) = @_; |
68 |
return if !$self->{_list}; |
69 |
my $data = $params->{data} // { $self->{rs}->get_columns }; |
70 |
return $self->{_allowlist}->apply({ input => $data }); |
71 |
} |
72 |
|
73 |
=head3 list_columns |
74 |
|
75 |
$set->list_columns |
76 |
|
77 |
=cut |
78 |
|
79 |
sub list_columns { |
80 |
my ( $self ) = @_; |
81 |
return $self->{_list}; |
82 |
} |
83 |
|
84 |
1; |