X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=html.pl;h=e9194b3d90e278e40c6443d00c34ad00199dbc78;hb=90916f5c0700c5ba54435feacfbe40c1c0a6dffb;hp=949563dc2c88f924e18787a020756a7c2fdd2497;hpb=e72d0f84429021225e6b54f42844fc5994089d6c;p=koha-bibliografija diff --git a/html.pl b/html.pl index 949563d..e9194b3 100755 --- a/html.pl +++ b/html.pl @@ -13,12 +13,28 @@ use Text::Unaccent; use Carp qw(confess); use utf8; use JSON; +use POSIX qw(strftime); +use Storable; use lib '/srv/koha_ffzg'; use C4::Context; use XML::LibXML; use XML::LibXSLT; +my $pid_file = '/dev/shm/bibliografija.pid'; +{ + if ( -e $pid_file ) { + open(my $fh, '<', $pid_file); + my $pid = <$fh>; + no autodie; # it will die on kill + kill 0, $pid || die "$0 allready running as pid $pid"; + } + open(my $fh, '>', $pid_file); + print $fh $$; + close($fh); +} + + my $dbh = C4::Context->dbh; sub debug { @@ -98,10 +114,11 @@ while( my $row = $sth_auth->fetchrow_hashref ) { debug 'department_in_group' => $department_in_group; foreach my $department ( keys %$department_in_sum ) { - $department_in_sum->{$department} = 0 unless $department =~ m/(centar|croaticum|katedra|odsjek)/i; +# $department_in_sum->{$department} = 0 unless $department =~ m/(centar|croaticum|katedra|odsjek)/i; } debug 'auth_department' => $auth_department; +store $auth_department, '/dev/shm/auth_department.storable'; debug 'auth_group' => $auth_group; debug 'department_in_sum' => $department_in_sum; @@ -111,10 +128,11 @@ my $marcxml; my $sth_select_authors = $dbh->prepare(q{ select - biblionumber, + biblioitems.biblionumber, itemtype, - marcxml + metadata as marcxml from biblioitems +join biblio_metadata on (biblio_metadata.biblionumber = biblioitems.biblionumber) where agerestriction > 0 }); @@ -129,6 +147,7 @@ where =cut my $biblio_year; +my $biblio_full_name; my $type_stats; my $parser = XML::LibXML->new(); @@ -199,6 +218,7 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) { my $extract = { '008' => undef, '100' => '(9|a)', + '245' => 'a', '680' => 'i', '700' => '(9|4|a)', '942' => '(t|r|v)' @@ -278,10 +298,13 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) { foreach my $authid ( @first_author ) { push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber}; } + $biblio_full_name->{ $row->{biblionumber} } = $data->{100}->[0]->{a}; } else { $have_100 = 0; } + $biblio_full_name->{ $row->{biblionumber} } ||= $data->{245}->[0]->{a}; + my $have_edt; if ( exists $data->{700} ) { @@ -303,23 +326,33 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) { $type_stats->{$type}++; - if ( $type =~ m/(edt|trl|com|ctb)/ ) { - push @{ $authors->{$authid}->{sec}->{ $category } }, $row->{biblionumber}; - push @{ $authors->{$authid}->{$1}->{ $category } }, $row->{biblionumber}; - } elsif ( $type =~ m/aut/ ) { - if ( ! $have_100 ) { - $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt; - if ( $have_edt ) { - $skip->{ have_700_edt }->{ $row->{biblionumber} }++; + my @types = split(/[\s\/]+/, $type); + + foreach my $type ( @types ) { + my $type = substr($type,0,3); + $type_stats->{_count_each_type}->{$type}++; + + if ( $type =~ m/(edt|trl|com|ctb)/ ) { + push @{ $authors->{$authid}->{__sec}->{ $category } }, $row->{biblionumber}; + push @{ $authors->{$authid}->{$type}->{ $category } }, $row->{biblionumber}; + $type =~ s/(com|ctb)/_ostalo/; + push @{ $authors->{$authid}->{$type}->{ $category } }, $row->{biblionumber}; + + } elsif ( $type =~ m/aut/ ) { + if ( ! $have_100 ) { + $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt; + if ( $have_edt ) { + $skip->{ have_700_edt }->{ $row->{biblionumber} }++; + } else { + push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber}; + } } else { push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber}; } } else { - push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber}; +# warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data); + $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++; } - } else { -# warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data); - $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++; } } delete $data->{700}; @@ -330,9 +363,11 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) { } debug 'authors' => $authors; +store $authors, '/dev/shm/authors.storable'; debug 'type_stats' => $type_stats; debug 'skip' => $skip; debug 'biblio_year' => $biblio_year; +debug 'biblio_full_name' => $biblio_full_name; debug 'biblio_data' => $biblio_data; debug 'biblio_author_external' => $biblio_author_external; @@ -354,13 +389,17 @@ sub html_title { |, join(" ", @_), qq| + |; } sub html_end { - return qq|\n\n|; + return + qq|Zadnji puta osvježeno: |, + strftime("%Y-%m-%d %H:%M:%S\n", localtime()), + qq|\n\n|; } mkdir 'html' unless -d 'html'; @@ -381,62 +420,93 @@ sub li_biblio { qq|\n|; } +sub unique { + my $unique; + $unique->{$_}++ foreach @_; + return keys %$unique; +} + +sub unique_biblionumber { + my @v = unique @_; + return sort { + $biblio_year->{$b} <=> $biblio_year->{$a} || + $biblio_full_name->{$a} cmp $biblio_full_name->{$b} || + $a <=> $b + } @v; +} + sub author_html { my ( $fh, $authid, $type, $label ) = @_; return unless exists $authors->{$authid}->{$type}; - print $fh qq|

$label

\n|; + print $fh qq|

$label

\n|; foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) { my $label = $category_label->{$category} || 'Bez kategorije'; - print $fh qq|

$label

\n\n|; + print $fh qq|\n|; } } +my @toc_type_label = ( +'aut' => 'Primarno autorstvo', +'edt' => 'Uredništva', +'trl' => 'Prijevodi', +'_ostalo' => 'Ostalo', +); + + sub count_author_years { + my $years = shift; my ($authid) = @_; - my $years; foreach my $type ( keys %{ $authors->{$authid} } ) { +# next if $type =~ m/^_/; # FIXME foreach my $category ( keys %{ $authors->{$authid}->{$type} } ) { - foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) { - $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }++; + foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) { + $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }->{ $biblionumber }++; } } } return $years; } -foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) { +sub html_year_selection { + my $fh = shift; + my @authids = unique @_; - my $first = substr( $row->{full_name}, 0, 1 ); - if ( $first ne $first_letter ) { - print $index qq{\n} if $first_letter; - $first_letter = $first; - print $index qq{

$first

\n\n} if $first_letter; + $first_letter = $first; + print $index qq{

$first

\n