use C4::Context;
use XML::LibXML;
use XML::LibXSLT;
+use XML::Simple;
my $dbh = C4::Context->dbh;
my $xslfilename = 'compact.xsl';
my $authors;
+my $marcxml;
my $sth_select_authors = $dbh->prepare(q{
select
biblionumber,
ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="9"]') as first_author,
ExtractValue(marcxml,'//datafield[@tag="700"]/subfield[@code="9"]') as other_authors,
- ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category
-from biblioitems where agerestriction > 0
+ ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category,
+ marcxml
+from biblioitems
+where
+ agerestriction > 0
+ and SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) between 2008 and 2013
+order by SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) desc
});
$sth_select_authors->execute();
while( my $row = $sth_select_authors->fetchrow_hashref ) {
# warn dump($row),$/;
- my $all_authors = join(' ', $row->{first_author}, $row->{other_authors});
- foreach my $authid ( split(/\s+/, $all_authors) ) {
- push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
+ if ( $row->{first_author} ) {
+ my $all_authors = join(' ', $row->{first_author}, $row->{other_authors});
+ foreach my $authid ( split(/\s+/, $all_authors) ) {
+ push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
+ $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
+ }
+ } else {
+ my $xml = XMLin( $row->{marcxml}, ForceArray => [ 'subfield' ] );
+ foreach my $f700 ( map { $_->{subfield} } grep { $_->{tag} eq 700 } @{ $xml->{datafield} } ) {
+ my $authid = 0;
+ my $is_edt = 0;
+ foreach my $sf ( @$f700 ) {
+ if ( $sf->{code} eq '4' && $sf->{content} =~ m/^edt/ ) {
+ $is_edt++;
+ } elsif ( $sf->{code} eq '9' ) {
+ $authid = $sf->{content};
+ }
+ }
+ if ( $authid && $is_edt ) {
+ warn "# ++ ", $row->{biblionumber}, " $authid f700 ", dump( $f700 );
+ push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
+ $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
+ } else {
+ warn "# -- ", $row->{biblionumber}, " f700 ", dump( $f700 );
+ }
+ }
}
}
}
+my $category_label;
+my $sth_categories = $dbh->prepare(q{
+select authorised_value, lib from authorised_values where category = 'BIBCAT'
+});
+$sth_categories->execute();
+while( my $row = $sth_categories->fetchrow_hashref ) {
+ $category_label->{ $row->{authorised_value} } = $row->{lib};
+
+}
+warn dump( $category_label );
+
sub html_title {
return qq|<html>
<head>
<meta charset="UTF-8">
<title>|, join(" ", @_), qq|</title>
+<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
|;
}
-my $sth_marcxml = $dbh->prepare(q{
-select marcxml from biblioitems where biblionumber = ?
-});
-
sub biblioitem_html {
my $biblionumber = shift;
- $sth_marcxml->execute( $biblionumber );
- my $xmlrecord = $sth_marcxml->fetchrow_arrayref->[0];
+ my $xmlrecord = $marcxml->{$biblionumber} || die "missing $biblionumber marcxml";
my $parser = XML::LibXML->new();
$parser->recover_silently(0); # don't die when you find &, >, etc
open(my $fh, '>:encoding(utf-8)', "html/$row->{authid}.html");
print $fh html_title($row->{full_name}, "bibliografija");
foreach my $category ( sort keys %{ $authors->{ $row->{authid} } } ) {
- print $fh qq|<h1>$category</h1>\n<ul>\n|;
+ my $label = $category_label->{$category} || 'Bez kategorije';
+ print $fh qq|<h1>$label</h1>\n<ul>\n|;
foreach my $biblionumber ( @{ $authors->{ $row->{authid} }->{$category} } ) {
print $fh qq|<li><a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|, biblioitem_html($biblionumber), qq|</li>\n|;
}