From 3d04be488e6e73840d5701f0290defa1f88c8943 Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Sun, 21 Oct 2007 15:11:38 -0500 Subject: [PATCH] adding branch groups search in intranet. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Branch.pm | 79 ++++++++++--------- catalogue/search.pl | 14 +++- .../prog/en/modules/catalogue/advsearch.tmpl | 20 ++++- 3 files changed, 68 insertions(+), 45 deletions(-) diff --git a/C4/Branch.pm b/C4/Branch.pm index 08b10aef22..f8edb6a99d 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -275,6 +275,41 @@ sub GetBranchCategory { return \@results; } +=head2 GetBranchCategories + + my $categories = GetBranchCategories($branchcode,$categorytype); + +Returns a list ref of anon hashrefs with keys eq columns of branchcategories table, +i.e. categorycode, categorydescription, categorytype, categoryname. +if $branchcode and/or $categorytype are passed, limit set to categories that +$branchcode is a member of , and to $categorytype. + +=cut + +sub GetBranchCategories { + my ($branchcode,$categorytype) = @_; + my $dbh = C4::Context->dbh(); + my $query = "SELECT c.* FROM branchcategories c"; + my (@where, @bind); + if($branchcode) { + $query .= ",branchrelations r, branches b "; + push @where, "c.categorycode=r.categorycode and r.branchcode=? "; + push @bind , $branchcode; + } + if ($categorytype) { + push @where, " c.categorytype=? "; + push @bind, $categorytype; + } + $query .= " where " . join(" and ", @where) if(@where); + $query .= " order by categorytype,c.categorycode"; + my $sth=$dbh->prepare( $query); + $sth->execute(@bind); + + my $branchcats = $sth->fetchall_arrayref({}); + $sth->finish(); + return( $branchcats ); +} + =head2 GetCategoryTypes $categorytypes = GetCategoryTypes; @@ -353,39 +388,6 @@ sub get_branchinfos_of { return C4::Koha::get_infos_of( $query, 'branchcode' ); } -=head2 GetBranchCategories - - my $categories = GetBranchCategories($branchcode,$categorytype); - -Returns a list ref of anon hashrefs with keys eq columns of branchcategories table, -i.e. categorycode, categorydescription, categorytype, categoryname. -if $branchcode and/or $categorytype are passed, limit set to categories that -$branchcode is a member of , and to $categorytype. - -=cut - -sub GetBranchCategories($$) { - my ($branchcode,$categorytype) = @_; - my $dbh = C4::Context->dbh(); - my $select = "SELECT c.* FROM branchcategories c"; - my (@where, @bind); - if($branchcode) { - $select .= ",branchrelations r, branches b "; - push @where, "c.categorycode=r.categorycode and r.branchcode=? "; - push @bind , $branchcode; - } - if ($categorytype) { - push @where, " c.categorytype=? "; - push @bind, $categorytype; - } - my $sth=$dbh->prepare( $select . " where " . join(" and ", @where) ); - $sth->execute(@bind); - - my $branchcats = $sth->fetchall_arrayref({}); - $sth->finish(); - return( $branchcats ); -} - =head2 GetBranchesInCategory @@ -397,13 +399,16 @@ Returns a href: keys %$branches eq (branchcode,branchname) . sub GetBranchesInCategory($) { my ($categorycode) = @_; - my $dbh = C4::context->dbh(); - my $sth=$dbh->prepare( "SELECT branchcode, branchname FROM branchrelations r, branches b + my @branches; + my $dbh = C4::Context->dbh(); + my $sth=$dbh->prepare( "SELECT b.branchcode FROM branchrelations r, branches b where r.branchcode=b.branchcode and r.categorycode=?"); $sth->execute($categorycode); - my $branches = $sth->fetchall_hashref; + while (my $branch = $sth->fetchrow) { + push @branches, $branch; + } $sth->finish(); - return( $branches ); + return( \@branches ); } =head2 GetBranchInfo diff --git a/catalogue/search.pl b/catalogue/search.pl index da672d7ec2..fff41df184 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -162,13 +162,12 @@ my ($template,$borrowernumber,$cookie); # decide which template to use my $template_name; my @params = $cgi->param("limit"); -if ((@params>=1) || ($cgi->param("q")) ) { +if ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) ) { $template_name = 'catalogue/results.tmpl'; } else { $template_name = 'catalogue/advsearch.tmpl'; } - # load the template ($template, $borrowernumber, $cookie) = get_template_and_user({ template_name => $template_name, @@ -216,9 +215,12 @@ my $branches = GetBranches(); my @branch_loop; #push @branch_loop, {value => "", branchname => "All Branches", }; for my $branch_hash (sort keys %$branches) { - push @branch_loop, {value => "branch: $branch_hash", branchname => $branches->{$branch_hash}->{'branchname'}, }; + push @branch_loop, {value => "branch:$branch_hash" , branchname => $branches->{$branch_hash}->{'branchname'}, }; } -$template->param(branchloop => \@branch_loop,); + +my $categories = GetBranchCategories(undef,'searchdomain'); + +$template->param(branchloop => \@branch_loop, searchdomainloop => $categories); # load the itemtypes (Called Collection Codes in the template -- used for circ rules ) my $itemtypes = GetItemTypes; @@ -345,6 +347,10 @@ my @operands; my @limits; @limits = split("\0",$params->{'limit'}) if $params->{'limit'}; +if($params->{'multibranchlimit'}) { +push @limits, join(" or ", map { "branch: $_ "} @{GetBranchesInCategory($params->{'multibranchlimit'})}) ; +} + my $available; foreach my $limit(@limits) { if ($limit =~/available/) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl index 9e36d20e0b..07ad4aaf3c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl @@ -436,15 +436,27 @@
Location and availability:

-

+

+ +

-

-

+ +

OR

+

+ +

+
-- 2.39.5