Bug 20473: Whitespace
[koha.git] / Koha / BackgroundJobs.pm
1 package Koha::BackgroundJobs;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Koha::BackgroundJob;
21
22 use base qw(Koha::Objects);
23
24 =head1 NAME
25
26 Koha::BackgroundJobs - Koha BackgroundJob Object set class
27
28 =head1 API
29
30 =head2 Class methods
31
32 =head3 search_limited
33
34   my $background_jobs = Koha::BackgroundJobs->search_limited( $params, $attributes );
35
36 Returns all background jobs the logged in user should be allowed to see
37
38 =cut
39
40 sub search_limited {
41     my ( $self, $params, $attributes ) = @_;
42
43     my $can_manage_background_jobs;
44     my $logged_in_user;
45     my $userenv = C4::Context->userenv;
46     if ( $userenv and $userenv->{number} ) {
47         $logged_in_user = Koha::Patrons->find( $userenv->{number} );
48         $can_manage_background_jobs = $logged_in_user->has_permission(
49             { parameters => 'manage_background_jobs' } );
50     }
51
52     return $self->search( $params, $attributes ) if $can_manage_background_jobs;
53     my $id = $logged_in_user ? $logged_in_user->borrowernumber : undef;
54     return $self->search({ borrowernumber => $id  })->search( $params, $attributes );
55 }
56
57 =head3 filter_by_current
58
59     my $current_jobs = $jobs->filter_by_current;
60
61 Returns a new resultset, filtering out finished jobs.
62
63 =cut
64
65 sub filter_by_current {
66     my ($self) = @_;
67
68     return $self->search(
69         {
70             status => { not_in => [ 'cancelled', 'failed', 'finished' ] }
71         }
72     );
73 }
74
75 =head2 Internal methods
76
77 =head3 _type
78
79 =cut
80
81 sub _type {
82     return 'BackgroundJob';
83 }
84
85 =head3 object_class
86
87 =cut
88
89 sub object_class {
90     return 'Koha::BackgroundJob';
91 }
92
93 1;