Bugzilla – Attachment 179135 Details for
Bug 39296
Provide a template plugin to return MARC::Record for MARCXML metadata
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39296: Provide a template plugin for getting a MARC::Record from MARCXML
Bug-39296-Provide-a-template-plugin-for-getting-a-.patch (text/plain), 3.11 KB, created by
David Cook
on 2025-03-11 04:26:18 UTC
(
hide
)
Description:
Bug 39296: Provide a template plugin for getting a MARC::Record from MARCXML
Filename:
MIME Type:
Creator:
David Cook
Created:
2025-03-11 04:26:18 UTC
Size:
3.11 KB
patch
obsolete
>From 3643ea053ba3d110f75b0d4a1590b7af75fb61ae Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Tue, 11 Mar 2025 04:24:34 +0000 >Subject: [PATCH] Bug 39296: Provide a template plugin for getting a > MARC::Record from MARCXML > >This change takes MARCXML data (e.g. from the biblio_metadata table) and >returns a MARC::Record object which can be used in Reports templates to >allow for more sophisticated reporting using MARCXML data. > >Test plan: >0. Apply the patch and koha-plack --restart kohadev >1. Go to http://localhost:8081/cgi-bin/koha/tools/letter.pl >2. Add a new notice for Reports with the following content: >[% USE KohaMarcRecord %] >[% SET all_subjects = {} %] >[% FOREACH row IN data %] > [% SET record= KohaMarcRecord.from_xml(row.metadata) %] > [% SET fields = record.field('6..') %] > [% FOREACH field IN fields %] > [% tmp = field.delete_subfield('code','9') %] > [% SET subject = field.as_string() %] > [% IF ( all_subjects.$subject ) %] > [% all_subjects.$subject = all_subjects.$subject + 1 %] > [% ELSE %] > [% all_subjects.$subject = 1 %] > [% END %] > [% END %] >[% END %] ><table> ><tr><th>Subject</th><th>Count</th></tr> >[% FOREACH key IN all_subjects.nsort.reverse %] ><tr><td>[% key %]</td><td>[% all_subjects.$key %]</td></tr> >[% END %] ></table> >3. Go to http://localhost:8081/cgi-bin/koha/reports/guided_reports.pl?op=add_form_sql >4. Create a new report with the following SQL: >5. Click "Run with template" and choose the template/notice you've created above >6. Note that you get a list of MARC subjects sorted by the most used to the least used >--- > Koha/Template/Plugin/KohaMarcRecord.pm | 40 ++++++++++++++++++++++++++ > 1 file changed, 40 insertions(+) > create mode 100644 Koha/Template/Plugin/KohaMarcRecord.pm > >diff --git a/Koha/Template/Plugin/KohaMarcRecord.pm b/Koha/Template/Plugin/KohaMarcRecord.pm >new file mode 100644 >index 0000000000..0d87438808 >--- /dev/null >+++ b/Koha/Template/Plugin/KohaMarcRecord.pm >@@ -0,0 +1,40 @@ >+package Koha::Template::Plugin::KohaMarcRecord; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Template::Plugin; >+use base qw( Template::Plugin ); >+ >+use C4::Context; >+use MARC::File::XML; >+ >+sub from_xml { >+ my ( $self, $xml ) = @_; >+ my $encoding = 'UTF-8'; >+ my $format = C4::Context->preference('marcflavour'); >+ my $record; >+ eval { >+ $record = MARC::Record->new_from_xml( $xml, $encoding, $format ); >+ }; >+ if ($@){ >+ warn $@; >+ } >+ return $record; >+} >+ >+1; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39296
:
179135
|
179189