Bug 14544: Get rid of C4::VirtualShelves and C4::VirtualShelves::Page
[srvgit] / C4 / ItemType.pm
index 648cff9..209a77d 100644 (file)
@@ -5,22 +5,24 @@ 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;
 
@@ -77,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)} )
     {
-        utf8::encode($_->{description});
         push @itypes, $class->new($_);
     }
     return @itypes;
@@ -90,6 +99,29 @@ sub all {
 
 
 
+=head3 C4::ItemType->get
+
+Return the itemtype indicated by the itemtype given as argument, as
+an object.
+
+=cut
+
+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
+    );
+    return $class->new($data);
+}
+
+
+
+
 =head2 Object Methods
 
 These are read-only accessors for attributes of a C4::ItemType object.
@@ -118,6 +150,10 @@ These are read-only accessors for attributes of a C4::ItemType object.
 
 =cut
 
+=head3 $itemtype->checkinmsg
+
+=cut
+
 =head3 $itemtype->summary
 
 =cut
@@ -152,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>