Bugzilla – Attachment 21141 Details for
Bug 10892
Make facets customisable - step 1 : store facet config in YAML block
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PATCH] Bug 10892 : Make facets customizable - step 1 store configuration in YAML block
0001-O-This-is-a-combination-of-2-commits.patch (text/plain), 12.24 KB, created by
Mathieu Saby
on 2013-09-17 16:05:03 UTC
(
hide
)
Description:
[PATCH] Bug 10892 : Make facets customizable - step 1 store configuration in YAML block
Filename:
MIME Type:
Creator:
Mathieu Saby
Created:
2013-09-17 16:05:03 UTC
Size:
12.24 KB
patch
obsolete
>From 7584cf8de1d90209567023e6cf076671f5ecdf61 Mon Sep 17 00:00:00 2001 >From: Mathieu Saby <mathieu.saby@univ-rennes2.fr> >Date: Mon, 16 Sep 2013 11:37:51 +0200 >Subject: [PATCH] Bug 10892 : Make facets customizable - step 1 store configuration in YAML block >Content-Type: text/plain; charset="utf-8" > >This is the first of a group of patches whose goal is to make facets configurable. >This patch stores facet configuration in a YAML block, within Koha.pm file. >Next steps will be to use an external YAML file. > >No functional changes are expected, except for UNIMARC : >I took the occasion for fixing location facets, which were broken (wrongly build on 995$c instead of 995$e). > >To test : >1. make some searches, use facets >2. apply >3. make the same searches, use facets the same way. No differences should be visible >4. in a UNIMARC Koha, check location facets are visible after applying the patch >--- > C4/Koha.pm | 271 ++++++++++++++++++++++++++++++++++------------------------ > C4/Search.pm | 34 ++++++-- > 2 files changed, 184 insertions(+), 121 deletions(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index c5b32a6..b67ff05 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -29,6 +29,7 @@ use Koha::DateUtils qw(dt_from_string); > use Memoize; > use DateTime::Format::MySQL; > use autouse 'Data::Dumper' => qw(Dumper); >+use YAML::Syck; > > use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); > >@@ -674,121 +675,167 @@ sub getallthemes { > return @themes; > } > >+sub get_facets_from_yaml { >+ my $marcflavor = shift; >+ my $YAML_conf; >+ if ($marcflavor eq "UNIMARC") { >+ $YAML_conf = <<END; >+topics: >+ idx: 'su-to' >+ label: 'Topics' >+ tags: >+ - 600ab >+ - 601ab >+ - 602ab >+ - 604at >+ - 605a >+ - 606ax >+ - 610a >+ sep: ' - ' >+ order: 1 >+places: >+ idx: 'su-geo' >+ label: 'Places' >+ tags: >+ - 607a >+ sep: ' - ' >+ order: 2 >+titles: >+ idx: 'su-ut' >+ label: 'Titles' >+ tags: >+ - 500a >+ - 501a >+ - 503a >+ sep: ' - ' >+ order: 3 >+authors: >+ idx: 'au' >+ label: 'Authors' >+ tags: >+ - 700ab >+ - 701ab >+ - 702ab >+ order: 4 >+series: >+ idx: 'se' >+ label: 'Series' >+ tags: >+ - 225a >+ sep: ', ' >+ order: 5 >+branches: >+ idx: 'branch' >+ label: 'Libraries' >+ tags: >+ - 995b >+ order: 6 >+location: >+ idx: 'location' >+ label: 'Location' >+ tags: >+ - 995e >+ order: 7 >+ >+END >+ } else { >+ $YAML_conf = <<END; >+topics: >+ idx: 'su-to' >+ label: 'Topics' >+ tags: >+ - 650a >+ sep: ' - ' >+ order: 1 >+places: >+ idx: 'su-geo' >+ label: 'Places' >+ tags: >+ - 651a >+ sep: ' - ' >+ order: 2 >+titles: >+ idx: 'su-ut' >+ label: 'Titles' >+ tags: >+ - 630a >+ sep: ' - ' >+ order: 3 >+authors: >+ idx: 'au' >+ label: 'Authors' >+ tags: >+ - 100a >+ - 110a >+ - 700a >+ order: 4 >+peopleandorganizations: >+ idx: 'su-na' >+ label: 'People and Organizations' >+ tags: >+ - 600a >+ - 610a >+ - 611a >+series: >+ idx: 'se' >+ label: 'Series' >+ tags: >+ - 440a >+ - 490a >+ sep: ', ' >+ order: 5 >+branches: >+ idx: 'branch' >+ label: 'Libraries' >+ tags: >+ - 995b >+ order: 6 >+ sort: alpha_desc >+location: >+ idx: 'location' >+ label: 'Location' >+ tags: >+ - 995c >+ order: 7 >+itemtypes: >+ idx: 'itype' >+ label: 'ItemTypes' >+ tags: >+ - 952y >+ - 942c >+ order: 8 >+ sep: ' - ' >+ >+END >+ } >+return YAML::Load($YAML_conf); >+} >+ > sub getFacets { >- my $facets; >- if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) { >- $facets = [ >- { >- idx => 'su-to', >- label => 'Topics', >- tags => [ qw/ 600ab 601ab 602a 604at 605a 606ax 610a / ], >- sep => ' - ', >- }, >- { >- idx => 'su-geo', >- label => 'Places', >- tags => [ qw/ 607a / ], >- sep => ' - ', >- }, >- { >- idx => 'su-ut', >- label => 'Titles', >- tags => [ qw/ 500a 501a 503a / ], >- sep => ', ', >- }, >- { >- idx => 'au', >- label => 'Authors', >- tags => [ qw/ 700ab 701ab 702ab / ], >- sep => C4::Context->preference("UNIMARCAuthorsFacetsSeparator"), >- }, >- { >- idx => 'se', >- label => 'Series', >- tags => [ qw/ 225a / ], >- sep => ', ', >- }, >- ]; >- >- my $library_facet; >- unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) { >- $library_facet = { >- idx => 'branch', >- label => 'Libraries', >- tags => [ qw/ 995b / ], >- }; >- } else { >- $library_facet = { >- idx => 'location', >- label => 'Location', >- tags => [ qw/ 995c / ], >- }; >- } >- push( @$facets, $library_facet ); >+ my $all_facets; >+ my $marcflavor = C4::Context->preference("marcflavour"); >+ $all_facets = get_facets_from_yaml ($marcflavor); >+# gets facets from YAML data >+# return a reference to a hash with following values of each facet >+# {facet_n}-> {idx => index_n string >+# label => label_n string >+# tags => [ fieldandsubfields string : MARC tag code followed by MARC subtags codes >+# fieldandsubfields >+# fieldandsubfields ] >+# order => order digit, or undef (don't show the facet). For the moment, only used to hide facet if undef. >+# sep => separator} string >+ >+# Some values are special and must be modified: >+# author >+ if ($marcflavor eq "UNIMARC") { >+ $all_facets->{authors}->{sep} = C4::Context->preference("UNIMARCAuthorsFacetsSeparator"); > } >- else { >- $facets = [ >- { >- idx => 'su-to', >- label => 'Topics', >- tags => [ qw/ 650a / ], >- sep => '--', >- }, >- # { >- # idx => 'su-na', >- # label => 'People and Organizations', >- # tags => [ qw/ 600a 610a 611a / ], >- # sep => 'a', >- # }, >- { >- idx => 'su-geo', >- label => 'Places', >- tags => [ qw/ 651a / ], >- sep => '--', >- }, >- { >- idx => 'su-ut', >- label => 'Titles', >- tags => [ qw/ 630a / ], >- sep => '--', >- }, >- { >- idx => 'au', >- label => 'Authors', >- tags => [ qw/ 100a 110a 700a / ], >- sep => ', ', >- }, >- { >- idx => 'se', >- label => 'Series', >- tags => [ qw/ 440a 490a / ], >- sep => ', ', >- }, >- { >- idx => 'itype', >- label => 'ItemTypes', >- tags => [ qw/ 952y 942c / ], >- sep => ', ', >- }, >- ]; >- >- my $library_facet; >- unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) { >- $library_facet = { >- idx => 'branch', >- label => 'Libraries', >- tags => [ qw / 952b / ], >- }; >- } else { >- $library_facet = { >- idx => 'location', >- label => 'Location', >- tags => [ qw / 952c / ], >- }; >- } >- push( @$facets, $library_facet ); >+ unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) { >+ undef $all_facets->{location}->{order}; >+ } else { >+ undef $all_facets->{branches}->{order}; > } >- return $facets; >+ return $all_facets; > } > > =head2 get_infos_of >diff --git a/C4/Search.pm b/C4/Search.pm >index 0453b91..2b79b2a 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -340,6 +340,16 @@ sub getRecords { > my $facets_counter = (); > my $facets_info = (); > my $facets = getFacets(); >+# result : reference to a hash with the following informations for each facet: >+# facet_n => {idx => index_n string >+# label => label_n string >+# tags => [ fieldandsubfields string : MARC tag code followed by MARC subtags codes >+# fieldandsubfields >+# fieldandsubfields ] >+# order => 0 digit : if 0 or void, don't show the facet >+# sort => type_of_string string : 4 values : alpha_asc, alpha_desc, occur_asc, occur_desc >+# sep => separator} string >+ > my $facets_maxrecs = C4::Context->preference('maxRecordsForFacets')||20; > > my @facets_loop; # stores the ref to array of hashes for template facets loop >@@ -501,13 +511,14 @@ sub getRecords { > > my $jmax = > $size > $facets_maxrecs ? $facets_maxrecs : $size; >- for my $facet (@$facets) { >+# only display facets with {order} value undef >+ my @active_facets = grep {defined $facets->{$_}->{order}} keys %{ $facets }; >+ foreach my $facet_key (@active_facets) { > for ( my $j = 0 ; $j < $jmax ; $j++ ) { > my $render_record = > $results[ $i - 1 ]->record($j)->render(); > my @used_datas = (); >- foreach my $tag ( @{ $facet->{tags} } ) { >- >+ foreach my $tag ( @{ $facets->{$facet_key}->{tags}} ) { > # avoid first line > my $tag_num = substr( $tag, 0, 3 ); > my $letters = substr( $tag, 3 ); >@@ -529,19 +540,19 @@ sub getRecords { > push @values, $value; > } > } >- my $data = join( $facet->{sep}, @values ); >+ my $data = join( $facets->{$facet_key}-> {sep}, @values ); > unless ( $data ~~ @used_datas ) { >- $facets_counter->{ $facet->{idx} } >+ $facets_counter->{ $facets->{$facet_key}-> {idx} } > ->{$data}++; > push @used_datas, $data; > } > } # fields > } # field codes > } # records >- $facets_info->{ $facet->{idx} }->{label_value} = >- $facet->{label}; >- $facets_info->{ $facet->{idx} }->{expanded} = >- $facet->{expanded}; >+ $facets_info->{ $facets->{$facet_key}-> {idx} }->{label_value} = >+ $facets->{$facet_key}-> {label}; >+ $facets_info->{ $facets->{$facet_key}-> {idx} }->{expanded} = >+ $facets->{$facet_key}-> {expanded}; > } # facets > } > >@@ -621,9 +632,14 @@ sub getRecords { > > # also, if it's a location code, use the name instead of the code > if ( $link_value =~ /location/ ) { >+ warn $link_value ; >+ warn $one_facet; >+ warn $opac; >+ warn $facet_label_value; > $facet_label_value = > GetKohaAuthorisedValueLib( 'LOC', > $one_facet, $opac ); >+ warn $facet_label_value; > } > > # but we're down with the whole label being in the link's title. >-- >1.7.9.5 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10892
: 21141