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