finally fixed count with unique_biblionumber
[koha-bibliografija] / html.pl
diff --git a/html.pl b/html.pl
index 38f11b0..cc7089c 100755 (executable)
--- a/html.pl
+++ b/html.pl
@@ -311,13 +311,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};
@@ -432,13 +433,21 @@ 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/^_/;
                foreach my $category ( keys %{ $authors->{$authid}->{$type} } ) {
-                       foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
+                       foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) {
                                $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }++;
                        }
                }
@@ -446,17 +455,12 @@ sub count_author_years {
        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 = @_;
 
+       debug 'html_year_selection authids=', [ @authids ];
+
        print $fh qq|<span id="years">Godine:\n|;
        my $type_cat_count = {};
        my $years;
@@ -465,6 +469,8 @@ sub html_year_selection {
                $years = count_author_years( $years, $authid );
        }
 
+       debug 'years' => $years;
+
        foreach my $year ( sort { $b <=> $a } keys %$years ) {
                print $fh qq|<label><input name="year_selection" value="$year" type=checkbox onClick="toggle_year($year, this)" checked="checked">$year</label>&nbsp;\n|;
                foreach my $type_cat ( keys %{ $years->{$year} } ) {
@@ -493,6 +499,8 @@ var type_cat_count = |, encode_json($type_cat_count), q|;
 
        |;
 
+       debug 'type_cat_count' => $type_cat_count;
+
        # TOC
        print $fh qq|<ul id="toc">\n|;
        my $i = 0;
@@ -556,7 +564,7 @@ my $department_category_author;
 foreach my $department ( sort keys %$auth_department ) {
        foreach my $authid ( sort @{ $auth_department->{$department} } ) {
                my   @categories = keys %{ $authors->{$authid}->{aut} };
-               push @categories,  keys %{ $authors->{$authid}->{sec} };
+               push @categories,  keys %{ $authors->{$authid}->{__sec} };
                foreach my $category ( sort @categories ) {
                        push @{ $department_category_author->{$department}->{$category} }, $authid;
                        push @{ $department_category_author->{'AAA_ukupno'}->{$category} }, $authid if $department_in_sum->{$department};
@@ -616,12 +624,12 @@ foreach my $department ( sort keys %$department_category_author ) {
        }
        html_year_selection $fh => @authids;
 
-       department_html( $fh, $department, 'aut', 'Primarno autorstvo' );
-
-#      department_html( $fh, $department, 'sec', 'Sekundarno autorstvo' );
-       department_html( $fh, $department, 'edt', 'Uredništva' );
-       department_html( $fh, $department, 'trl', 'Prijevodi' );
-       department_html( $fh, $department, '_ostalo', 'Ostalo' );
+       my $i = 0;
+       while ( $i < $#toc_type_label ) {
+               my $type  = $toc_type_label[$i++] || die "type";
+               my $label = $toc_type_label[$i++] || die "label";
+               department_html( $fh, $department, $type, $label );
+       }
 
        print $fh html_end;
        close($fh);