From 7b13fb7e98e3d0a1a8cd01c750bc16f8568d69d4 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Sun, 24 Sep 2017 15:12:47 +0000 Subject: [PATCH] Bug 19360 - Give items URL a link text This patch allows a user to write in a link text when adding an item to a MARC record in addition to a URI. The link text is displayed instead of the URI (only if a link text has been entered, otherwise the URI value is displayed) which makes the link more readable. Test plan: 1. Add a MARC record (of any framework) 2. Add an item making sure to write in a URL e.g. https://www.google.com 3. Notice on the additem page there is no 'Link text' input 4. Submit the add item form 5. Search for the item in the intranet and OPAC and notice that the whole URL is displayed, which would get annoying if the URL is long 6. Apply patch 7. Update the database by going to Administration->Global system preferences-> local use and change the 'version' system preference to an previous version and then click 'Save' 8. This will prompt the update process 9. After going through the update process repeat step 1 and add an item. When adding the item notice there is a 'Link text' option write in an appropriate name e.g. 'Google' and write in the URI value 10. Submit the form 11. Repeat step 5 and notice that the link text value is displayed instead of the URL 12. Click on the link and check that it works 13. Add another item to a record and write in a URI but no link text value 14. Search for the item in intranet and OPAC and notice that when no link text is entered but a URI is then the URI is displayed Sponsored-By: Catalyst IT --- C4/Items.pm | 5 ++++- Koha/Schema/Result/Item.pm | 8 ++++++++ catalogue/detail.pl | 3 ++- .../intranet-tmpl/prog/en/modules/catalogue/detail.tt | 10 +++++++--- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt | 14 +++++++++++--- opac/opac-detail.pl | 6 ++++-- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 0b6a77e..1f7169d 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -478,6 +478,7 @@ sub _build_default_values_for_mod_marc { stocknumber => undef, uri => undef, withdrawn => 0, + link_text => undef, }; my %default_values_for_mod_from_marc; while ( my ( $field, $default_value ) = each %$default_values ) { @@ -1784,7 +1785,8 @@ sub _koha_new_item { more_subfields_xml = ?, copynumber = ?, stocknumber = ?, - new_status = ? + new_status = ?, + link_text = ? "; my $sth = $dbh->prepare($query); my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); @@ -1829,6 +1831,7 @@ sub _koha_new_item { $item->{'copynumber'}, $item->{'stocknumber'}, $item->{'new_status'}, + $item->{'link_text'} ); my $itemnumber; diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index ce85bd7..33a2b7b 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -280,6 +280,12 @@ __PACKAGE__->table("items"); is_nullable: 1 size: 32 +=head2 link_text + + data_type: 'varchar' + is_nullable: 1 + size: 200 + =cut __PACKAGE__->add_columns( @@ -394,6 +400,8 @@ __PACKAGE__->add_columns( { data_type => "varchar", is_nullable => 1, size => 32 }, "new_status", { data_type => "varchar", is_nullable => 1, size => 32 }, + "link_text", + { data_type => "varchar", is_nullable => 1, size => 200 }, ); =head1 PRIMARY KEY diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 1e18a1d..3414609 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -249,7 +249,7 @@ foreach my $item (@items) { $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) ); my $copynumber = $item->{'copynumber'}; $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) ); - foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri)) { + foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri link_text)) { $itemfields{$_} = 1 if ( $item->{$_} ); } @@ -362,6 +362,7 @@ $template->param( volinfo => $itemfields{enumchron}, itemdata_itemnotes => $itemfields{itemnotes}, itemdata_nonpublicnotes => $itemfields{itemnotes_nonpublic}, + itemdata_linktext => $itemfields{link_text}, z3950_search_params => C4::Search::z3950_search_args($dat), hostrecords => $hostrecords, analytics_flag => $analytics_flag, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index be5932b..d4b4bf6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -251,7 +251,7 @@
  • Dewey: [% dewey %]
  • [% END %] [% IF ( urlS ) %] -
  • URL: +
  • URL/Link: [% FOREACH url IN urlS %] [% url.url %] [% END %] @@ -338,7 +338,7 @@ Last seen Barcode [% IF ( volinfo ) %]Serial enumeration / chronology[% END %] - [% IF ( itemdata_uri ) %]URL[% END %] + [% IF ( itemdata_uri ) %]URL/Link[% END %] [% IF ( itemdata_copynumber ) %]Copy number[% END %] [% IF ( itemdata_stocknumber ) %]Inventory number[% END %] [% IF materials %]Materials specified[% END %] @@ -481,7 +481,11 @@ [% END %] [% IF ( itemdata_uri ) %] - [% item.uri %] + [% IF ( itemdata_linktext ) %] + [% item.link_text %] + [% ELSE %] + [% item.uri %] + [% END %] [% END %] [% IF ( itemdata_copynumber ) %] [% item.copynumber %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 9d1f2b9..1c11b8d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -1191,7 +1191,7 @@ [% IF ( itemdata_ccode ) %]Collection[% END %] Call number [% IF ( itemdata_enumchron ) %]Vol info[% END %] - [% IF ( itemdata_uri ) %]URL[% END %] + [% IF ( itemdata_uri ) %]URL/Link[% END %] [% IF ( itemdata_copynumber ) %]Copy number[% END %] Status [% IF ( itemdata_itemnotes ) %]Notes[% END %] @@ -1317,9 +1317,17 @@ [% ELSE %] [% IF Koha.Preference("OPACURLOpenInNewWindow") %] - [% ITEM_RESULT.uri %] + [% IF ITEM_RESULT.link_text %] + [% ITEM_RESULT.link_text %] + [% ELSE %] + [% ITEM_RESULT.uri %] + [% END %] [% ELSE %] - [% ITEM_RESULT.uri %] + [% IF ITEM_RESULT.link_text %] + [% ITEM_RESULT.link_text %] + [% ELSE %] + [% ITEM_RESULT.uri %] + [% END %] [% END %] [% END %] [% END %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 8252e50..d295d0a 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -685,7 +685,8 @@ if ( not $viewallitems and @items > $max_items_to_display ) { $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} ); $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{translated_description}; } - foreach (qw(ccode enumchron copynumber itemnotes uri)) { + + foreach (qw(ccode enumchron copynumber itemnotes uri link_text)) { $itemfields{$_} = 1 if ($itm->{$_}); } @@ -759,7 +760,8 @@ my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($bib itemdata_enumchron => $itemfields{enumchron}, itemdata_uri => $itemfields{uri}, itemdata_copynumber => $itemfields{copynumber}, - itemdata_itemnotes => $itemfields{itemnotes}, + itemdata_itemnotes => $itemfields{itemnotes}, + itemdata_linktext => $itemfields{link_text}, subtitle => $subtitle, OpacStarRatings => C4::Context->preference("OpacStarRatings"), ); -- 2.1.4