&GetBranch
&GetBranches
&GetBranchesLoop
- &GetBranchInfo
&mybranch
);
@EXPORT_OK = qw( &onlymine &mybranch );
$branches = &GetBranches();
Returns informations about ALL branches, IndependentBranches Insensitive.
-GetBranchInfo() returns the same information.
Create a branch selector with the following code.
return $branch;
}
-=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,$categorytype) = @_;
- my $dbh = C4::Context->dbh;
- my $sth;
-
-
- if ($branchcode) {
- $sth =
- $dbh->prepare(
- "Select * from branches where branchcode = ? order by branchcode");
- $sth->execute($branchcode);
- }
- else {
- $sth = $dbh->prepare("Select * from branches order by branchcode");
- $sth->execute();
- }
- my @results;
- while ( my $data = $sth->fetchrow_hashref ) {
- 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 );
- }
- $data->{'categories'} = \@cats;
- push( @results, $data );
- }
- return \@results;
-}
-
1;
__END__
use C4::Suggestions;
use C4::Koha;
use C4::Scrubber;
+use Koha::Libraries;
use Koha::DateUtils qw( dt_from_string );
print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
exit;
}
-map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;
+map{ $_->{'branchcodesuggestedby'} = Koha::Libraries->find($_->{'branchcodesuggestedby'})->branchname} @$suggestions_loop;
foreach my $suggestion(@$suggestions_loop) {
if($suggestion->{'suggestedby'} == $borrowernumber) {
GetBranch
GetBranches
GetBranchesLoop
- GetBranchInfo
mybranch
)
);
$b2_stored->add_to_categories([$CAT1]);
is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
-#Test GetBranchInfo
-my $b1info = GetBranchInfo( $b1->{branchcode} );
-$b1->{categories} = [];
-is_deeply( @$b1info[0], $b1, 'BRA has no categories' );
-
-my $b2info = GetBranchInfo( $b2->{branchcode} );
-my @cat = ( $cat1->{categorycode} );
-delete $b2->{add};
-delete $b2->{CAT1};
-$b2->{issuing} = undef;
-$b2->{categories} = \@cat;
-is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' );
+my $b1info = Koha::Libraries->find( $b1->{branchcode} );
+is_deeply( $b1info->categories->count, 0, 'BRA has no categories' );
+
+my $b2info = Koha::Libraries->find( $b2->{branchcode} );
+is_deeply( $b2->categories->count, 1, 'BRB has the category CAT1' );
Koha::LibraryCategory->new($cat2)->store;
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );