Bug 29002: Tidy
[koha.git] / Koha / Template / Plugin / Biblio.pm
1 package Koha::Template::Plugin::Biblio;
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 use Template::Plugin;
23 use base qw( Template::Plugin );
24
25 use Koha::Holds;
26 use Koha::Biblios;
27 use Koha::Database;
28 use Koha::Patrons;
29 use Koha::ArticleRequests;
30 use Koha::Recalls;
31
32 use Koha::DateUtils qw(dt_from_string);
33
34 sub HoldsCount {
35     my ( $self, $biblionumber ) = @_;
36
37     my $holds = Koha::Holds->search( { biblionumber => $biblionumber } );
38
39     return $holds->count();
40 }
41
42 sub ArticleRequestsActiveCount {
43     my ( $self, $biblionumber ) = @_;
44
45     my $ar = Koha::ArticleRequests->search(
46         {
47             biblionumber => $biblionumber
48         }
49     )->filter_by_current;
50
51     return $ar->count();
52 }
53
54 sub CanArticleRequest {
55     my ( $self, $biblionumber, $borrowernumber ) = @_;
56
57     my $biblio = Koha::Biblios->find( $biblionumber );
58     my $borrower = Koha::Patrons->find( $borrowernumber );
59
60     return $biblio ? $biblio->can_article_request( $borrower ) : 0;
61 }
62
63 sub RecallsCount {
64     my ( $self, $biblionumber ) = @_;
65
66     my $recalls = Koha::Recalls->search({ biblio_id => $biblionumber, completed => 0 });
67
68     return $recalls->count;
69 }
70
71 sub CanBook {
72     my ( $self, $biblionumber ) = @_;
73
74     my $biblio = Koha::Biblios->find($biblionumber);
75     return $biblio->bookable_items->count ? 1 : 0;
76 }
77
78 sub BookingsCount {
79     my ( $self, $biblionumber ) = @_;
80
81     my $biblio = Koha::Biblios->find($biblionumber);
82
83     my $now = dt_from_string;
84     my $dtf = Koha::Database->new->schema->storage->datetime_parser;
85     return $biblio->bookings->search( { start_date => { '>' => $dtf->format_datetime($now) } } )->count;
86 }
87
88 1;