Bug 33954: Koha::Biblio->opac_summary_html
[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 Throws a I<Koha::Exceptions::MissingParameter> exception if the B<mandatory> parameter I<patron>
46 is not passed.
47
48 =cut
49
50 sub pickup_locations {
51     my ( $self, $params ) = @_;
52
53     Koha::Exceptions::MissingParameter->throw( parameter => 'patron' )
54       unless exists $params->{patron};
55
56     my $patron = $params->{patron};
57
58     my @pickup_locations;
59     foreach my $biblio ( $self->as_list ) {
60         push @pickup_locations,
61           $biblio->pickup_locations( { patron => $patron } )
62           ->_resultset->get_column('branchcode')->all;
63     }
64
65     return Koha::Libraries->search(
66         {
67             branchcode => \@pickup_locations
68         },
69         { order_by => ['branchname'] }
70     );
71 }
72
73 =head2 Internal methods
74
75 =head3 api_query_fixer
76
77     $query_string = $biblios->api_query_fixer( $query_string, $context, $no_quotes );
78
79 Method that takes care of adjusting I<$query_string> as required. An optional I<$context> parameter
80 will be used to prefix the relevant query atoms if present. A I<$no_quotes> boolean parameter
81 can be passed to choose not to use quotes on matching. This is particularly useful in the context of I<order_by>.
82
83 =cut
84
85 sub api_query_fixer {
86     my ( $self, $query, $context, $no_quotes ) = @_;
87
88     my $quotes = $no_quotes ? '' : '"';
89
90     if ($context) {
91         $query =~
92             s/${quotes}${context}\.(age_restriction|cn_class|cn_item|cn_sort|cn_source|cn_suffix|collection_issn|collection_title|collection_volume|ean|edition_statement|illustrations|isbn|issn|item_type|lc_control_number|notes|number|pages|publication_place|publication_year|publisher|material_size|serial_total_issues|url|volume|volume_date|volume_description)${quotes}/${quotes}${context}\.biblioitem\.$1${quotes}/g;
93     } else {
94         $query =~
95             s/${quotes}(age_restriction|cn_class|cn_item|cn_sort|cn_source|cn_suffix|collection_issn|collection_title|collection_volume|ean|edition_statement|illustrations|isbn|issn|item_type|lc_control_number|notes|number|pages|publication_place|publication_year|publisher|material_size|serial_total_issues|url|volume|volume_date|volume_description)${quotes}/${quotes}biblioitem\.$1${quotes}/g;
96         $query =~ # handle ambiguous 'biblionumber'
97             s/${quotes}(biblio_id)${quotes}/${quotes}me\.$1${quotes}/g;
98     }
99
100     return $query;
101 }
102
103 =head3 _type
104
105 =cut
106
107 sub _type {
108     return 'Biblio';
109 }
110
111 =head3 object_class
112
113 =cut
114
115 sub object_class {
116     return 'Koha::Biblio';
117 }
118
119 =head1 AUTHOR
120
121 Kyle M Hall <kyle@bywatersolutions.com>
122
123 =cut
124
125 1;