first naive implementation of authors list and biblios
[koha-bibliografija] / html.pl
1 #!/usr/bin/perl
2
3 # LC_COLLATE=hr_HR.utf8 KOHA_CONF=/etc/koha/sites/ffzg/koha-conf.xml ./html.pl
4
5 use warnings;
6 use strict;
7
8 use DBI;
9 use Data::Dump qw(dump);
10 use autodie;
11 use locale;
12
13 use lib '/srv/koha_ffzg';
14 use C4::Context;
15
16 my $dbh = C4::Context->dbh;
17
18 my $authors;
19
20 my $sth_select_authors  = $dbh->prepare(q{
21 select
22         biblionumber,
23         ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="9"]') as first_author,
24         ExtractValue(marcxml,'//datafield[@tag="700"]/subfield[@code="9"]') as other_authors,
25         ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category
26 from biblioitems where agerestriction > 0
27 });
28
29 $sth_select_authors->execute();
30 while( my $row = $sth_select_authors->fetchrow_hashref ) {
31 #       warn dump($row),$/;
32         my $all_authors = join(' ', $row->{first_author}, $row->{other_authors});
33         foreach my $authid ( split(/\s+/, $all_authors) ) {
34                 push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
35         }
36 }
37
38 my $auth_header;
39 my @authors;
40
41 my $all_authids = join(',', grep { length($_) > 0 } keys %$authors);
42 my $sth_auth = $dbh->prepare(q{
43 select
44         authid,
45         ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="a"]') as full_name
46 from auth_header
47 where
48         ExtractValue(marcxml,'//datafield[@tag="024"]/subfield[@code="a"]') <> '' and
49         authid in (} . $all_authids . q{)
50 });
51
52 $sth_auth->execute();
53 while( my $row = $sth_auth->fetchrow_hashref ) {
54         warn dump( $row );
55         $auth_header->{ $row->{authid} } = $row->{full_name};
56         push @authors, $row;
57
58 }
59
60 sub html_title {
61         return qq|<html>
62 <head>
63 <meta charset="UTF-8">
64 <title>|, join(" ", @_), qq|</title>
65 </head>
66 <body>
67 |;
68 }
69
70 sub html_end {
71         return qq|</body>\n</html\n|;
72 }
73
74 open(my $index, '>:encoding(utf-8)', 'html/index.html');
75 print $index html_title('Bibliografija Filozogskog fakulteta');
76
77 my $first_letter;
78
79 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
80
81         my $first = substr( $row->{full_name}, 0, 1 );
82         if ( $first ne $first_letter ) {
83                 print $index qq{</ul>\n} if $first_letter;
84                 $first_letter = $first;
85                 print $index qq{<h1>$first</h1>\n<ul>\n};
86         }
87         print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
88
89         open(my $fh, '>:encoding(utf-8)', "html/$row->{authid}.html");
90         print $fh html_title($row->{full_name}, "bibliografija");
91         foreach my $category ( sort keys %{ $authors->{ $row->{authid} } } ) {
92                 print $fh qq|<h1>$category</h1>\n<ul>\n|;
93                 foreach my $biblionumber ( @{ $authors->{ $row->{authid} }->{$category} } ) {
94                         print $fh qq|<li><a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a></li>\n|;
95                 }
96                 print $fh qq|</ul>\n|;
97         }
98         print $fh html_end;
99         close($fh);
100
101 }
102
103 print $index html_end;
104
105 print dump( $authors );
106
107 print dump( $auth_header );
108
109
110