From cbd26659db8875f1e4b5676a86982eff141b5d94 Mon Sep 17 00:00:00 2001 From: Magnus Enger Date: Thu, 27 Jun 2013 22:22:18 +0200 Subject: [PATCH] Bug 10513 - Light up a warning/message when returning a chosen item type This patch adds a new column to item types. Text in this column is displayed as a warning when an item of the given type is checked in. Use case: Items that are on inter-library loan can have a separate item type, and when items of this type are checked in a message saying something like "ILL! Remember to return it to the owning library!" can be displayed. To test: - Apply the patch - Go to Home > Administration > Item types administration - Check that there is a new column, called "Check in message" - Edit an item type and add a check in message - Check that the check in message you added is displayed in the table - Check in an item with an item type that has a check in message - Check that the message is displayed - Check in an item with an item type that does *not* have a check in message, and make sure no false messages are displayed - Run the tests in t/ItemType.t, which are updated by this patch This patch also removes backticks around column names in the itemtypes table in installer/data/mysql/kohastructure.sql Sponsored-by: Kultur i Halland - Regionbibliotek --- C4/ItemType.pm | 27 +++++++++++ admin/itemtypes.pl | 6 ++- circ/returns.pl | 9 ++++ installer/data/mysql/kohastructure.sql | 13 +++--- installer/data/mysql/updatedatabase.pl | 7 +++ .../prog/en/modules/admin/itemtypes.tt | 6 +++ .../intranet-tmpl/prog/en/modules/circ/returns.tt | 5 ++- t/ItemType.t | 47 ++++++++++++++++---- 8 files changed, 103 insertions(+), 17 deletions(-) diff --git a/C4/ItemType.pm b/C4/ItemType.pm index 648cff9..ad253a7 100644 --- a/C4/ItemType.pm +++ b/C4/ItemType.pm @@ -90,6 +90,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) = @_; + my $dbh = C4::Context->dbh; + + my $data = $dbh->selectrow_hashref( + "SELECT * FROM itemtypes WHERE itemtype = ?", undef, $itemtype + ); + if ( $data->{description} ) { + utf8::encode($data->{description}); + } + return $class->new($data); +} + + + + =head2 Object Methods These are read-only accessors for attributes of a C4::ItemType object. @@ -118,6 +141,10 @@ These are read-only accessors for attributes of a C4::ItemType object. =cut +=head3 $itemtype->checkinmsg + +=cut + =head3 $itemtype->summary =cut diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 841672d..493b68b 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -117,6 +117,7 @@ if ( $op eq 'add_form' ) { imageurl => $data->{'imageurl'}, template => C4::Context->preference('template'), summary => $data->{summary}, + checkinmsg => $data->{'checkinmsg'}, imagesets => $imagesets, remote_image => $remote_image, ); @@ -140,6 +141,7 @@ elsif ( $op eq 'add_validate' ) { , rentalcharge = ? , notforloan = ? , imageurl = ? + , checkinmsg = ? , summary = ? WHERE itemtype = ? '; @@ -155,6 +157,7 @@ elsif ( $op eq 'add_validate' ) { : $input->param('image') . "" ) ), + $input->param('checkinmsg'), $input->param('summary'), $input->param('itemtype') ); @@ -162,7 +165,7 @@ elsif ( $op eq 'add_validate' ) { else { # add a new itemtype & not modif an old my $query = " INSERT INTO itemtypes - (itemtype,description,rentalcharge, notforloan, imageurl,summary) + (itemtype,description,rentalcharge, notforloan, imageurl, checkinmsg, summary) VALUES (?,?,?,?,?,?); "; @@ -176,6 +179,7 @@ elsif ( $op eq 'add_validate' ) { $image eq 'removeImage' ? '' : $image eq 'remoteImage' ? $input->param('remoteImage') : $image, + $input->param('checkinmsg'), $input->param('summary'), ); } diff --git a/circ/returns.pl b/circ/returns.pl index 9472797..3b8441c 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -225,6 +225,15 @@ if ($barcode) { # fix up item type for display $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'}; + # Check if we should display a check in message, based on the the item + # type of the checked in item + my $itemtype = C4::ItemType->get( $biblio->{'itemtype'} ); + if ( $itemtype->{'checkinmsg'} ) { + $template->param( + checkinmsg => $itemtype->{'checkinmsg'}, + ); + } + $template->param( title => $biblio->{'title'}, homebranch => $biblio->{'homebranch'}, diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index f5e1862..c68588e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1204,12 +1204,13 @@ CREATE TABLE `items` ( -- holdings/item information DROP TABLE IF EXISTS `itemtypes`; CREATE TABLE `itemtypes` ( -- defines the item types - `itemtype` varchar(10) NOT NULL default '', -- unique key, a code associated with the item type - `description` mediumtext, -- a plain text explanation of the item type - `rentalcharge` double(16,4) default NULL, -- the amount charged when this item is checked out/issued - `notforloan` smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan - `imageurl` varchar(200) default NULL, -- URL for the item type icon - `summary` text, -- information from the summary field, may include HTML + itemtype varchar(10) NOT NULL default '', -- unique key, a code associated with the item type + description mediumtext, -- a plain text explanation of the item type + rentalcharge double(16,4) default NULL, -- the amount charged when this item is checked out/issued + notforloan smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan + imageurl varchar(200) default NULL, -- URL for the item type icon + summary text, -- information from the summary field, may include HTML + checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in PRIMARY KEY (`itemtype`), UNIQUE KEY `itemtype` (`itemtype`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a6b0090..d2be60e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7017,6 +7017,13 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("ALTER TABLE itemtypes ADD COLUMN checkinmsg VARCHAR(255);"); + print "Upgrade to $DBversion done (Bug 10513 - Light up a warning/message when returning a chosen item type)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt index 210b575..e5c9c87 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -229,6 +229,10 @@ Item types administration
  • + + +
  • +
  • Enter a summary that will overwrite the default one in search results lists. Example, for a website itemtype :

    @@ -282,6 +286,7 @@ Item types administration Description Not for loan Charge + Check in message Actions [% FOREACH loo IN loop %] @@ -303,6 +308,7 @@ Item types administration [% loo.rentalcharge %] [% END %] + [% loo.checkinmsg %] Edit Delete diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 98d2ae9..ee85db3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -315,7 +315,7 @@ $(document).ready(function () { [% END %] [% ELSE %] -[% IF ( errmsgloop ) %] +[% IF ( errmsgloop || checkinmsg ) %]

    Check in message

    [% FOREACH errmsgloo IN errmsgloop %] @@ -359,6 +359,9 @@ $(document).ready(function () { [% END %] [% END %] + [% IF ( checkinmsg ) %] +

    [% checkinmsg %]

    + [% END%]
    [% END %] diff --git a/t/ItemType.t b/t/ItemType.t index 87e090e..558bba9 100755 --- a/t/ItemType.t +++ b/t/ItemType.t @@ -1,11 +1,9 @@ #!/usr/bin/perl -# -# Add more tests here!!! use strict; use warnings; use DBI; -use Test::More tests => 15; +use Test::More tests => 26; use Test::MockModule; BEGIN { @@ -26,16 +24,16 @@ $module->mock( my $itemtypes = [ [ 'itemtype', 'description', 'rentalcharge', 'notforloan', - 'imageurl', 'summary' + 'imageurl', 'summary', 'checkinmsg' ], - [ 'BK', 'Books', 0, 0, '', '' ], - [ 'CD', 'CDRom', 0, 0, '', '' ] + [ 'BK', 'Books', 0, 0, '', '', 'foo' ], + [ 'CD', 'CDRom', 0, 0, '', '', 'bar' ] ]; my $itemtypes_empty = [ [ 'itemtype', 'description', 'rentalcharge', 'notforloan', - 'imageurl', 'summary' + 'imageurl', 'summary', 'checkinmsg' ], ]; @@ -53,6 +51,10 @@ is( scalar( @{$history} ), 1, 'Correct number of statements executed' ); $dbh->{mock_add_resultset} = $itemtypes; @itemtypes = C4::ItemType->all(); + +$history = $dbh->{mock_all_history}; +is( scalar( @{$history} ), 2, 'Correct number of statements executed' ); + is( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' ); is( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' ); @@ -73,6 +75,33 @@ is( $itemtypes[0]->notforloan, '0', 'first not for loan is 0' ); is( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' ); -is( $itemtypes[0]->imageurl, '', 'first not for loan is undef' ); +is( $itemtypes[0]->imageurl, '', 'first imageurl is undef' ); + +is( $itemtypes[1]->imageurl, '', 'second imageurl is undef' ); + +is( $itemtypes[0]->checkinmsg, 'foo', 'first checkinmsg is foo' ); + +is( $itemtypes[1]->checkinmsg, 'bar', 'second checkinmsg is bar' ); + +# Mock the data again +$dbh->{mock_add_resultset} = $itemtypes; + +# Test get(), which should return one itemtype +my $itemtype = C4::ItemType->get( 'BK' ); + +$history = $dbh->{mock_all_history}; +is( scalar( @{$history} ), 3, 'Correct number of statements executed' ); + +is( $itemtype->fish, undef, 'Calling a bad descriptor gives undef' ); + +is( $itemtype->itemtype, 'BK', 'itemtype is bk' ); + +is( $itemtype->description, 'Books', 'description is books' ); + +is( $itemtype->rentalcharge, '0', 'rental charge is 0' ); + +is( $itemtype->notforloan, '0', 'not for loan is 0' ); + +is( $itemtype->imageurl, '', ' not for loan is undef' ); -is( $itemtypes[1]->imageurl, '', 'second not for loan is undef' ); +is( $itemtype->checkinmsg, 'foo', 'checkinmsg is foo' ); -- 1.7.9.5