=cut
-my $syspref_cache = Koha::Caches->get_instance('syspref');
+my $syspref_cache;
my $use_syspref_cache = 1;
sub preference {
my $self = shift;
my $var = shift; # The system preference to return
- $var = lc $var;
-
return $ENV{"OVERRIDE_SYSPREF_$var"}
if defined $ENV{"OVERRIDE_SYSPREF_$var"};
- my $cached_var = $use_syspref_cache
- ? $syspref_cache->get_from_cache("syspref_$var")
- : undef;
- return $cached_var if defined $cached_var;
+ $var = lc $var;
+
+ if ($use_syspref_cache) {
+ $syspref_cache = Koha::Caches->get_instance('syspref') unless $syspref_cache;
+ my $cached_var = $syspref_cache->get_from_cache("syspref_$var");
+ return $cached_var if defined $cached_var;
+ }
my $syspref;
eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) };
return C4::Context->userenv->{branch} || '';
}
+=head2 only_my_library
+
+ my $test = C4::Context->only_my_library;
+
+ Returns true if you enabled IndependentBranches and the current user
+ does not have superlibrarian permissions.
+
+=cut
+
+sub only_my_library {
+ return
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
+}
+
1;
+
__END__
=head1 ENVIRONMENT