From 70f46147a6d5cca2f58cc8e66260effe9f6349e3 Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Sun, 21 Oct 2007 15:11:37 -0500 Subject: [PATCH] Extending branch categories : adding search domains. partial commit. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Branch.pm | 107 ++++++++++++++++-- admin/branches.pl | 47 ++++---- installer/kohastructure.sql | 8 +- .../prog/en/modules/admin/branches.tmpl | 30 +++-- 4 files changed, 149 insertions(+), 43 deletions(-) diff --git a/C4/Branch.pm b/C4/Branch.pm index 561ec2c9d6..08b10aef22 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -53,6 +53,9 @@ The functions in this module deal with branches. &ModBranch &CheckBranchCategorycode &GetBranchInfo + &GetCategoryTypes + &GetBranchCategories + &GetBranchesInCategory &ModBranchCategoryInfo &DelBranch &DelBranchCategory @@ -64,6 +67,9 @@ The functions in this module deal with branches. returns informations about ALL branches. Create a branch selector with the following code IndependantBranches Insensitive... + GetBranchInfo() returns the same information without the problems of this function + (namespace collision, mainly). You should probably use that, and replace GetBranches() + with GetBranchInfo() where you see it in the code. =head3 in PERL SCRIPT @@ -118,7 +124,8 @@ sub GetBranches { # you to list the categories that a branch belongs to: # you'd have to list keys %$branch, and remove those keys # that aren't fields in the "branches" table. - $branch->{$cat} = 1; + # $branch->{$cat} = 1; + $branch->{category}{$cat} = 1; } $branches{ $branch->{'branchcode'} } = $branch; } @@ -268,6 +275,23 @@ sub GetBranchCategory { return \@results; } +=head2 GetCategoryTypes + +$categorytypes = GetCategoryTypes; +returns a list of category types. +Currently these types are HARDCODED. +type: 'searchdomain' defines a group of agencies that the calling library may search in. +Other usage of agency categories falls under type: 'properties'. + to allow for other uses of categories. +The searchdomain bit may be better implemented as a separate module, but +the categories were already here, and minimally used. +=cut + + #TODO manage category types. rename possibly to 'agency domains' ? as borrowergroups are called categories. +sub GetCategoryTypes() { + return ( 'searchdomain','properties'); +} + =head2 GetBranch $branch = GetBranch( $query, $branches ); @@ -302,7 +326,6 @@ sub GetBranchDetail { return $branchname; } - =head2 get_branchinfos_of my $branchinfos_of = get_branchinfos_of(@branchcodes); @@ -330,19 +353,75 @@ 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 + + my $branches = GetBranchesInCategory($categorycode); + +Returns a href: keys %$branches eq (branchcode,branchname) . + +=cut + +sub GetBranchesInCategory($) { + my ($categorycode) = @_; + my $dbh = C4::context->dbh(); + my $sth=$dbh->prepare( "SELECT branchcode, branchname FROM branchrelations r, branches b + where r.branchcode=b.branchcode and r.categorycode=?"); + $sth->execute($categorycode); + my $branches = $sth->fetchall_hashref; + $sth->finish(); + return( $branches ); +} + =head2 GetBranchInfo $results = GetBranchInfo($branchcode); returns C<$results>, a reference to an array of hashes containing branches. - +if $branchcode, just this branch, with associated categories. +if ! $branchcode && $categorytype, all branches in the category. =cut sub GetBranchInfo { - my ($branchcode) = @_; + my ($branchcode,$categorytype) = @_; my $dbh = C4::Context->dbh; my $sth; - if ($branchcode) { + + + if ($branchcode) { $sth = $dbh->prepare( "Select * from branches where branchcode = ? order by branchcode"); @@ -354,10 +433,16 @@ sub GetBranchInfo { } my @results; while ( my $data = $sth->fetchrow_hashref ) { - my $nsth = - $dbh->prepare( - "select categorycode from branchrelations where branchcode = ?"); - $nsth->execute( $data->{'branchcode'} ); + my @bind = ($data->{'branchcode'}); + my $query= "select r.categorycode from branchrelations r"; + $query .= ", branchcategories c " if($categorytype); + $query .= " where branchcode=? "; + if($categorytype) { + $query .= " and c.categorytype=? and r.categorycode=c.categorycode"; + push @bind, $categorytype; + } + my $nsth=$dbh->prepare($query); + $nsth->execute( @bind ); my @cats = (); while ( my ($cat) = $nsth->fetchrow_array ) { push( @cats, $cat ); @@ -395,8 +480,8 @@ sub ModBranchCategoryInfo { my ($data) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("replace branchcategories (categorycode,categoryname,codedescription) values (?,?,?)"); - $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'} ); + my $sth = $dbh->prepare("replace branchcategories (categorycode,categoryname,codedescription,categorytype) values (?,?,?,?)"); + $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'} ); $sth->finish; } diff --git a/admin/branches.pl b/admin/branches.pl index 0b7532c6e7..4f314bd26f 100755 --- a/admin/branches.pl +++ b/admin/branches.pl @@ -282,6 +282,7 @@ sub editbranchform { { categoryname => $cat->{'categoryname'}, categorycode => $cat->{'categorycode'}, + categorytype => $cat->{'categorytype'}, codedescription => $cat->{'codedescription'}, checked => $checked, }; @@ -303,13 +304,19 @@ sub editcatform { my ($categorycode,$innertemplate) = @_; warn "cat : $categorycode"; my $data; - if ($categorycode) { + my @cats; + $innertemplate->param( categorytype => \@cats); + if ($categorycode) { $data = GetBranchCategory($categorycode); $data = $data->[0]; - $innertemplate->param( categorycode => $data->{'categorycode'} ); - $innertemplate->param( categoryname => $data->{'categoryname'} ); - $innertemplate->param( codedescription => $data->{'codedescription'} ); + $innertemplate->param( categorycode => $data->{'categorycode'} , + categoryname => $data->{'categoryname'}, + codedescription => $data->{'codedescription'} , + ); } + for my $ctype (GetCategoryTypes()) { + push @cats , { type => $ctype , selected => ($data->{'categorytype'} eq $ctype) }; + } } sub deleteconfirm { @@ -328,7 +335,7 @@ sub branchinfotable { $branchinfo = GetBranchInfo($branchcode); } else { - $branchinfo = GetBranchInfo(); + $branchinfo = GetBranchInfo(undef,'properties'); } my $toggle; my $i; @@ -408,20 +415,20 @@ sub branchinfotable { $i++; } my @branchcategories = (); - my $catinfo = GetBranchCategory(); - $i = 0; - foreach my $cat (@$catinfo) { - ( $i % 2 ) ? ( $toggle = 1 ) : ( $toggle = 0 ); - push @branchcategories, - { - toggle => $toggle, - categoryname => $cat->{'categoryname'}, - categorycode => $cat->{'categorycode'}, - codedescription => $cat->{'codedescription'}, - }; - $i++; - } - + for my $ctype ( GetCategoryTypes() ) { + my $catinfo = GetBranchCategories(undef,$ctype); + my @categories; + foreach my $cat (@$catinfo) { + push @categories, + { + categoryname => $cat->{'categoryname'}, + categorycode => $cat->{'categorycode'}, + codedescription => $cat->{'codedescription'}, + categorytype => $cat->{'categorytype'}, + }; + } + push @branchcategories, { categorytype => $ctype , $ctype => 1 , catloop => \@categories}; + } $innertemplate->param( branches => \@loop_data, branchcategories => \@branchcategories @@ -429,7 +436,7 @@ sub branchinfotable { } -# FIXME logic seems wrong +# FIXME logic seems wrong ## sub is not used. sub branchcategoriestable { my $innertemplate = shift; #Needs to be implemented... diff --git a/installer/kohastructure.sql b/installer/kohastructure.sql index 50d53c5f26..59aa4f715c 100644 --- a/installer/kohastructure.sql +++ b/installer/kohastructure.sql @@ -489,9 +489,10 @@ CREATE TABLE `borrowers` ( DROP TABLE IF EXISTS `branchcategories`; CREATE TABLE `branchcategories` ( - `categorycode` varchar(4) NOT NULL default '', - `categoryname` mediumtext, + `categorycode` char(10) NOT NULL default '', + `categoryname` varchar(32), `codedescription` mediumtext, + `categorytype` varchar(16), PRIMARY KEY (`categorycode`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -522,7 +523,8 @@ CREATE TABLE `branches` ( DROP TABLE IF EXISTS `branchrelations`; CREATE TABLE `branchrelations` ( `branchcode` char(10) NOT NULL default '', - `categorycode` varchar(4) NOT NULL default '', + `categorycode` char(10) NOT NULL default '', + `relation` char(10) default NULL, PRIMARY KEY (`branchcode`,`categorycode`), KEY `branchcode` (`branchcode`), KEY `categorycode` (`categorycode`), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tmpl index 034458f282..35bd1bc9f7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tmpl @@ -114,9 +114,9 @@ Name Code Address - Category - Library IP - Library Printer + Properties + IP + Printer   @@ -143,7 +143,6 @@ - (no categories set)
@@ -171,8 +170,10 @@ - - + + +
Agency Categories
+ @@ -180,7 +181,7 @@ - + @@ -192,6 +193,8 @@
Agency Categories: PropertiesSearch Domain
Name Code   
+ +

No Agency Categories defined. @@ -216,7 +219,7 @@ - " /> + " />

  • @@ -226,7 +229,16 @@
  • " /> -
  • + +
  • + + +
  • + -- 2.39.5