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