X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=html.pl;h=3d9cfce0e96fcec5c2542e6ee1011e4f403af5c6;hb=626163e24773f07bb9131a80a3a111f052b64f24;hp=38f11b0794fd7e72f77d162c7bfee0c4c35e1447;hpb=729a8cca21dc52613bbf9a8e789252974f513766;p=koha-bibliografija diff --git a/html.pl b/html.pl index 38f11b0..3d9cfce 100755 --- a/html.pl +++ b/html.pl @@ -21,6 +21,20 @@ 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 { @@ -100,7 +114,7 @@ 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; @@ -311,13 +325,14 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) { $type_stats->{$type}++; - my @types = split(/\s+/, $type); + 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}->{__sec}->{ $category } }, $row->{biblionumber}; push @{ $authors->{$authid}->{$type}->{ $category } }, $row->{biblionumber}; $type =~ s/(com|ctb)/_ostalo/; push @{ $authors->{$authid}->{$type}->{ $category } }, $row->{biblionumber}; @@ -404,15 +419,19 @@ sub li_biblio { qq|\n|; } +sub unique { + my $unique; + $unique->{$_}++ foreach @_; + return keys %$unique; +} + sub unique_biblionumber { - my @v = @_; - my $u; - $u->{$_}++ foreach @v; + my @v = unique @_; return sort { $biblio_year->{$b} <=> $biblio_year->{$a} || $biblio_full_name->{$a} cmp $biblio_full_name->{$b} || $a <=> $b - } keys %$u; + } @v; } sub author_html { @@ -432,30 +451,33 @@ sub author_html { } } +my @toc_type_label = ( +'aut' => 'Primarno autorstvo', +'edt' => 'UredniÅ¡tva', +'trl' => 'Prijevodi', +'_ostalo' => 'Ostalo', +); + sub count_author_years { my $years = shift; my ($authid) = @_; 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; } -my @toc_type_label = ( -'aut' => 'Primarno autorstvo', -'edt' => 'UredniÅ¡tva', -'trl' => 'Prijevodi', -'_ostalo' => 'Ostalo', -); - sub html_year_selection { my $fh = shift; - my @authids = @_; + my @authids = unique @_; + + debug 'html_year_selection authids=', [ @authids ]; print $fh qq|Godine:\n|; my $type_cat_count = {}; @@ -465,13 +487,17 @@ sub html_year_selection { $years = count_author_years( $years, $authid ); } + debug 'years' => $years; + foreach my $year ( sort { $b <=> $a } keys %$years ) { print $fh qq| \n|; foreach my $type_cat ( keys %{ $years->{$year} } ) { - $type_cat_count->{ $type_cat } += $years->{$year}->{$type_cat}; + my $count = scalar keys %{ $years->{$year}->{$type_cat} }; + $years->{$year}->{$type_cat} = $count; # remove biblionumbers and use count + $type_cat_count->{ $type_cat } += $count; my ($type,$cat) = split(/-/, $type_cat); $type_cat_count->{_toc}->{$type}->{$cat}++; - $type_cat_count->{_toc_count}->{$type} += $years->{$year}->{$type_cat}; + $type_cat_count->{_toc_count}->{$type} += $count; } } @@ -493,6 +519,8 @@ var type_cat_count = |, encode_json($type_cat_count), q|; |; + debug 'type_cat_count' => $type_cat_count; + # TOC print $fh qq|\n|, html_end; close($dep_fh); @@ -700,12 +759,9 @@ sub table_count { my $label = shift @_; my $department = shift @_; my $group = shift @_; - my @biblionumbers = @_; - my $unique; - $unique->{$_}++ foreach @biblionumbers; - my @bibs = keys %$unique; - $table->{ffzg}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar @bibs; - $table->{external}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar grep { $biblio_author_external->{$_} } @bibs; + my @biblionumbers = unique @_; + $table->{ffzg}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar @biblionumbers; + $table->{external}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar grep { $biblio_author_external->{$_} } @biblionumbers; } foreach my $group ( '', keys %$azvo_group_title ) { @@ -797,3 +853,5 @@ close($fh2); rename 'html/azvo.new', 'html/azvo.html'; rename 'html/azvo2.new', 'html/azvo2.html'; +unlink $pid_file; +