Bug 17501: Remove Koha::Upload::get from Koha::Upload
[koha.git] / Koha / UploadedFiles.pm
1 package Koha::UploadedFiles;
2
3 # Copyright Rijksmuseum 2016
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 #use Koha::Database;
23 use Koha::UploadedFile;
24
25 use parent qw(Koha::Objects);
26
27 =head1 NAME
28
29 Koha::UploadedFiles - Koha::Objects class for uploaded files
30
31 =head1 SYNOPSIS
32
33 use Koha::UploadedFiles;
34
35 =head1 DESCRIPTION
36
37 Description
38
39 =head1 METHODS
40
41 =head2 INSTANCE METHODS
42
43 =head3 delete, delete_errors
44
45 Delete uploaded files.
46 Returns true if no errors occur.
47 Delete_errors returns the number of errors when deleting files.
48
49 Parameter keep_file may be used to delete records, but keep files.
50
51 =cut
52
53 sub delete {
54     my ( $self, $params ) = @_;
55     # We use the individual delete on each resultset record
56     my $err = 0;
57     while( my $row = $self->_resultset->next ) {
58         my $kohaobj = Koha::UploadedFile->_new_from_dbic( $row );
59         $err++ if !$kohaobj->delete( $params );
60     }
61     $self->{delete_errors} = $err;
62     return $err==0;
63 }
64
65 sub delete_errors {
66     my ( $self ) = @_;
67     return $self->{delete_errors};
68 }
69
70 =head3 search_term
71
72 Search_term allows you to pass a term to search in filename and hashvalue.
73 If you do not pass include_private, only public records are returned.
74
75 Is only a wrapper around Koha::Objects search. Has similar return value.
76
77 =cut
78
79 sub search_term {
80     my ( $self, $params ) = @_;
81     my $term = $params->{term} // '';
82     my %public = ();
83     if( !$params->{include_private} ) {
84         %public = ( public => 1 );
85     }
86     return $self->search(
87         [ { filename => { like => '%'.$term.'%' }, %public },
88           { hashvalue => { like => '%'.$params->{term}.'%' }, %public } ],
89         { order_by => { -asc => 'id' }},
90     );
91 }
92
93 =head2 CLASS METHODS
94
95 =head3 _type
96
97 Returns name of corresponding DBIC resultset
98
99 =cut
100
101 sub _type {
102     return 'UploadedFile';
103 }
104
105 =head3 object_class
106
107 Returns name of corresponding Koha object class
108
109 =cut
110
111 sub object_class {
112     return 'Koha::UploadedFile';
113 }
114
115 =head1 AUTHOR
116
117 Marcel de Rooy (Rijksmuseum)
118
119 Koha Development Team
120
121 =cut
122
123 1;