View | Details | Raw Unified | Return to bug 10892
Collapse All | Expand All

(-)a/C4/Koha.pm (-112 / +159 lines)
Lines 29-34 use Koha::DateUtils qw(dt_from_string); Link Here
29
use Memoize;
29
use Memoize;
30
use DateTime::Format::MySQL;
30
use DateTime::Format::MySQL;
31
use autouse 'Data::Dumper' => qw(Dumper);
31
use autouse 'Data::Dumper' => qw(Dumper);
32
use YAML::Syck;
32
33
33
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
34
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
34
35
Lines 674-794 sub getallthemes { Link Here
674
    return @themes;
675
    return @themes;
675
}
676
}
676
677
678
sub get_facets_from_yaml {
679
    my $marcflavor = shift;
680
    my $YAML_conf;
681
    if ($marcflavor eq "UNIMARC") {
682
        $YAML_conf = <<END;
683
topics:
684
  idx: 'su-to'
685
  label: 'Topics'
686
  tags:
687
    - 600ab
688
    - 601ab
689
    - 602ab
690
    - 604at
691
    - 605a
692
    - 606ax
693
    - 610a
694
  sep: ' - '
695
  order: 1
696
places:
697
  idx: 'su-geo'
698
  label: 'Places'
699
  tags:
700
    - 607a
701
  sep: ' - '
702
  order: 2
703
titles:
704
  idx: 'su-ut'
705
  label: 'Titles'
706
  tags:
707
    - 500a
708
    - 501a
709
    - 503a
710
  sep: ' - '
711
  order: 3
712
authors:
713
  idx: 'au'
714
  label: 'Authors'
715
  tags:
716
    - 700ab
717
    - 701ab
718
    - 702ab
719
  order: 4
720
series:
721
  idx: 'se'
722
  label: 'Series'
723
  tags:
724
    - 225a
725
  sep: ', '
726
  order: 5
727
branches:
728
  idx: 'branch'
729
  label: 'Libraries'
730
  tags:
731
    - 995b
732
  order: 6
733
location:
734
  idx: 'location'
735
  label: 'Location'
736
  tags:
737
    - 995e
738
  order: 7
739
740
END
741
    } else {
742
        $YAML_conf = <<END;
743
topics:
744
  idx: 'su-to'
745
  label: 'Topics'
746
  tags:
747
    - 650a
748
  sep: ' - '
749
  order: 1
750
places:
751
  idx: 'su-geo'
752
  label: 'Places'
753
  tags:
754
    - 651a
755
  sep: ' - '
756
  order: 2
757
titles:
758
  idx: 'su-ut'
759
  label: 'Titles'
760
  tags:
761
    - 630a
762
  sep: ' - '
763
  order: 3
764
authors:
765
  idx: 'au'
766
  label: 'Authors'
767
  tags:
768
    - 100a
769
    - 110a
770
    - 700a
771
  order: 4
772
peopleandorganizations:
773
  idx: 'su-na'
774
  label: 'People and Organizations'
775
  tags:
776
    - 600a
777
    - 610a
778
    - 611a
779
series:
780
  idx: 'se'
781
  label: 'Series'
782
  tags:
783
    - 440a
784
    - 490a
785
  sep: ', '
786
  order: 5
787
branches:
788
  idx: 'branch'
789
  label: 'Libraries'
790
  tags:
791
    - 995b
792
  order: 6
793
  sort: alpha_desc
794
location:
795
  idx: 'location'
796
  label: 'Location'
797
  tags:
798
    - 995c
799
  order: 7
800
itemtypes:
801
  idx: 'itype'
802
  label: 'ItemTypes'
803
  tags:
804
    - 952y
805
    - 942c
806
  order: 8
807
  sep: ' - '
808
809
END
810
    }
811
return YAML::Load($YAML_conf);
812
}
813
677
sub getFacets {
814
sub getFacets {
678
    my $facets;
815
    my $all_facets;
679
    if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
816
    my $marcflavor = C4::Context->preference("marcflavour");
680
        $facets = [
817
    $all_facets = get_facets_from_yaml ($marcflavor);
681
            {
818
# gets facets from YAML data
682
                idx   => 'su-to',
819
# return a reference to a hash with following values of each facet
683
                label => 'Topics',
820
# {facet_n}-> {idx => index_n                   string
684
                tags  => [ qw/ 600ab 601ab 602a 604at 605a 606ax 610a / ],
821
#              label => label_n                  string
685
                sep   => ' - ',
822
#              tags => [ fieldandsubfields       string : MARC tag code followed by MARC subtags codes
686
            },
823
#                        fieldandsubfields
687
            {
824
#                        fieldandsubfields ]
688
                idx   => 'su-geo',
825
#              order => order                    digit, or undef (don't show the facet). For the moment, only used to hide facet if undef.
689
                label => 'Places',
826
#              sep => separator}                 string
690
                tags  => [ qw/ 607a / ],
827
691
                sep   => ' - ',
828
# Some values are special and must be modified:
692
            },
829
# author
693
            {
830
    if ($marcflavor eq "UNIMARC") {
694
                idx   => 'su-ut',
831
	$all_facets->{authors}->{sep} = C4::Context->preference("UNIMARCAuthorsFacetsSeparator");
695
                label => 'Titles',
696
                tags  => [ qw/ 500a 501a 503a / ],
697
                sep   => ', ',
698
            },
699
            {
700
                idx   => 'au',
701
                label => 'Authors',
702
                tags  => [ qw/ 700ab 701ab 702ab / ],
703
                sep   => C4::Context->preference("UNIMARCAuthorsFacetsSeparator"),
704
            },
705
            {
706
                idx   => 'se',
707
                label => 'Series',
708
                tags  => [ qw/ 225a / ],
709
                sep   => ', ',
710
            },
711
            ];
712
713
            my $library_facet;
714
            unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) {
715
                $library_facet = {
716
                    idx  => 'branch',
717
                    label => 'Libraries',
718
                    tags        => [ qw/ 995b / ],
719
                };
720
            } else {
721
                $library_facet = {
722
                    idx  => 'location',
723
                    label => 'Location',
724
                    tags        => [ qw/ 995c / ],
725
                };
726
            }
727
            push( @$facets, $library_facet );
728
    }
832
    }
