Bug 12462: Fix some POD errors
[koha.git] / Koha / Borrower / Files.pm
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);
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 }
34
35 =head1 NAME
36
37 Koha::Borrower::Files - Module for managing borrower files
38
39 =head1 METHODS
40
41 =over
42
43 =cut
44
45 sub new {
46     my ( $class, %args ) = @_;
47     my $self = bless( {}, $class );
48
49     $self->{'borrowernumber'} = $args{'borrowernumber'};
50
51     return $self;
52 }
53
54 =item GetFilesInfo()
55
56     my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
57     my $files_hashref = $bf->GetFilesInfo
58
59 =cut
60
61 sub GetFilesInfo {
62     my $self = shift;
63
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
75     ";
76     my $sth = $dbh->prepare($query);
77     $sth->execute( $self->{'borrowernumber'} );
78     return $sth->fetchall_arrayref( {} );
79 }
80
81 =item AddFile()
82
83     my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
84     $bh->AddFile( name => $filename, type => $mimetype,
85                   description => $description, content => $content );
86
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
111     my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
112     my $file = $bh->GetFile( file_id => $file_id );
113
114 =cut
115
116 sub GetFile {
117     my ( $self, %args ) = @_;
118
119     my $file_id = $args{'id'};
120
121     my $dbh   = C4::Context->dbh;
122     my $query = "
123         SELECT * FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
124     ";
125     my $sth = $dbh->prepare($query);
126     $sth->execute( $file_id, $self->{'borrowernumber'} );
127     return $sth->fetchrow_hashref();
128 }
129
130 =item DelFile()
131
132     my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
133     $bh->DelFile( file_id => $file_id );
134
135 =cut
136
137 sub DelFile {
138     my ( $self, %args ) = @_;
139
140     my $file_id = $args{'id'};
141
142     my $dbh   = C4::Context->dbh;
143     my $query = "
144         DELETE FROM borrower_files WHERE file_id = ? AND borrowernumber = ?
145     ";
146     my $sth = $dbh->prepare($query);
147     $sth->execute( $file_id, $self->{'borrowernumber'} );
148 }
149
150 1;
151 __END__
152
153 =back
154
155 =head1 AUTHOR
156
157 Kyle M Hall <kyle.m.hall@gmail.com>
158
159 =cut