Bug 14333: Update MARC21 frameworks to Update No. 20 and 21
[koha.git] / Koha / Borrower / Files.pm
blob028757d089be0feb50affe9697e1e661814748c9
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::Debug;
28 BEGIN {
30 # set the version for version checking
31 $VERSION = 0.01;
34 =head1 NAME
36 Koha::Borrower::Files - Module for managing borrower files
38 =head1 METHODS
40 =over
42 =cut
44 sub new {
45 my ( $class, %args ) = @_;
46 my $self = bless( {}, $class );
48 $self->{'borrowernumber'} = $args{'borrowernumber'};
50 return $self;
53 =item GetFilesInfo()
55 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
56 my $files_hashref = $bf->GetFilesInfo
58 =cut
60 sub GetFilesInfo {
61 my $self = shift;
63 my $dbh = C4::Context->dbh;
64 my $query = "
65 SELECT
66 file_id,
67 file_name,
68 file_type,
69 file_description,
70 date_uploaded
71 FROM borrower_files
72 WHERE borrowernumber = ?
73 ORDER BY file_name, date_uploaded
75 my $sth = $dbh->prepare($query);
76 $sth->execute( $self->{'borrowernumber'} );
77 return $sth->fetchall_arrayref( {} );
80 =item AddFile()
82 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
83 $bh->AddFile( name => $filename, type => $mimetype,
84 description => $description, content => $content );
86 =cut
88 sub AddFile {
89 my ( $self, %args ) = @_;
91 my $name = $args{'name'};
92 my $type = $args{'type'};
93 my $description = $args{'description'};
94 my $content = $args{'content'};
96 return unless ( $name && $content );
98 my $dbh = C4::Context->dbh;
99 my $query = "
100 INSERT INTO borrower_files ( borrowernumber, file_name, file_type, file_description, file_content )
101 VALUES ( ?,?,?,?,? )
103 my $sth = $dbh->prepare($query);
104 $sth->execute( $self->{'borrowernumber'},
105 $name, $type, $description, $content );
108 =item GetFile()
110 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
111 my $file = $bh->GetFile( file_id => $file_id );
113 =cut
115 sub GetFile {
116 my ( $self, %args ) = @_;
118 my $file_id = $args{'id'};
120 my $dbh = C4::Context->dbh;
121 my $query = "
122 SELECT * FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
124 my $sth = $dbh->prepare($query);
125 $sth->execute( $file_id, $self->{'borrowernumber'} );
126 return $sth->fetchrow_hashref();
129 =item DelFile()
131 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
132 $bh->DelFile( file_id => $file_id );
134 =cut
136 sub DelFile {
137 my ( $self, %args ) = @_;
139 my $file_id = $args{'id'};
141 my $dbh = C4::Context->dbh;
142 my $query = "
143 DELETE FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
145 my $sth = $dbh->prepare($query);
146 $sth->execute( $file_id, $self->{'borrowernumber'} );
150 __END__
152 =back
154 =head1 AUTHOR
156 Kyle M Hall <kyle.m.hall@gmail.com>
158 =cut