+=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;
+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');
+}
+