Bug 20473: Whitespace
[koha.git] / Koha / Patron / Files.pm
1 package Koha::Patron::Files;
2
3 # Copyright 2012 Kyle M Hall
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 C4::Context;
24 use C4::Output;
25
26 =head1 NAME
27
28 Koha::Patron::Files - Module for managing patron files
29
30 =head1 METHODS
31
32 =over
33
34 =cut
35
36 sub new {
37     my ( $class, %args ) = @_;
38     my $self = bless( {}, $class );
39
40     $self->{'borrowernumber'} = $args{'borrowernumber'};
41
42     return $self;
43 }
44
45 =item GetFilesInfo()
46
47     my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
48     my $files_hashref = $bf->GetFilesInfo
49
50 =cut
51
52 sub GetFilesInfo {
53     my $self = shift;
54
55     my $dbh   = C4::Context->dbh;
56     my $query = "
57         SELECT
58             file_id,
59             file_name,
60             file_type,
61             file_description,
62             date_uploaded
63         FROM borrower_files
64         WHERE borrowernumber = ?
65         ORDER BY file_name, date_uploaded
66     ";
67     my $sth = $dbh->prepare($query);
68     $sth->execute( $self->{'borrowernumber'} );
69     return $sth->fetchall_arrayref( {} );
70 }
71
72 =item AddFile()
73
74     my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
75     $bh->AddFile( name => $filename, type => $mimetype,
76                   description => $description, content => $content );
77
78 =cut
79
80 sub AddFile {
81     my ( $self, %args ) = @_;
82
83     my $name        = $args{'name'};
84     my $type        = $args{'type'};
85     my $description = $args{'description'};
86     my $content     = $args{'content'};
87
88     return unless ( $name && $content );
89
90     my $dbh   = C4::Context->dbh;
91     my $query = "
92         INSERT INTO borrower_files ( borrowernumber, file_name, file_type, file_description, file_content )
93         VALUES ( ?,?,?,?,? )
94     ";
95     my $sth = $dbh->prepare($query);
96     $sth->execute( $self->{'borrowernumber'},
97         $name, $type, $description, $content );
98 }
99
100 =item GetFile()
101
102     my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
103     my $file = $bh->GetFile( file_id => $file_id );
104
105 =cut
106
107 sub GetFile {
108     my ( $self, %args ) = @_;
109
110     my $file_id = $args{'id'};
111
112     my $dbh   = C4::Context->dbh;
113     my $query = "
114         SELECT * FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
115     ";
116     my $sth = $dbh->prepare($query);
117     $sth->execute( $file_id, $self->{'borrowernumber'} );
118     return $sth->fetchrow_hashref();
119 }
120
121 =item DelFile()
122
123     my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
124     $bh->DelFile( file_id => $file_id );
125
126 =cut
127
128 sub DelFile {
129     my ( $self, %args ) = @_;
130
131     my $file_id = $args{'id'};
132
133     my $dbh   = C4::Context->dbh;
134     my $query = "
135         DELETE FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
136     ";
137     my $sth = $dbh->prepare($query);
138     $sth->execute( $file_id, $self->{'borrowernumber'} );
139 }
140
141 1;
142 __END__
143
144 =back
145
146 =head1 AUTHOR
147
148 Kyle M Hall <kyle.m.hall@gmail.com>
149
150 =cut