X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FCategory.pm;h=72ed42432e82c90dc7736b04d978a4b45e72d985;hb=3bb1578354e75ae160830a410340c6fbb9faaf3a;hp=8cadc8b6126c9df9e38d76783fb05b89d79a67ad;hpb=88b6e0f90a32af03ed6c4876e0917176bafe8376;p=koha.git diff --git a/C4/Category.pm b/C4/Category.pm index 8cadc8b612..72ed42432e 100644 --- a/C4/Category.pm +++ b/C4/Category.pm @@ -5,18 +5,18 @@ package C4::Category; # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; @@ -74,13 +74,24 @@ C. =cut sub all { - my $class = shift; - map { - utf8::encode($_->{description}); - $class->new($_); - } @{C4::Context->dbh->selectall_arrayref( - "SELECT * FROM categories ORDER BY description", { Slice => {} } - )}; + my ( $class ) = @_; + my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; + my $dbh = C4::Context->dbh; + # The categories table is small enough for + # `SELECT *` to be harmless. + my $query = "SELECT categories.* FROM categories"; + $query .= qq{ + LEFT JOIN categories_branches ON categories_branches.categorycode = categories.categorycode + WHERE categories_branches.branchcode = ? OR categories_branches.branchcode IS NULL + } if $branch_limit; + $query .= " ORDER BY description"; + return map { $class->new($_) } @{ + $dbh->selectall_arrayref( + $query, + { Slice => {} }, + $branch_limit ? $branch_limit : () + ) + }; }