729
    else {
833
    unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) {
730
        $facets = [
834
	undef $all_facets->{location}->{order};
731
            {
835
    } else {
732
                idx   => 'su-to',
836
        undef $all_facets->{branches}->{order};
733
                label => 'Topics',
734
                tags  => [ qw/ 650a / ],
735
                sep   => '--',
736
            },
737
            #        {
738
            #        idx   => 'su-na',
739
            #        label => 'People and Organizations',
740
            #        tags  => [ qw/ 600a 610a 611a / ],
741
            #        sep   => 'a',
742
            #        },
743
            {
744
                idx   => 'su-geo',
745
                label => 'Places',
746
                tags  => [ qw/ 651a / ],
747
                sep   => '--',
748
            },
749
            {
750
                idx   => 'su-ut',
751
                label => 'Titles',
752
                tags  => [ qw/ 630a / ],
753
                sep   => '--',
754
            },
755
            {
756
                idx   => 'au',
757
                label => 'Authors',
758
                tags  => [ qw/ 100a 110a 700a / ],
759
                sep   => ', ',
760
            },
761
            {
762
                idx   => 'se',
763
                label => 'Series',
764
                tags  => [ qw/ 440a 490a / ],
765
                sep   => ', ',
766
            },
767
            {
768
                idx   => 'itype',
769
                label => 'ItemTypes',
770
                tags  => [ qw/ 952y 942c / ],
771
                sep   => ', ',
772
            },
773
            ];
774
775
            my $library_facet;
776
            unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) {
777
                $library_facet = {
778
                    idx  => 'branch',
779
                    label => 'Libraries',
780
                    tags        => [ qw / 952b / ],
781
                };
782
            } else {
783
                $library_facet = {
784
                    idx => 'location',
785
                    label => 'Location',
786
                    tags => [ qw / 952c / ],
787
                };
788
            }
789
            push( @$facets, $library_facet );
790
    }
837
    }
791
    return $facets;
838
    return $all_facets;
