Bug 14544: Get rid of C4::VirtualShelves and C4::VirtualShelves::Page
[koha.git] / C4 / ItemType.pm
index cf61d40..209a77d 100644 (file)
@@ -5,22 +5,23 @@ package C4::ItemType;
 #
 # 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 <http://www.gnu.org/licenses>.
 
 use strict;
 use warnings;
 use C4::Context;
+use C4::Languages;
 use Encode qw( encode );
 
 our $AUTOLOAD;
@@ -78,11 +79,18 @@ sub all {
     my ($class) = @_;
     my $dbh = C4::Context->dbh;
 
+    my $language = C4::Languages::getlanguage();
     my @itypes;
-    for ( @{$dbh->selectall_arrayref(
-        "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} )
+    for ( @{$dbh->selectall_arrayref(q|
+        SELECT *,
+            COALESCE( localization.translation, itemtypes.description ) AS translated_description
+        FROM itemtypes
+        LEFT JOIN localization ON itemtypes.itemtype = localization.code
+            AND localization.entity = 'itemtypes'
+            AND localization.lang = ?
+        ORDER BY description
+    |, { Slice => {} }, $language)} )
     {
-        $_->{description} = Encode::encode('UTF-8', $_->{description});
         push @itypes, $class->new($_);
     }
     return @itypes;
@@ -100,14 +108,14 @@ an object.
 
 sub get {
     my ($class, $itemtype) = @_;
+
+    return unless defined $itemtype;
+
     my $dbh = C4::Context->dbh;
 
     my $data = $dbh->selectrow_hashref(
         "SELECT * FROM itemtypes WHERE itemtype = ?", undef, $itemtype
     );
-    if ( $data->{description} ) {
-        $data->{description} = Encode::encode('UTF-8', $data->{description});
-    }
     return $class->new($data);
 }
 
@@ -180,8 +188,6 @@ L<C4::Labels>,
 L<C4::Overdues>,
 L<C4::Reserves>,
 L<C4::Search>,
-L<C4::VirtualShelves::Page>,
-L<C4::VirtualShelves>,
 L<C4::XSLT>