Bug 33447: (follow-up) Fix tests and make assumption explicit
[koha.git] / Koha / Biblios.pm
1 package Koha::Biblios;
2
3 # Copyright ByWater Solutions 2015
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22
23 use Koha::Database;
24
25 use Koha::Biblio;
26 use Koha::Libraries;
27
28 use base qw(Koha::Objects Koha::Objects::Record::Collections);
29
30 =head1 NAME
31
32 Koha::Biblios - Koha Biblio object set class
33
34 =head1 API
35
36 =head2 Class methods
37
38 =head3 pickup_locations
39
40     my $biblios = Koha::Biblios->search(...);
41     my $pickup_locations = $biblios->pickup_locations({ patron => $patron });
42
43 For a given resultset, it returns all the pickup locations.
44
45 Patron is a required parameter.
46
47 =cut
48
49 sub pickup_locations {
50     my ( $self, $params ) = @_;
51
52     my $patron = $params->{patron};
53
54     my @pickup_locations;
55     foreach my $biblio ( $self->as_list ) {
56         push @pickup_locations,
57           $biblio->pickup_locations( { patron => $patron } )
58           ->_resultset->get_column('branchcode')->all;
59     }
60
61     return Koha::Libraries->search(
62         {
63             branchcode => \@pickup_locations
64         },
65         { order_by => ['branchname'] }
66     );
67 }
68
69 =head2 Internal methods
70
71 =head3 type
72
73 =cut
74
75 sub _type {
76     return 'Biblio';
77 }
78
79 =head3 object_class
80
81 =cut
82
83 sub object_class {
84     return 'Koha::Biblio';
85 }
86
87 =head1 AUTHOR
88
89 Kyle M Hall <kyle@bywatersolutions.com>
90
91 =cut
92
93 1;