X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FCategory.pm;h=255db2b02495c06168ab9db468b9692e5df66ca7;hb=0423b43b1761a9c5d86888426643d69015b15e3a;hp=8cadc8b6126c9df9e38d76783fb05b89d79a67ad;hpb=0d4acbba5c5db238eb42ed37dc9ba3dc2f36974b;p=koha_fer diff --git a/C4/Category.pm b/C4/Category.pm index 8cadc8b612..255db2b024 100644 --- a/C4/Category.pm +++ b/C4/Category.pm @@ -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 : () + ) + }; }