Bug 14119: Missing de-DE DISCHARGE message
[koha.git] / Koha / Borrower / Files.pm
blob7084c1e1257fcd830bbd88edb52c3284265c8eb1
1 package Koha::Borrower::Files;
3 # Copyright 2012 Kyle M Hall
5 # This file is part of Koha.
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.
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.
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>.
20 use Modern::Perl;
22 use vars qw($VERSION);
24 use C4::Context;
25 use C4::Output;
26 use C4::Dates;
27 use C4::Debug;
29 BEGIN {
31 # set the version for version checking
32 $VERSION = 0.01;
35 =head1 NAME
37 Koha::Borrower::Files - Module for managing borrower files
39 =head1 METHODS
41 =over
43 =cut
45 sub new {
46 my ( $class, %args ) = @_;
47 my $self = bless( {}, $class );
49 $self->{'borrowernumber'} = $args{'borrowernumber'};
51 return $self;
54 =item GetFilesInfo()
56 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
57 my $files_hashref = $bf->GetFilesInfo
59 =cut
61 sub GetFilesInfo {
62 my $self = shift;
64 my $dbh = C4::Context->dbh;
65 my $query = "
66 SELECT
67 file_id,
68 file_name,
69 file_type,
70 file_description,
71 date_uploaded
72 FROM borrower_files
73 WHERE borrowernumber = ?
74 ORDER BY file_name, date_uploaded
76 my $sth = $dbh->prepare($query);
77 $sth->execute( $self->{'borrowernumber'} );
78 return $sth->fetchall_arrayref( {} );
81 =item AddFile()
83 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
84 $bh->AddFile( name => $filename, type => $mimetype,
85 description => $description, content => $content );
87 =cut
89 sub AddFile {
90 my ( $self, %args ) = @_;
92 my $name = $args{'name'};
93 my $type = $args{'type'};
94 my $description = $args{'description'};
95 my $content = $args{'content'};
97 return unless ( $name && $content );
99 my $dbh = C4::Context->dbh;
100 my $query = "
101 INSERT INTO borrower_files ( borrowernumber, file_name, file_type, file_description, file_content )
102 VALUES ( ?,?,?,?,? )
104 my $sth = $dbh->prepare($query);
105 $sth->execute( $self->{'borrowernumber'},
106 $name, $type, $description, $content );
109 =item GetFile()
111 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
112 my $file = $bh->GetFile( file_id => $file_id );
114 =cut
116 sub GetFile {
117 my ( $self, %args ) = @_;
119 my $file_id = $args{'id'};
121 my $dbh = C4::Context->dbh;
122 my $query = "
123 SELECT * FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
125 my $sth = $dbh->prepare($query);
126 $sth->execute( $file_id, $self->{'borrowernumber'} );
127 return $sth->fetchrow_hashref();
130 =item DelFile()
132 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
133 $bh->DelFile( file_id => $file_id );
135 =cut
137 sub DelFile {
138 my ( $self, %args ) = @_;
140 my $file_id = $args{'id'};
142 my $dbh = C4::Context->dbh;
143 my $query = "
144 DELETE FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
146 my $sth = $dbh->prepare($query);
147 $sth->execute( $file_id, $self->{'borrowernumber'} );
151 __END__
153 =back
155 =head1 AUTHOR
157 Kyle M Hall <kyle.m.hall@gmail.com>
159 =cut