@ISA = qw(Exporter);
@EXPORT = qw(
- GetItem
AddItemFromMarc
AddItem
AddItemBatchFromMarc
DelItemCheck
MoveItemFromBiblio
CartToShelf
- ShelfToCart
GetAnalyticsCount
SearchItemsByField
SearchItems
}
use Carp;
+use Try::Tiny;
use C4::Context;
use C4::Koha;
use C4::Biblio;
modification transaction must keep the items table
and the MARC XML in sync at all times.
-Consequently, all code that creates, modifies, or deletes
-item records B<must> use an appropriate function from
-C<C4::Items>. If no existing function is suitable, it is
-better to add one to C<C4::Items> than to use add
-one-off SQL statements to add or modify items.
-
The items table will be considered authoritative. In other
words, if there is ever a discrepancy between the items
table and the MARC XML, the items table should be considered
=cut
-=head2 GetItem
-
- $item = GetItem($itemnumber,$barcode,$serial);
-
-Return item information, for a given itemnumber or barcode.
-The return value is a hashref mapping item column
-names to values. If C<$serial> is true, include serial publication data.
-
-=cut
-
-sub GetItem {
- my ($itemnumber,$barcode, $serial) = @_;
- my $dbh = C4::Context->dbh;
-
- my $item;
- if ($itemnumber) {
- $item = Koha::Items->find( $itemnumber );
- } else {
- $item = Koha::Items->find( { barcode => $barcode } );
- }
-
- return unless ( $item );
-
- my $data = $item->unblessed();
- $data->{itype} = $item->effective_itemtype(); # set the correct itype
-
- if ($serial) {
- my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=?");
- $ssth->execute( $data->{'itemnumber'} );
- ( $data->{'serialseq'}, $data->{'publisheddate'} ) = $ssth->fetchrow_array();
- }
-
- return $data;
-} # sub GetItem
-
=head2 CartToShelf
CartToShelf($itemnumber);
}
}
-=head2 ShelfToCart
-
- ShelfToCart($itemnumber);
-
-Set the current shelving location of the item
-to shelving cart ('CART').
-
-=cut
-
-sub ShelfToCart {
- my ( $itemnumber ) = @_;
-
- unless ( $itemnumber ) {
- croak "FAILED ShelfToCart() - no itemnumber supplied";
- }
-
- ModItem({ location => 'CART'}, undef, $itemnumber);
-}
-
=head2 AddItemFromMarc
my ($biblionumber, $biblioitemnumber, $itemnumber)
logaction( "CATALOGUING", "ADD", $itemnumber, "item" )
if C4::Context->preference("CataloguingLog");
+ _after_item_action_hooks({ action => 'create', item_id => $itemnumber });
+
return ( $item->{biblionumber}, $item->{biblioitemnumber}, $itemnumber );
}
materials => undef,
new_status => undef,
notforloan => 0,
- # paidfor => undef, # commented, see bug 12817
price => undef,
replacementprice => undef,
replacementpricedate => undef,
# item status is possible
ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
+ _after_item_action_hooks({ action => 'modify', item_id => $itemnumber });
+
logaction( "CATALOGUING", "MODIFY", $itemnumber, "item " . Dumper($item) )
if $log_action && C4::Context->preference("CataloguingLog");
}
my ( $itemnumber, $frombranch, $tobranch ) = @_;
my $dbh = C4::Context->dbh;
+ my $item = Koha::Items->find( $itemnumber );
# Remove the 'shelving cart' location status if it is being used.
- CartToShelf( $itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
+ CartToShelf( $itemnumber ) if ( $item->location eq 'CART' && $item->permanent_location ne 'CART' );
$dbh->do("UPDATE branchtransfers SET datearrived = NOW(), comments = ? WHERE itemnumber = ? AND datearrived IS NULL", undef, "Canceled, new transfer from $frombranch to $tobranch created", $itemnumber);
ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
+ _after_item_action_hooks({ action => 'delete', item_id => $itemnumber });
+
#search item field code
logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
return $deleted;
my $max_cnsort = GetClassSort($class_source,undef,$maxlocation);
my $select_columns = q{
- SELECT items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, biblio.frameworkcode, datelastseen, homebranch, location, notforloan, damaged, itemlost, withdrawn, stocknumber
+ SELECT DISTINCT(items.itemnumber), barcode, itemcallnumber, title, author, biblio.biblionumber, biblio.frameworkcode, datelastseen, homebranch, location, notforloan, damaged, itemlost, withdrawn, stocknumber
};
- my $select_count = q{SELECT COUNT(*)};
+ my $select_count = q{SELECT COUNT(DISTINCT(items.itemnumber))};
my $query = q{
FROM items
LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
holding.opac_info as holding_branch_opac_info,
home.opac_info as home_branch_opac_info
";
+ $query .= ",IF(tmp_holdsqueue.itemnumber,1,0) AS has_pending_hold" if !C4::Context->preference('AllowItemsOnHoldCheckout');
$query .= "
FROM items
LEFT JOIN branches AS holding ON items.holdingbranch = holding.branchcode
LEFT JOIN serial USING (serialid)
LEFT JOIN itemtypes ON itemtypes.itemtype = "
. (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype');
+ $query .= "
+ LEFT JOIN tmp_holdsqueue USING (itemnumber)" if !C4::Context->preference('AllowItemsOnHoldCheckout');
$query .= q|
LEFT JOIN localization ON itemtypes.itemtype = localization.code
AND localization.entity = 'itemtypes'
itemnotes = ?,
itemnotes_nonpublic = ?,
holdingbranch = ?,
- paidfor = ?,
location = ?,
permanent_location = ?,
onloan = ?,
$item->{'itemnotes'},
$item->{'itemnotes_nonpublic'},
$item->{'holdingbranch'},
- $item->{'paidfor'},
$item->{'location'},
$item->{'permanent_location'},
$item->{'onloan'},
$defaultvalue =~ s/"/"/g;
}
+ my $maxlength = $tagslib->{$tag}->{$subfield}->{maxlength};
+
# search for itemcallnumber if applicable
if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
&& C4::Context->preference('itemcallnumber') ) {
my $tab= $plugin->noclick? '-1': '';
my $class= $plugin->noclick? ' disabled': '';
my $title= $plugin->noclick? 'No popup': 'Tag editor';
- $subfield_data{marc_value} = qq[<input type="text" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="255" value="$defaultvalue" /><a href="#" id="buttonDot_$subfield_data{id}" tabindex="$tab" class="buttonDot $class" title="$title">...</a>\n].$plugin->javascript;
+ $subfield_data{marc_value} = qq[<input type="text" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$maxlength" value="$defaultvalue" /><a href="#" id="buttonDot_$subfield_data{id}" tabindex="$tab" class="buttonDot $class" title="$title">...</a>\n].$plugin->javascript;
} else {
warn $plugin->errstr;
- $subfield_data{marc_value} = qq(<input type="text" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="255" value="$defaultvalue" />); # supply default input form
+ $subfield_data{marc_value} = qq(<input type="text" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$maxlength" value="$defaultvalue" />); # supply default input form
}
}
elsif ( $tag eq '' ) { # it's an hidden field
- $subfield_data{marc_value} = qq(<input type="hidden" tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="255" value="$defaultvalue" />);
+ $subfield_data{marc_value} = qq(<input type="hidden" tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$maxlength" value="$defaultvalue" />);
}
elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ?
- $subfield_data{marc_value} = qq(<input type="text" tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="255" value="$defaultvalue" />);
+ $subfield_data{marc_value} = qq(<input type="text" tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$maxlength" value="$defaultvalue" />);
}
elsif ( length($defaultvalue) > 100
or (C4::Context->preference("marcflavour") eq "UNIMARC" and
500 <= $tag && $tag < 600 )
) {
# oversize field (textarea)
- $subfield_data{marc_value} = qq(<textarea tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="255">$defaultvalue</textarea>\n");
+ $subfield_data{marc_value} = qq(<textarea tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="50" maxlength="$maxlength">$defaultvalue</textarea>\n");
} else {
- $subfield_data{marc_value} = "<input type=\"text\" name=\"field_value\" value=\"$defaultvalue\" size=\"50\" maxlength=\"255\" />";
+ $subfield_data{marc_value} = "<input type=\"text\" name=\"field_value\" value=\"$defaultvalue\" size=\"50\" maxlength=\"$maxlength\" />";
}
push( @loop_data, \%subfield_data );
}
my $age = $rule->{age};
my $conditions = $rule->{conditions};
my $substitutions = $rule->{substitutions};
+ foreach ( @$substitutions ) {
+ ( $_->{item_field} ) = ( $_->{field} =~ /items\.(.*)/ );
+ }
my @params;
my $query = q|
- SELECT items.biblionumber, items.itemnumber
+ SELECT items.*
FROM items
LEFT JOIN biblioitems ON biblioitems.biblionumber = items.biblionumber
WHERE 1
my $itemnumber = $values->{itemnumber};
for my $substitution ( @$substitutions ) {
next unless $substitution->{field};
- C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
+ next if ( defined $values->{ $substitution->{item_field} } and $values->{ $substitution->{item_field} } eq $substitution->{value} );
+ C4::Items::ModItem( { $substitution->{item_field} => $substitution->{value} }, $biblionumber, $itemnumber )
unless $report_only;
push @{ $report->{$itemnumber} }, $substitution;
}
return $report;
}
+=head2 _after_item_action_hooks
+
+Helper method that takes care of calling all plugin hooks
+
+=cut
+
+sub _after_item_action_hooks {
+ my ( $args ) = @_;
+
+ my $item_id = $args->{item_id};
+ my $action = $args->{action};
+
+ if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) {
+
+ my @plugins = Koha::Plugins->new->GetPlugins({
+ method => 'after_item_action',
+ });
+
+ if (@plugins) {
+
+ my $item = Koha::Items->find( $item_id );
+
+ foreach my $plugin ( @plugins ) {
+ try {
+ $plugin->after_item_action({ action => $action, item => $item, item_id => $item_id });
+ }
+ catch {
+ warn "$_";
+ };
+ }
+ }
+ }
+}
1;