Bug 35298: Remove focus handler from dateaccessioned plugin.
[koha.git] / Koha / Illrequests.pm
1 package Koha::Illrequests;
2
3 # Copyright PTFS Europe 2016
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 Koha::Database;
23 use Koha::Illrequest;
24 use Koha::Illrequest::Config;
25
26 use base qw(Koha::Objects);
27
28 =head1 NAME
29
30 Koha::Illrequests - Koha Illrequests Object class
31
32 =head1 API
33
34 =head2 Class methods
35
36 ##### To be implemented Facade
37
38 =head3 new
39
40     my $illRequests = Koha::Illrequests->new();
41
42 Create an ILLREQUESTS object, a singleton through which we can interact with
43 ILLREQUEST objects stored in the database or search for ILL candidates at API
44 backends.
45
46 =cut
47
48 sub new {
49     my ( $class, $attributes ) = @_;
50
51     my $self = $class->SUPER::new($class, $attributes);
52
53     my $config = Koha::Illrequest::Config->new; # <- Necessary
54     $self->{_config} = $config;                 # <- Necessary
55
56     return $self;
57 }
58
59 =head3 filter_by_visible
60
61     my $visible_requests = $requests->filter_by_visible;
62
63 Returns a I<Koha::Illrequests> resultset, filtered by statuses that are not listed
64 as hidden in the I<ILLHiddenRequestStatuses> system preference.
65
66 =cut
67
68 sub filter_by_visible {
69     my ($self) = @_;
70
71     my $hidden_statuses_string = C4::Context->preference('ILLHiddenRequestStatuses') // q{};
72     my $hidden_statuses = [ split '\|', $hidden_statuses_string ];
73
74     if ( scalar @{$hidden_statuses} ) {
75         return $self->search(
76             {
77                 -and => {
78                     status => { 'not in' => $hidden_statuses },
79                     status_alias => [ -or =>
80                         { 'not in' => $hidden_statuses },
81                         { '=' => undef }
82                     ]
83                 }
84             }
85         );
86     }
87
88     return $self;
89 }
90
91 =head3 search_incomplete
92
93     my $requests = $illRequests->search_incomplete;
94
95 A specialised version of `search`, returning all requests currently
96 not considered completed.
97
98 =cut
99
100 sub search_incomplete {
101     my ( $self ) = @_;
102     $self->search( {
103         status => [
104             -and => { '!=', 'COMP' }, { '!=', 'GENCOMP' }
105         ]
106     } );
107 }
108
109 =head2 Internal methods
110
111 =head3 _type
112
113 =cut
114
115 sub _type {
116     return 'Illrequest';
117 }
118
119 =head3 object_class
120
121 =cut
122
123 sub object_class {
124     return 'Koha::Illrequest';
125 }
126
127 =head1 AUTHOR
128
129 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
130
131 =cut
132
133 1;