Bug 8978: Patron's dateexpiry erroneously updated when in UnwantedField
[koha.git] / Koha / Borrower / Files.pm
blobd1660bbae52d438a01752178cf5b3776f0584290
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
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.
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.
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 =cut
41 sub new {
42 my ( $class, %args ) = @_;
43 my $self = bless( {}, $class );
45 $self->{'borrowernumber'} = $args{'borrowernumber'};
47 return $self;
50 =item GetFilesInfo()
52 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
53 my $files_hashref = $bf->GetFilesInfo
55 =cut
57 sub GetFilesInfo {
58 my $self = shift;
60 my $dbh = C4::Context->dbh;
61 my $query = "
62 SELECT
63 file_id,
64 file_name,
65 file_type,
66 file_description,
67 date_uploaded
68 FROM borrower_files
69 WHERE borrowernumber = ?
70 ORDER BY file_name, date_uploaded
72 my $sth = $dbh->prepare($query);
73 $sth->execute( $self->{'borrowernumber'} );
74 return $sth->fetchall_arrayref( {} );
77 =item AddFile()
78 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
79 $bh->AddFile( name => $filename, type => $mimetype, description => $description, content => $content );
80 =cut
82 sub AddFile {
83 my ( $self, %args ) = @_;
85 my $name = $args{'name'};
86 my $type = $args{'type'};
87 my $description = $args{'description'};
88 my $content = $args{'content'};
90 return unless ( $name && $content );
92 my $dbh = C4::Context->dbh;
93 my $query = "
94 INSERT INTO borrower_files ( borrowernumber, file_name, file_type, file_description, file_content )
95 VALUES ( ?,?,?,?,? )
97 my $sth = $dbh->prepare($query);
98 $sth->execute( $self->{'borrowernumber'},
99 $name, $type, $description, $content );
102 =item GetFile()
103 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
104 my $file = $bh->GetFile( file_id => $file_id );
105 =cut
107 sub GetFile {
108 my ( $self, %args ) = @_;
110 my $file_id = $args{'id'};
112 my $dbh = C4::Context->dbh;
113 my $query = "
114 SELECT * FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
116 my $sth = $dbh->prepare($query);
117 $sth->execute( $file_id, $self->{'borrowernumber'} );
118 return $sth->fetchrow_hashref();
121 =item DelFile()
122 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
123 $bh->DelFile( file_id => $file_id );
124 =cut
126 sub DelFile {
127 my ( $self, %args ) = @_;
129 my $file_id = $args{'id'};
131 my $dbh = C4::Context->dbh;
132 my $query = "
133 DELETE FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
135 my $sth = $dbh->prepare($query);
136 $sth->execute( $file_id, $self->{'borrowernumber'} );
140 __END__
142 =back
144 =head1 AUTHOR
146 Kyle M Hall <kyle.m.hall@gmail.com>
148 =cut