+=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.
=cut
+=head3 $itemtype->checkinmsg
+
+=cut
+
=head3 $itemtype->summary
=cut
imageurl => $data->{'imageurl'},
template => C4::Context->preference('template'),
summary => $data->{summary},
+ checkinmsg => $data->{'checkinmsg'},
+ checkinmsgtype => $data->{'checkinmsgtype'},
imagesets => $imagesets,
remote_image => $remote_image,
);
, notforloan = ?
, imageurl = ?
, summary = ?
+ , checkinmsg = ?
+ , checkinmsgtype = ?
WHERE itemtype = ?
';
$sth = $dbh->prepare($query2);
)
),
$input->param('summary'),
+ $input->param('checkinmsg'),
+ $input->param('checkinmsgtype'),
$input->param('itemtype')
);
}
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, summary, checkinmsg, checkinmsgtype)
VALUES
- (?,?,?,?,?,?);
+ (?,?,?,?,?,?,?,?);
";
my $sth = $dbh->prepare($query);
my $image = $input->param('image');
$image eq 'remoteImage' ? $input->param('remoteImage') :
$image,
$input->param('summary'),
+ $input->param('checkinmsg'),
+ $input->param('checkinmsgtype'),
);
}
# 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'},
+ checkinmsgtype => $itemtype->{'checkinmsgtype'},
+ );
+ }
+
$template->param(
title => $biblio->{'title'},
homebranch => $biblio->{'homebranch'},
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
+ checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message"
PRIMARY KEY (`itemtype`),
UNIQUE KEY `itemtype` (`itemtype`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SetVersion($DBversion);
}
+$DBversion = "3.13.00.XXX";
+if ( CheckVersion($DBversion) ) {
+ $dbh->do("ALTER TABLE itemtypes ADD COLUMN checkinmsg VARCHAR(255) AFTER summary;");
+ $dbh->do("ALTER TABLE itemtypes ADD COLUMN checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL AFTER checkinmsg;");
+ print "Upgrade to $DBversion done (Bug 10513 - Light up a warning/message when returning a chosen item type)\n";
+ SetVersion($DBversion);
+}
=head1 FUNCTIONS
<input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% rentalcharge %]" />
</li>
<li>
+ <label for="checkinmsg">Check in message: </label>
+ <input type="text" id="checkinmsg" name="checkinmsg" size="48" value="[% checkinmsg %]" />
+ </li>
+ <li>
+ <label for="checkinmsgtype">Check in message type: </label>
+ <select type="text" id="checkinmsgtype" name="checkinmsgtype">
+ [% IF ( checkinmsgtype == 'message' ) %]
+ <option value="message" selected="selected">Message</option>
+ [% ELSE %]
+ <option value="message">Message</option>
+ [% END %]
+ [% IF ( checkinmsgtype == 'alert' ) %]
+ <option value="alert" selected="selected">Alert</option>
+ [% ELSE %]
+ <option value="alert">Alert</option>
+ [% END %]
+ <select>
+ </li>
+ <li>
<label for="summary">Summary: </label>
<textarea id="summary" name="summary" cols="55" rows="5">[% summary %]</textarea>
<p>Enter a summary that will overwrite the default one in search results lists. Example, for a website itemtype : </p>
<th>Description</th>
<th>Not for loan</th>
<th>Charge</th>
+ <th>Check in message</th>
<th>Actions</th>
</thead>
[% FOREACH loo IN loop %]
[% loo.rentalcharge %]
[% END %]
</td>
+ <td>[% loo.checkinmsg %]</td>
<td>
<a href="[% loo.script_name %]?op=add_form&itemtype=[% loo.itemtype |html %]">Edit</a>
<a href="[% loo.script_name %]?op=delete_confirm&itemtype=[% loo.itemtype |html %]">Delete</a>
[% END %]
</div>
+[% IF ( checkinmsg ) %]
+ [% IF ( checkinmsgtype == 'alert' ) %]
+ <div class="dialog alert">
+ [% ELSE %]
+ <div class="dialog message">
+ [% END %]
+ <p class="problem">[% checkinmsg %]</p>
+ </div>
+[% END%]
+
<div id="exemptfines" class="dialog message" style="display:none;">
<p>Fines for returned items are forgiven.</p>
</div>
#!/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 {
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'
],
];
$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' );
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' );