Bug 24640: DBRev 19.12.00.023
[srvgit] / Koha / ItemTypes.pm
index daa808b..1fa76df 100644 (file)
@@ -24,7 +24,7 @@ use C4::Languages;
 use Koha::Database;
 use Koha::ItemType;
 
-use base qw(Koha::Objects);
+use base qw(Koha::Objects Koha::Objects::Limit::Library);
 
 =head1 NAME
 
@@ -32,7 +32,7 @@ Koha::ItemTypes - Koha ItemType Object set class
 
 =head1 API
 
-=head2 Class Methods
+=head2 Class methods
 
 =cut
 
@@ -46,14 +46,25 @@ sub search_with_localization {
     my ( $self, $params, $attributes ) = @_;
 
     my $language = C4::Languages::getlanguage();
-    $params->{'-or'} = { 'localization.lang' => [ $language, undef ] };
-    $attributes->{order_by} = 'localization.translation' unless exists $attributes->{order_by};
+    $Koha::Schema::Result::Itemtype::LANGUAGE = $language;
+    $attributes->{order_by} = 'translated_description' unless exists $attributes->{order_by};
     $attributes->{join} = 'localization';
-    $attributes->{'+select'} = [ { coalesce => [qw( localization.translation me.description )] } ];
-    $attributes->{'+as'} = ['translated_description'];
-    $self->SUPER::search( $params, $attributes );
+    $attributes->{'+select'} = [
+        {
+            coalesce => [qw( localization.translation me.description )],
+            -as      => 'translated_description'
+        }
+    ];
+    if(defined $params->{branchcode}) {
+        my $branchcode = delete $params->{branchcode};
+        $self->search_with_library_limits( $params, $attributes, $branchcode );
+    } else {
+        $self->SUPER::search( $params, $attributes );
+    }
 }
 
+=head2 Internal methods
+
 =head3 type
 
 =cut
@@ -62,6 +73,10 @@ sub _type {
     return 'Itemtype';
 }
 
+=head3 object_class
+
+=cut
+
 sub object_class {
     return 'Koha::ItemType';
 }