1 package Koha::UI::Table::Builder::Items;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 use List::MoreUtils qw( uniq );
20 use C4::Biblio qw( GetMarcStructure GetMarcFromKohaField IsMarcStructureInternal );
25 Koha::UI::Table::Builder::Items
27 Helper to build a table with a list of items with all their information.
29 Items' attributes that are mapped and not mapped will be listed in the table.
31 Only attributes that have been defined only once will be displayed (empty string is considered as not defined).
41 my $table = Koha::UI::Table::Builder::Items->new( { itemnumbers => \@itemnumbers } );
48 my ( $class, $params ) = @_;
51 $self->{itemnumbers} = $params->{itemnumbers} || [];
59 my $items_table = Koha::UI::Table::Builder::Items->new( { itemnumbers => \@itemnumbers } )
62 my $items = $items_table->{items};
63 my $headers = $items_table->{headers};
65 Build the headers and rows for the table.
68 [% PROCESS items_table_batchmod headers => headers, items => items %]
73 my ( $self, $params ) = @_;
75 my $items = Koha::Items->search( { itemnumber => $self->{itemnumbers} } );
78 while ( my $item = $items->next ) {
79 my $item_info = $item->columns_to_str;
82 biblio => $item->biblio,
83 safe_to_delete => $item->safe_to_delete,
84 holds => $item->biblio->holds->count,
85 item_holds => $item->holds->count,
86 is_checked_out => $item->checkout || 0,
88 push @items, $item_info;
91 $self->{headers} = $self->_build_headers( \@items );
92 $self->{items} = \@items;
96 =head2 Internal methods
100 =head3 _build_headers
102 Build the headers given the items' info.
107 my ( $self, $items ) = @_;
109 my @witness_attributes = uniq map {
113 && !ref( $item->{$_} ) # biblio and safe_to_delete are objects
120 my ( $itemtag, $itemsubfield ) =
121 C4::Biblio::GetMarcFromKohaField("items.itemnumber");
122 my $tagslib = C4::Biblio::GetMarcStructure(1);
123 my $subfieldcode_attribute_mappings;
124 for my $subfield_code ( keys %{ $tagslib->{$itemtag} } ) {
126 my $subfield = $tagslib->{$itemtag}->{$subfield_code};
128 next if IsMarcStructureInternal($subfield);
129 next unless $subfield->{tab} eq 10; # Is this really needed?
132 if ( $subfield->{kohafield} ) {
133 ( $attribute = $subfield->{kohafield} ) =~ s|^items\.||;
136 $attribute = $subfield_code; # It's in more_subfields_xml
138 next unless grep { $attribute eq $_ } @witness_attributes;
139 $subfieldcode_attribute_mappings->{$subfield_code} = $attribute;
145 header_value => $tagslib->{$itemtag}->{$_}->{lib},
146 attribute => $subfieldcode_attribute_mappings->{$_},
149 } sort keys %$subfieldcode_attribute_mappings