792
}
839
}
793
840
794
=head2 get_infos_of
841
=head2 get_infos_of
(-)a/C4/Search.pm (-10 / +25 lines)
Lines 340-345 sub getRecords { Link Here
340
    my $facets_counter = ();
340
    my $facets_counter = ();
341
    my $facets_info    = ();
341
    my $facets_info    = ();
342
    my $facets         = getFacets();
342
    my $facets         = getFacets();
343
# result : reference to a hash with the following informations for each facet:
344
# facet_n => {idx => index_n                   string
345
#            label => label_n                  string
346
#            tags => [ fieldandsubfields       string : MARC tag code followed by MARC subtags codes
347
#                      fieldandsubfields
348
#                      fieldandsubfields ]
349
#            order => 0                        digit : if 0 or void, don't show the facet
350
#            sort => type_of_string            string : 4 values : alpha_asc, alpha_desc, occur_asc, occur_desc
351
#            sep => separator}                 string
352
343
    my $facets_maxrecs = C4::Context->preference('maxRecordsForFacets')||20;
353
    my $facets_maxrecs = C4::Context->preference('maxRecordsForFacets')||20;
344
354
345
    my @facets_loop;    # stores the ref to array of hashes for template facets loop
355
    my @facets_loop;    # stores the ref to array of hashes for template facets loop
Lines 501-513 sub getRecords { Link Here
501
511
502
                    my $jmax =
512
                    my $jmax =
503
                      $size > $facets_maxrecs ? $facets_maxrecs : $size;
513
                      $size > $facets_maxrecs ? $facets_maxrecs : $size;
504
                    for my $facet (@$facets) {
514
# only display facets with {order} value undef
515
                    my @active_facets =  grep {defined $facets->{$_}->{order}} keys %{ $facets };
516
                    foreach my $facet_key (@active_facets) {
505
                        for ( my $j = 0 ; $j < $jmax ; $j++ ) {
517
                        for ( my $j = 0 ; $j < $jmax ; $j++ ) {
506
                            my $render_record =
518
                            my $render_record =
507
                              $results[ $i - 1 ]->record($j)->render();
519
                              $results[ $i - 1 ]->record($j)->render();
508
                            my @used_datas = ();
520
                            my @used_datas = ();
509
                            foreach my $tag ( @{ $facet->{tags} } ) {
521
                            foreach my $tag ( @{ $facets->{$facet_key}->{tags}} ) {
510
511
                                # avoid first line
522
                                # avoid first line
512
                                my $tag_num = substr( $tag, 0, 3 );
523
                                my $tag_num = substr( $tag, 0, 3 );
513
                                my $letters = substr( $tag, 3 );
524
                                my $letters = substr( $tag, 3 );
Lines 529-547 sub getRecords { Link Here
529
                                            push @values, $value;
540
                                            push @values, $value;
530
                                        }
541
                                        }
531
                                    }
542
                                    }
532
                                    my $data = join( $facet->{sep}, @values );
543
                                    my $data = join( $facets->{$facet_key}-> {sep}, @values );
533
                                    unless ( $data ~~ @used_datas ) {
544
                                    unless ( $data ~~ @used_datas ) {
534
                                        $facets_counter->{ $facet->{idx} }
545
                                        $facets_counter->{ $facets->{$facet_key}-> {idx} }
535
                                          ->{$data}++;
546
                                          ->{$data}++;
536
                                        push @used_datas, $data;
547
                                        push @used_datas, $data;
537
                                    }
548
                                    }
538
                                }    # fields
549
                                }    # fields
539
                            }    # field codes
550
                            }    # field codes
540
                        }    # records
551
                        }    # records
541
                        $facets_info->{ $facet->{idx} }->{label_value} =
552
                        $facets_info->{ $facets->{$facet_key}-> {idx} }->{label_value} =
542
                          $facet->{label};
553
                          $facets->{$facet_key}-> {label};
543
                        $facets_info->{ $facet->{idx} }->{expanded} =
554
                        $facets_info->{ $facets->{$facet_key}-> {idx} }->{expanded} =
544
                          $facet->{expanded};
555
                          $facets->{$facet_key}-> {expanded};
545
                    }    # facets
556
                    }    # facets
546
                }
557
                }
547
558
Lines 621-629 sub getRecords { Link Here
621
632
622
               # also, if it's a location code, use the name instead of the code
633
               # also, if it's a location code, use the name instead of the code
623
                                if ( $link_value =~ /location/ ) {
634
                                if ( $link_value =~ /location/ ) {
635
                                    warn $link_value ;
636
                                    warn $one_facet;
637
                                    warn $opac;
638
                                    warn $facet_label_value;
624
                                    $facet_label_value =
639
                                    $facet_label_value =
625
                                      GetKohaAuthorisedValueLib( 'LOC',
640
                                      GetKohaAuthorisedValueLib( 'LOC',
626
                                        $one_facet, $opac );
641
                                        $one_facet, $opac );
642
                                      warn $facet_label_value;
627
                                }
643
                                }
628
644
629
                # but we're down with the whole label being in the link's title.
645
                # but we're down with the whole label being in the link's title.
630
- 

Return to bug 10892