use C4::Koha;
use C4::Context;
+use Koha::Libraries;
sub GetName {
my ( $self, $branchcode ) = @_;
return $b->{branchurl};
}
-sub OnlyMine {
- return C4::Branch::onlymine;
-}
-
sub all {
my ( $self, $params ) = @_;
my $selected = $params->{selected};
- my $dbh = C4::Context->dbh;
- my @params;
- my $query = q|
- SELECT branchcode, branchname
- FROM branches
- |;
- if ( C4::Branch::onlymine
- and C4::Context->userenv
- and C4::Context->userenv->{branch} )
- {
- $query .= q| WHERE branchcode = ? |;
- push @params, C4::Context->userenv->{branch};
- }
- $query .= q| ORDER BY branchname|;
- my $branches = $dbh->selectall_arrayref( $query, { Slice => {} }, @params );
-
- if ( $selected ) {
- for my $branch ( @$branches ) {
- if ( $branch->{branchcode} eq $selected ) {
- $branch->{selected} = 1;
- }
+ my $unfiltered = $params->{unfiltered} || 0;
+
+ my $libraries = $unfiltered
+ ? Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed
+ : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed;
+
+ for my $l ( @$libraries ) {
+ if ( defined $selected and $l->{branchcode} eq $selected
+ or not defined $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch}
+ ) {
+ $l->{selected} = 1;
}
}
- return $branches;
+
+ return $libraries;
+}
+
+sub InIndependentBranchesMode {
+ my ( $self ) = @_;
+ return ( not C4::Context->preference("IndependentBranches") or C4::Context::IsSuperLibrarian );
}
1;