Bug 28847: Move SearchLimitLibrary code to QueryBuilder Modules
This patch removes the code from the search scripts into QueryBuilder modules. To test: 1 - Have a library group defined as a search group for both staff and opac 2 - Search on staff client and opac with that group limit and a single branch limit 3 - Note your results/counts 4 - Note the visuals of the search description 5 - Apply patch 6 - Repeat searches 7 - All should work as before Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
01bb1f2787
commit
777c519c5a
30
C4/Search.pm
30
C4/Search.pm
|
|
@ -1472,6 +1472,36 @@ sub buildQuery {
|
|||
$limit_cgi .= "&limit=" . uri_escape_utf8($this_limit);
|
||||
$limit_desc .= " $this_limit";
|
||||
}
|
||||
elsif ( $this_limit =~ 'multibranchlimit|^branch' ) {
|
||||
$limit_cgi .= "&limit=" . uri_escape_utf8($this_limit);
|
||||
$limit .= " and " if $limit || $query;
|
||||
my $branchfield = C4::Context->preference('SearchLimitLibrary');
|
||||
my @branchcodes;
|
||||
if( $this_limit =~ 'multibranchlimit' ){
|
||||
my ($group_id) = ( $this_limit =~ /^multibranchlimit:(.*)$/ );
|
||||
my $search_group = Koha::Library::Groups->find( $group_id );
|
||||
@branchcodes = map { $_->branchcode } $search_group->all_libraries;
|
||||
@branchcodes = sort { $a cmp $b } @branchcodes;
|
||||
} else {
|
||||
@branchcodes = ( $this_limit =~ /^branch:(.*)$/ );
|
||||
}
|
||||
|
||||
if (@branchcodes) {
|
||||
if ( $branchfield eq "homebranch" ) {
|
||||
$this_limit = sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes;
|
||||
}
|
||||
elsif ( $branchfield eq "holdingbranch" ) {
|
||||
$this_limit = sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes;
|
||||
}
|
||||
else {
|
||||
$this_limit = sprintf "(%s or %s)",
|
||||
join( " or ", map { 'homebranch: ' . $_ } @branchcodes ),
|
||||
join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes );
|
||||
}
|
||||
}
|
||||
$limit .= "$this_limit";
|
||||
$limit_desc .= " $this_limit";
|
||||
}
|
||||
|
||||
# Regular old limits
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -1011,6 +1011,32 @@ sub _fix_limit_special_cases {
|
|||
$date = $self->_modify_string_by_type(type => 'st-year', operand => $date);
|
||||
push @new_lim, "date-of-publication:$date";
|
||||
}
|
||||
elsif ( $l =~ 'multibranchlimit|^branch' ) {
|
||||
my $branchfield = C4::Context->preference('SearchLimitLibrary');
|
||||
my @branchcodes;
|
||||
if( $l =~ 'multibranchlimit' ) {
|
||||
my ($group_id) = ( $l =~ /^multibranchlimit:(.*)$/ );
|
||||
my $search_group = Koha::Library::Groups->find( $group_id );
|
||||
@branchcodes = map { $_->branchcode } $search_group->all_libraries;
|
||||
@branchcodes = sort { $a cmp $b } @branchcodes;
|
||||
} else {
|
||||
@branchcodes = ( $l =~ /^branch:(.*)$/ );
|
||||
}
|
||||
|
||||
if (@branchcodes) {
|
||||
if ( $branchfield eq "homebranch" ) {
|
||||
push @new_lim, sprintf "(%s)", join " OR ", map { 'homebranch: ' . $_ } @branchcodes;
|
||||
}
|
||||
elsif ( $branchfield eq "holdingbranch" ) {
|
||||
push @new_lim, sprintf "(%s)", join " OR ", map { 'holdingbranch: ' . $_ } @branchcodes;
|
||||
}
|
||||
else {
|
||||
push @new_lim, sprintf "(%s OR %s)",
|
||||
join( " OR ", map { 'homebranch: ' . $_ } @branchcodes ),
|
||||
join( " OR ", map { 'holdingbranch: ' . $_ } @branchcodes );
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ( $l =~ /^available$/ ) {
|
||||
push @new_lim, 'onloan:false';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -378,45 +378,6 @@ my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit');
|
|||
my %is_nolimit = map { $_ => 1 } @nolimits;
|
||||
@limits = grep { not $is_nolimit{$_} } @limits;
|
||||
|
||||
if ( $params->{'multibranchlimit'} ) {
|
||||
my $branchfield = C4::Context->preference('SearchLimitLibrary');
|
||||
my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
|
||||
my @branchcodes = map { $_->branchcode } $search_group->all_libraries;
|
||||
|
||||
if (@branchcodes) {
|
||||
if ( $branchfield eq "homebranch" ) {
|
||||
push @limits, sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes;
|
||||
}
|
||||
elsif ( $branchfield eq "holdingbranch" ) {
|
||||
push @limits, sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes;
|
||||
}
|
||||
else {
|
||||
push @limits, sprintf "(%s or %s)",
|
||||
join( " or ", map { 'homebranch: ' . $_ } @branchcodes ),
|
||||
join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( my $i=0; $i<@limits; $i++ ) {
|
||||
if ( $limits[$i] =~ /^branch:/ ) {
|
||||
my $branchfield = C4::Context->preference('SearchLimitLibrary');
|
||||
if ( $branchfield eq "homebranch" ) {
|
||||
$limits[$i] =~ s/branch/homebranch/;
|
||||
}
|
||||
elsif ( $branchfield eq "holdingbranch" ) {
|
||||
$limits[$i] =~ s/branch/holdingbranch/;
|
||||
}
|
||||
else {
|
||||
my $homebranchlimit = $limits[$i];
|
||||
my $holdingbranchlimit = $limits[$i];
|
||||
$homebranchlimit =~ s/branch/homebranch/;
|
||||
$holdingbranchlimit =~ s/branch/holdingbranch/;
|
||||
$limits[$i] = "($homebranchlimit or $holdingbranchlimit)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $available;
|
||||
foreach my $limit(@limits) {
|
||||
if ($limit =~/available/) {
|
||||
|
|
|
|||
|
|
@ -446,45 +446,6 @@ if (@searchCategories > 0) {
|
|||
|
||||
@limits = map { uri_unescape($_) } @limits;
|
||||
|
||||
if ( $params->{'multibranchlimit'} || ( $branch_group_limit && $branch_group_limit =~ /^multibranchlimit-/ ) ) {
|
||||
my $branchfield = C4::Context->preference('SearchLimitLibrary');
|
||||
my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
|
||||
|
||||
my @branchcodes = map { $_->branchcode } $search_group->all_libraries;
|
||||
|
||||
if (@branchcodes) {
|
||||
if ( $branchfield eq "homebranch" ) {
|
||||
push @limits, sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes;
|
||||
}
|
||||
elsif ( $branchfield eq "holdingbranch" ) {
|
||||
push @limits, sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes;
|
||||
}
|
||||
else {
|
||||
push @limits, sprintf "(%s or %s)",
|
||||
join( " or ", map { 'homebranch: ' . $_ } @branchcodes ),
|
||||
join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( my $i=0; $i<@limits; $i++ ) {
|
||||
if ( $limits[$i] =~ /^branch:/ ) {
|
||||
my $branchfield = C4::Context->preference('SearchLimitLibrary');
|
||||
if ( $branchfield eq "homebranch" ) {
|
||||
$limits[$i] =~ s/branch/homebranch/;
|
||||
}
|
||||
elsif ( $branchfield eq "holdingbranch" ) {
|
||||
$limits[$i] =~ s/branch/holdingbranch/;
|
||||
}
|
||||
else {
|
||||
my $homebranchlimit = $limits[$i];
|
||||
my $holdingbranchlimit = $limits[$i];
|
||||
$homebranchlimit =~ s/branch/homebranch/;
|
||||
$holdingbranchlimit =~ s/branch/holdingbranch/;
|
||||
$limits[$i] = "($homebranchlimit or $holdingbranchlimit)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $available;
|
||||
foreach my $limit(@limits) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue