BEGIN {
# set the version for version checking
- $VERSION = 3.02;
+ $VERSION = 3.07.00.049;
@ISA = qw(Exporter);
@EXPORT = qw(
&GetBranchCategory
&DelBranchCategory
&CheckCategoryUnique
&mybranch
+ &GetBranchesCount
);
@EXPORT_OK = qw( &onlymine &mybranch get_branch_code_from_name );
}
return C4::Context->userenv->{branch} || '';
}
-sub GetBranchesLoop (;$$) { # since this is what most pages want anyway
+sub GetBranchesLoop { # since this is what most pages want anyway
my $branch = @_ ? shift : mybranch(); # optional first argument is branchcode of "my branch", if preselection is wanted.
my $onlymine = @_ ? shift : onlymine();
my $branches = GetBranches($onlymine);
my @loop;
- foreach ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
+ foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
push @loop, {
- value => $_,
- selected => ($_ eq $branch) ? 1 : 0,
- branchname => $branches->{$_}->{branchname},
+ value => $branchcode,
+ branchcode => $branchcode,
+ selected => ($branchcode eq $branch) ? 1 : 0,
+ branchname => $branches->{$branchcode}->{branchname},
};
}
return \@loop;
=head2 GetBranchCategories
- my $categories = GetBranchCategories($branchcode,$categorytype);
+ my $categories = GetBranchCategories($branchcode,$categorytype,$show_in_pulldown,$selected_in_pulldown);
Returns a list ref of anon hashrefs with keys eq columns of branchcategories table,
i.e. categorycode, categorydescription, categorytype, categoryname.
=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 );
+ my ( $branchcode, $categorytype, $show_in_pulldown, $selected_in_pulldown ) = @_;
+ 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;
+ }
+
+ if ( defined( $show_in_pulldown ) ) {
+ push( @where, " c.show_in_pulldown = ? " );
+ push( @bind, $show_in_pulldown );
+ }
+
+ $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();
+
+ if ( $selected_in_pulldown ) {
+ foreach my $bc ( @$branchcats ) {
+ $bc->{'selected'} = 1 if ( $bc->{'categorycode'} eq $selected_in_pulldown );
+ }
+ }
+
+ return( $branchcats );
}
=head2 GetCategoryTypes
=cut
#TODO manage category types. rename possibly to 'agency domains' ? as borrowergroups are called categories.
-sub GetCategoryTypes() {
+sub GetCategoryTypes {
return ( 'searchdomain','properties');
}
=cut
-sub GetBranch ($$) {
+sub GetBranch {
my ( $query, $branches ) = @_; # get branch for this query from branches
my $branch = $query->param('branch');
my %cookie = $query->cookie('userenv');
=cut
-sub GetBranchesInCategory($) {
+sub GetBranchesInCategory {
my ($categorycode) = @_;
my @branches;
my $dbh = C4::Context->dbh();
my $dbh = C4::Context->dbh;
if ($data->{'add'}){
# we are doing an insert
- my $sth = $dbh->prepare("INSERT INTO branchcategories (categorycode,categoryname,codedescription,categorytype) VALUES (?,?,?,?)");
- $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'} );
+ my $sth = $dbh->prepare("INSERT INTO branchcategories (categorycode,categoryname,codedescription,categorytype,show_in_pulldown) VALUES (?,?,?,?,?)");
+ $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'} );
$sth->finish();
}
else {
# modifying
- my $sth = $dbh->prepare("UPDATE branchcategories SET categoryname=?,codedescription=?,categorytype=? WHERE categorycode=?");
- $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},uc( $data->{'categorycode'} ) );
+ my $sth = $dbh->prepare("UPDATE branchcategories SET categoryname=?,codedescription=?,categorytype=?,show_in_pulldown=? WHERE categorycode=?");
+ $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) );
$sth->finish();
}
}
return $sth->fetchrow_array;
}
+sub GetBranchesCount {
+ my $dbh = C4::Context->dbh();
+ my $query = "SELECT COUNT(*) AS branches_count FROM branches";
+ my $sth = $dbh->prepare( $query );
+ $sth->execute();
+ my $row = $sth->fetchrow_hashref();
+ return $row->{'branches_count'};
+}
+
1;
__END__