1 package Koha
::Illrequest
::Logger
;
3 # Copyright 2018 PTFS Europe Ltd
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 3 of the License, or (at your option) any later
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.
21 use JSON
qw( to_json from_json );
27 use C4
::Log
qw( logaction );
32 Koha::Illrequest::Logger - Koha ILL Action / Event logger
36 Object-oriented class that provides event logging functionality for
41 This class provides the ability to log arbitrary actions or events
42 relating to Illrequest to the action log.
50 my $config = Koha::Illrequest::Logger->new();
52 Create a new Koha::Illrequest::Logger object.
53 We also set up what can be logged, how to do it and how to display
54 log entries we get back out
64 $self->log_status_change(@_);
68 my ( $htdocs, $theme, $lang, $base ) =
69 C4
::Templates
::_get_template_file
('ill/log/', 'intranet');
71 $self->{templates
} = {
72 STATUS_CHANGE
=> $base . 'status_change.tt'
82 Koha::IllRequest::Logger->log_maybe($params);
84 Receive params hashref, containing a request object and an attrs
85 hashref (which may or may not be defined) If the attrs hashref contains
86 a key matching our "loggers" hashref then we want to log it
91 my ($self, $params) = @_;
93 if (defined $params->{request
} && defined $params->{attrs
}) {
94 foreach my $key (keys %{ $params->{attrs
} }) {
95 if (defined($self->{loggers
}->{$key})) {
96 $self->{loggers
}->{$key}(
98 $params->{attrs
}->{$key}
105 =head3 log_status_change
107 Koha::IllRequest::Logger->log_status_change($params);
109 Receive a hashref containing a request object and a status to log,
114 sub log_status_change
{
115 my ( $self, $params ) = @_;
117 if (defined $params->{request
} && defined $params->{value
}) {
118 $self->log_something({
120 actionname
=> 'STATUS_CHANGE',
121 objectnumber
=> $params->{request
}->id,
123 log_origin
=> 'core',
124 status_before
=> $params->{request
}->{previous_status
},
125 status_after
=> $params->{value
}
133 Koha::IllRequest::Logger->log_something({
135 actionname => 'STATUS_CHANGE',
136 objectnumber => $req->id,
138 log_origin => 'core',
139 status_before => $req->{previous_status},
140 status_after => $new_status
144 If we have the required data passed, log an action
149 my ( $self, $to_log ) = @_;
152 defined $to_log->{modulename
} &&
153 defined $to_log->{actionname
} &&
154 defined $to_log->{objectnumber
} &&
155 defined $to_log->{infos
} &&
156 C4
::Context
->preference("IllLog")
159 $to_log->{modulename
},
160 $to_log->{actionname
},
161 $to_log->{objectnumber
},
167 =head3 get_log_template
169 $template_path = get_log_template($params);
171 Given a log's origin and action, get the appropriate display template
175 sub get_log_template
{
176 my ($self, $params) = @_;
178 my $origin = $params->{origin
};
179 my $action = $params->{action
};
181 if ($origin eq 'core') {
182 # It's a core log, so we can just get the template path from
184 return $self->{templates
}->{$action};
186 # It's probably a backend log, so we need to get the path to the
187 # template from the backend
188 my $backend =$params->{request
}->{_my_backend
};
189 return $backend->get_log_template_path($action);
193 =head3 get_request_logs
195 $requestlogs = Koha::IllRequest::Logger->get_request_logs($request_id);
197 Get all logged actions for a given request
201 sub get_request_logs
{
202 my ( $self, $request ) = @_;
204 my $logs = Koha
::ActionLogs
->search(
207 object
=> $request->id
209 { order_by
=> { -desc
=> "timestamp" } }
212 # Populate a lookup table for status aliases
213 my $aliases = GetAuthorisedValues
('ILLSTATUS');
215 foreach my $alias(@
{$aliases}) {
216 $alias_hash->{$alias->{authorised_value
}} = $alias;
218 foreach my $log(@
{$logs}) {
219 $log->{aliases
} = $alias_hash;
220 $log->{info
} = from_json
($log->{info
});
221 $log->{template
} = $self->get_log_template({
223 origin
=> $log->{info
}->{log_origin
},
224 action
=> $log->{action
}
233 Andrew Isherwood <andrew.isherwood@ptfs-europe.com>