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 ) = @_;
74 my %itemnumbers_to_idx = map { $self->{itemnumbers}->[$_] => $_ } 0..$#{$self->{itemnumbers}};
75 my $items = Koha::Items->search( { itemnumber => $self->{itemnumbers} } );
78 while ( my $item = $items->next ) {
79 my $item_info = $item->columns_to_str;
82 index => $itemnumbers_to_idx{$item->itemnumber},
83 biblio => $item->biblio,
84 safe_to_delete => $item->safe_to_delete,
85 holds => $item->biblio->holds->count,
86 item_holds => $item->holds->count,
87 is_checked_out => $item->checkout ? 1 : 0,
89 push @items, $item_info;
92 $self->{headers} = $self->_build_headers( \@items );
93 $self->{items} = \@items;
97 =head2 Internal methods
101 =head3 _build_headers
103 Build the headers given the items' info.
108 my ( $self, $items ) = @_;
110 my @witness_attributes = uniq map {
114 && !ref( $item->{$_} ) # biblio and safe_to_delete are objects
121 my ( $itemtag, $itemsubfield ) =
122 C4::Biblio::GetMarcFromKohaField("items.itemnumber");
123 my $tagslib = C4::Biblio::GetMarcStructure(1);
124 my $subfieldcode_attribute_mappings;
125 for my $subfield_code ( keys %{ $tagslib->{$itemtag} } ) {
127 my $subfield = $tagslib->{$itemtag}->{$subfield_code};
129 next if IsMarcStructureInternal($subfield);
130 next unless $subfield->{tab} eq 10; # Is this really needed?
133 if ( $subfield->{kohafield} ) {
134 ( $attribute = $subfield->{kohafield} ) =~ s|^items\.||;
137 $attribute = $subfield_code; # It's in more_subfields_xml
139 next unless grep { $attribute eq $_ } @witness_attributes;
140 $subfieldcode_attribute_mappings->{$subfield_code} = $attribute;
146 header_value => $tagslib->{$itemtag}->{$_}->{lib},
147 attribute => $subfieldcode_attribute_mappings->{$_},
150 } sort keys %$subfieldcode_attribute_mappings