Bug 18499: Use items cn_source in cn_browser.pl
authorNick Clemens <nick@bywatersolutions.com>
Thu, 6 Feb 2020 13:14:30 +0000 (13:14 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 17 Feb 2020 11:25:01 +0000 (11:25 +0000)
This does a few things:
 * We fetch the cn_sort from the DB and use this rather than calculating based on DefaultClassificationSource
   We were already pulling based on the items source, so this should not change things
 * Rather than using JS to submit the form, it submits via html
 * Fix subtitle display and add barcode (it was retrieved in one query but not used)
 * Add option to apply different classification scheme to the search

To test:
 1 - Add cn_browser.pl to the 'plugin' field in a framework for 952$o
 2 - Edit an item on a record in that framework
 3 - Enter an itemcallnumber
 4 - Click the two dots to launch the callnumber browser
 5 - Note the results
 6 - Apply patch
 7 - Repeat
 8 - Note subtitles and barcodes are displayed in results
 9 - Note callnumbers are appropriate
10 - Try changing the class source used
11 - Try this with differing dewey,lcc, and other callnumbers
12 - Ensure results are as expected

Signed-off-by: Myka Kennedy Stephens <mkstephens@lancasterseminary.edu>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

cataloguing/value_builder/cn_browser.pl
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/cn_browser.tt

index 51767a9..7aa8cd1 100755 (executable)
@@ -26,6 +26,8 @@ use C4::Auth;
 use C4::ClassSource;
 use C4::Output;
 
+use Koha::ClassSources;
+
 my $builder = sub {
     my ( $params ) = @_;
     my $function_name = $params->{id};
@@ -59,8 +61,6 @@ my $launcher = sub {
         }
     );
 
-    my $cn_sort;
-
     my $dbh = C4::Context->dbh;
     my $sth;
     my @cn;
@@ -86,17 +86,19 @@ my $launcher = sub {
         $search = $gt;
     }
 
+    my $cn_source = $cgi->param('cn_source') || C4::Context->preference("DefaultClassificationSource");
+    my @class_sources = Koha::ClassSources->search({ used => 1});
+
     #Don't show half the results of show lt or gt
     $real_limit = $results_per_page if $search ne $q;
-    $cn_sort = GetClassSort( undef, undef, $search );
-    my $cn_sort_q = GetClassSort( undef, undef, $q );
+    my $cn_sort = GetClassSort( $cn_source, undef, $search );
 
     my $red = 0;
     if ( $search ne $gt ) {
         my $green = 0;
 
         #Results before the cn_sort
-        $query = "SELECT b.title, itemcallnumber, biblionumber, barcode, cn_sort, branchname, author
+        $query = "SELECT b.title, b.subtitle, itemcallnumber, biblionumber, barcode, cn_sort, branchname, author
         FROM items AS i
         JOIN biblio AS b USING (biblionumber)
         LEFT OUTER JOIN branches ON (branches.branchcode = homebranch)
@@ -110,7 +112,7 @@ my $launcher = sub {
             if ( $data->{itemcallnumber} eq $q ) {
                 $data->{background} = 'red';
                 $red = 1;
-            } elsif ( ( GetClassSort( undef, undef, $data->{itemcallnumber} ) lt $cn_sort_q ) && !$green && !$red ) {
+            } elsif ( $data->{cn_sort} lt $cn_sort && !$green && !$red ) {
                 if ( $#cn != -1 ) {
                     unshift @cn, { 'background' => 'green' };
                     $globalGreen = 1;
@@ -126,7 +128,7 @@ my $launcher = sub {
         my $green = 0;
 
         #Results after the cn_sort
-        $query = "SELECT b.title, itemcallnumber, biblionumber, i.cn_sort, branchname, author
+        $query = "SELECT b.title, b.subtitle, itemcallnumber, biblionumber, barcode, cn_sort, branchname, author
         FROM items AS i
         JOIN biblio AS b USING (biblionumber)
         LEFT OUTER JOIN branches ON (branches.branchcode = homebranch)
@@ -141,7 +143,7 @@ my $launcher = sub {
             if ( $data->{itemcallnumber} eq $q ) {
                 $data->{background} = 'red';
                 $red = 1;
-            } elsif ( ( GetClassSort( undef, undef, $data->{itemcallnumber} ) gt $cn_sort_q ) && !$green && !$red && !$globalGreen ) {
+            } elsif ( $data->{cn_sort} gt $cn_sort && !$green && !$red && !$globalGreen ) {
                 push @cn, { 'background' => 'green' };
                 $green = 1;
             }
@@ -159,6 +161,9 @@ my $launcher = sub {
     $template->param( 'q'       => $q );
     $template->param( 'cn_loop' => \@cn ) if $#cn != -1;
     $template->param( 'popup'   => defined( $cgi->param('popup') ) );
+    $template->param( 'cn_source' => $cn_source ) if $cn_source;
+    $template->param( 'class_sources' => \@class_sources );
+
 
     output_html_with_http_headers $cgi, $cookie, $template->output;
 };
index 4e7dcc4..629ac87 100644 (file)
 <h1>Call number browser</h1>
 
 <div>
-    <form method="get" action="cn_browser.pl">
-    <label for="searchcn">Search call number:</label>
-    <input type="text" id="cn_browser_input" name="q" value="[% q | html %]" />
-    <input id="cn_browser_submit" type="submit" value="Search" />
+    <form id="cn_browser" method="get" action="/cgi-bin/koha/cataloguing/plugin_launcher.pl">
+        <label for="searchcn">Search call number:</label>
+        <input type="text" id="cn_browser_input" name="q" value="[% q | html %]" />
+        <input id="cn_browser_submit" type="submit" value="Search" />
+        <input name="plugin_name" type="hidden" value="cn_browser.pl"/>
+        <input name="popup" type="hidden" value="[% popup %]"/>
+        </br>
+        <label for="cn_source">Callnumber classification scheme</label>
+        <select name="cn_source" form="cn_browser">
+            [% FOREACH class_source IN class_sources %]
+                [% IF class_source.cn_source == cn_source %]
+                    <option value="[% class_source.cn_source | html %]" selected="selected">[% class_source.description | html %]</option>
+                [% ELSE %]
+                    <option value="[% class_source.cn_source | html %]">[% class_source.description | html %]</option>
+                [% END %]
+            [% END %]
+        </select>
     </form>
 </div>
 <br />
@@ -39,6 +52,7 @@
             [% IF ( cn_loo.author ) %]
                 <span>by</span> [% cn_loo.author | html %]
             [% END %]
+            [% IF ( cn_loo.barcode ) %] ([% cn_loo.barcode %])[% END %]
         </a>
     </td>
     <td style="background:[% cn_loo.background | html %];">[% cn_loo.branchname | html %]</td>
     </tbody>
 </table>
 
-[% MACRO jsinclude BLOCK %]
-    <script>
-        $(document).ready(function(){
-            $("#cn_browser_submit").click(function(){
-                window.location.href='/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=cn_browser.pl&popup&q='+$("#cn_browser_input").val();
-                return false;
-            });
-        });
-    </script>
-[% END %]
-
 [% INCLUDE 'intranet-bottom.inc' popup_window=1 %]