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