Bug 26265: (QA follow-up) Remove g option from regex, add few dirs
[koha-equinox.git] / Koha / ExternalContent.pm
1 # Copyright 2014 Catalyst
2 #
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 package Koha::ExternalContent;
19
20 use Modern::Perl;
21 use Carp;
22 use base qw(Class::Accessor);
23
24 use Koha;
25 use Koha::Patrons;
26 use C4::Auth;
27
28 __PACKAGE__->mk_accessors(qw(client koha_session_id koha_patron));
29
30 =head1 NAME
31
32 Koha::ExternalContent
33
34 =head1 SYNOPSIS
35
36  use Koha::ExternalContent;
37  my $externalcontent = Koha::ExternalContent->new();
38
39 =head1 DESCRIPTION
40
41 Base class for interfacing with external content providers.
42
43 Subclasses provide clients for particular systems. This class provides
44 common methods for getting Koha patron.
45
46 =head1 METHODS
47
48 =cut
49
50 sub agent_string {
51     return 'Koha/'.Koha::version();
52 }
53
54 sub new {
55     my $class     = shift;
56     my $params    = shift || {};
57     return bless $params, $class;
58 }
59
60 sub _koha_session {
61     my $self = shift;
62     my $session_id = $self->koha_session_id or return;
63     return C4::Auth::get_session($session_id);
64 }
65
66 sub get_from_koha_session {
67     my $self = shift;
68     my $key = shift or croak "No key";
69     my $session = $self->_koha_session or return;
70     return $session->param($key);
71 }
72
73 sub set_in_koha_session {
74     my $self = shift;
75     my $key = shift or croak "No key";
76     my $value = shift;
77     my $session = $self->_koha_session or croak "No Koha session";
78     return $session->param($key, $value);
79 }
80
81 sub koha_patron {
82     my $self = shift;
83
84     if (my $patron = $self->_koha_patron_accessor) {
85         return $patron;
86     }
87
88     my $id = $self->get_from_koha_session('number')
89       or return;
90     my $patron = Koha::Patrons->find($id)
91       or die "Invalid patron number in session";
92     return $self->_koha_patron_accessor($patron);
93 }
94
95 =head1 AUTHOR
96
97 CatalystIT
98
99 =cut
100
101 1;