Lines 18-23
package Koha::Patron::Attributes;
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Koha::Patron::Attribute; |
20 |
use Koha::Patron::Attribute; |
|
|
21 |
use Koha::Patron::Attribute::Types; |
21 |
|
22 |
|
22 |
use base qw(Koha::Objects); |
23 |
use base qw(Koha::Objects); |
23 |
|
24 |
|
Lines 33-67
Koha::Patron::Attributes - Koha Patron Attributes Object set class
Link Here
|
33 |
|
34 |
|
34 |
=head3 search |
35 |
=head3 search |
35 |
|
36 |
|
36 |
my $attributes-> Koha::Patron::Attributes->search( $params ); |
37 |
my $attributes = Koha::Patron::Attributes->search( $params ); |
37 |
|
38 |
|
38 |
=cut |
39 |
=cut |
39 |
|
40 |
|
40 |
sub search { |
41 |
sub search { |
41 |
my ( $self, $params, $attributes ) = @_; |
42 |
my ( $self, $params, $attributes ) = @_; |
42 |
|
43 |
|
43 |
my $branchcode = $params->{branchcode}; |
|
|
44 |
delete( $params->{branchcode} ); |
45 |
|
46 |
my $or = |
47 |
$branchcode |
48 |
? { |
49 |
'-or' => [ |
50 |
'borrower_attribute_types_branches.b_branchcode' => undef, |
51 |
'borrower_attribute_types_branches.b_branchcode' => $branchcode, |
52 |
] |
53 |
} : {}; |
54 |
|
55 |
my $join = |
56 |
$branchcode |
57 |
? { |
58 |
join => { |
59 |
'code' => 'borrower_attribute_types_branches' |
60 |
}, |
61 |
} : {}; |
62 |
$attributes //= {}; |
63 |
unless ( exists $attributes->{order_by} ) { $attributes->{order_by} = ['code', 'attribute'] } |
44 |
unless ( exists $attributes->{order_by} ) { $attributes->{order_by} = ['code', 'attribute'] } |
64 |
return $self->SUPER::search( { %$params, %$or }, { %$attributes, %$join } ); |
45 |
|
|
|
46 |
return $self->SUPER::search( $params, $attributes ); |
47 |
} |
48 |
|
49 |
=head3 filter_by_branch_limitations |
50 |
|
51 |
my $attributes = Koha::Patron::Attributes->filter_by_branch_limitations([$branchcode]); |
52 |
|
53 |
Search patron attributes filtered by a library |
54 |
|
55 |
If $branchcode exists it will be used to filter the result set. |
56 |
|
57 |
Otherwise it will be the library of the logged in user. |
58 |
|
59 |
=cut |
60 |
|
61 |
sub filter_by_branch_limitations { |
62 |
my ( $self, $branchcode ) = @_; |
63 |
|
64 |
# Maybe we should not limit if logged in user is superlibrarian? |
65 |
my $branch_limit = |
66 |
$branchcode ? $branchcode |
67 |
# Do we raise an exception if no userenv defined? |
68 |
: C4::Context->userenv ? C4::Context->userenv->{"branch"} |
69 |
: undef; |
70 |
|
71 |
my $or = $branch_limit |
72 |
? { |
73 |
'-or' => [ |
74 |
'borrower_attribute_types_branches.b_branchcode' => undef, |
75 |
'borrower_attribute_types_branches.b_branchcode' => $branch_limit, |
76 |
] |
77 |
} |
78 |
: {}; |
79 |
|
80 |
my $join = $branch_limit |
81 |
? { |
82 |
join => { |
83 |
code => 'borrower_attribute_types_branches' |
84 |
}, |
85 |
} |
86 |
: {}; |
87 |
return $self->search( $or, $join ); |
65 |
} |
88 |
} |
66 |
|
89 |
|
67 |
=head3 _type |
90 |
=head3 _type |