Show local call number in TPAC My Lists display
authorBill Erickson <berick@esilibrary.com>
Thu, 13 Dec 2012 16:34:50 +0000 (11:34 -0500)
committerBen Shum <bshum@biblio.org>
Mon, 11 Mar 2013 21:42:49 +0000 (17:42 -0400)
If an opac-visible call number exists that is owned by an org unit
relevant to the patron, show the (most relevant) call number label in
the My Lists display for each record in the list.  Call number is
displayed in both saved and temporary lists.

A call number is considered relevant if its owner is one of:

physical location library
preferred library (plib, home, etc.)
search library

This code leverages the new "exclude_invisible_acn" unapi filter to
ensure that we are only required to retrieve 1 call number in the unapi
output instead of an arbitrarily large set of call numbers, against
which we may have to filter non-visible call numbers.

This commit also addresses and outstanding TODO item in the tpac Perl:
Replace the last use of fetch_marc_xml_by_id with get_records_and_facets
and remove fetch_marc_xml_by_id

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/myopac/lists.tt2
Open-ILS/src/templates/opac/parts/anon_list.tt2
Open-ILS/src/templates/opac/parts/misc_util.tt2

index 337ee52..ec7bb96 100644 (file)
@@ -1755,6 +1755,7 @@ sub load_myopac_bookbags {
             # transaction rollback under the covers.
             $e->rollback;
 
+
             my $query = $self->_prepare_bookbag_container_query(
                 $bookbag->id, $sorter, $modifier
             );
@@ -1769,11 +1770,21 @@ sub load_myopac_bookbags {
             my $items = $U->bib_container_items_via_search($bookbag->id, $query, $args)
                 or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
 
+            # capture pref_ou for callnumber filter/display
+            $ctx->{pref_ou} = $self->_get_pref_lib() || $ctx->{search_ou};
+
+            # search for local callnumbers for display
+            my $focus_ou = $ctx->{physical_loc} || $ctx->{pref_ou};
 
             my (undef, @recs) = $self->get_records_and_facets(
                 [ map {$_->target_biblio_record_entry->id} @$items ],
                 undef, 
-                {flesh => '{mra}'}
+                {
+                    flesh => '{mra,holdings_xml,acp,exclude_invisible_acn}',
+                    flesh_depth => 1,
+                    site => $ctx->{get_aou}->($focus_ou)->shortname,
+                    pref_lib => $ctx->{pref_ou}
+                }
             );
 
             $ctx->{bookbags_marc_xml}{$_->{id}} = $_->{marc_xml} for @recs;
index 445654d..b61ac06 100644 (file)
@@ -28,9 +28,33 @@ sub fetch_mylist {
         }
     }
 
+    {   # sanitize
+        no warnings qw/numeric/;
+        $list = [map { int $_ } @$list];
+        $list = [grep { $_ > 0} @$list];
+    };
+
     my $marc_xml;
     if ($with_marc_xml) {
-        $marc_xml = $self->fetch_marc_xml_by_id($list);
+        my $ctx = $self->ctx;
+
+        # capture pref_ou for callnumber filter/display
+        $ctx->{pref_ou} = $self->_get_pref_lib() || $ctx->{search_ou};
+
+        # search for local callnumbers for display
+        my $focus_ou = $ctx->{physical_loc} || $ctx->{pref_ou};
+
+        my (undef, @recs) = $self->get_records_and_facets(
+            $list, undef, {
+                flesh => '{mra,holdings_xml,acp,exclude_invisible_acn}',
+                flesh_depth => 1,
+                site => $ctx->{get_aou}->($focus_ou)->shortname,
+                pref_lib => $ctx->{pref_ou}
+            }
+        );
+
+        # make it look like the caller is expecting
+        $marc_xml = { map {$_->{id} => $_->{marc_xml}} @recs };
     }
 
     # Leverage QueryParser to sort the items by values of config.metabib_fields
index ec8b6be..39f986f 100644 (file)
@@ -137,6 +137,13 @@ sub init_ro_object_cache {
         return [ values %{$cache{map}{$ctx->{locale}}{aou}} ];
     };
 
+    # returns the org unit object by shortname
+    $ro_object_subs->{get_aou_by_shortname} = sub {
+        my $sn = shift or return undef;
+        my $list = $ro_object_subs->{aou_list}->();
+        return (grep {$_->shortname eq $sn} @$list)[0];
+    };
+
     $ro_object_subs->{aouct_tree} = sub {
 
         # fetch the org unit tree
@@ -340,36 +347,6 @@ sub get_records_and_facets {
     return ($facets, @data);
 }
 
-# TODO: blend this code w/ ^-- get_records_and_facets
-sub fetch_marc_xml_by_id {
-    my ($self, $id_list) = @_;
-    $id_list = [$id_list] unless ref($id_list);
-
-    {
-        no warnings qw/numeric/;
-        $id_list = [map { int $_ } @$id_list];
-        $id_list = [grep { $_ > 0} @$id_list];
-    };
-
-    return {} if scalar(@$id_list) < 1;
-
-    # I'm just sure there needs to be some more efficient way to get all of
-    # this.
-    my $results = $self->editor->json_query({
-        "select" => {"bre" => ["id", "marc"]},
-        "from" => {"bre" => {}},
-        "where" => {"id" => $id_list}
-    }, {substream => 1}) or return $self->editor->die_event;
-
-    my $marc_xml = {};
-    for my $r (@$results) {
-        $marc_xml->{$r->{"id"}} =
-            (new XML::LibXML)->parse_string($r->{"marc"});
-    }
-
-    return $marc_xml;
-}
-
 sub _get_search_lib {
     my $self = shift;
     my $ctx = $self->ctx;
index 5347d34..b43ad42 100644 (file)
                     <td class="list_entry">
                         <a href="[% mkurl(ctx.opac_root _ '/myopac/lists', {sort=>(CGI.param('sort') == 'authorsort' ? 'authorsort.descending' : 'authorsort')}) %]">[% l('Author(s)') %]</a>
                     </td>
+                    <td class='list_entry'>
+                        [% l('Local Call Number') %]
+                    </td>
                     <td class="list_entry">
                         <a href="[% mkurl(ctx.opac_root _ '/myopac/lists', {sort=>(CGI.param('sort') == 'pubdate' ? 'pubdate.descending' : 'pubdate')}) %]">[% l('Publication Date') %]</a>
                     </td>
                             -%]">[% attrs.author | html %]</a>
                     </td>
                     <td class="list_entry">
+                        [% 
+                            copy = attrs.holdings.0;
+                            IF copy;
+                                # only show a relevant call number
+                                org = ctx.get_aou_by_shortname(copy.owner);
+                                IF  org.id == ctx.search_ou OR 
+                                    org.id == ctx.pref_ou OR
+                                    org.id == ctx.user.home_ou OR
+                                    org.id == ctx.physical_loc;
+                                        l('[_1] ([_2])', copy.label, org.name) | html;
+                                END;
+                            END;
+                        %]
+                    </td>
+                    <td class="list_entry">
                           [% attrs.pubdate | html %]
                     </td>
                     <td class="list_entry">
index 89e771c..cd39bbc 100644 (file)
@@ -23,8 +23,9 @@
                                 for (i = 0; i < inputs.length; i++) { 
                                     if (inputs[i].name == 'record' && !inputs[i].disabled) inputs[i].checked = this.checked;}"/>
                         </td>
-                        <td width="49%" class="opac-auto-108"><a href="[% mkurl('', {anonsort=>(CGI.param('anonsort') == 'titlesort' ? 'titlesort.descending' : 'titlesort')}) %]">[% l('Title') %]</a></td>
-                        <td width="49%" class="opac-auto-108"><a href="[% mkurl('', {anonsort=>(CGI.param('anonsort') == 'authorsort' ? 'authorsort.descending' : 'authorsort')}) %]">[% l('Author(s)') %]</a% l('Author(s)') %]</td>
+                        <td width="40%" class="opac-auto-108"><a href="[% mkurl('', {anonsort=>(CGI.param('anonsort') == 'titlesort' ? 'titlesort.descending' : 'titlesort')}) %]">[% l('Title') %]</a></td>
+                        <td width="40%" class="opac-auto-108"><a href="[% mkurl('', {anonsort=>(CGI.param('anonsort') == 'authorsort' ? 'authorsort.descending' : 'authorsort')}) %]">[% l('Author(s)') %]</a% l('Author(s)') %]</td>
+                        <td width='18%'>[% l('Local Call Number') %]</td>
                         <td width="1%" class="nowrap">
                             <select name="action">
                                 <option>[% l('-- Actions for these items --') %]</option>
                                 ['page', 'id', 'edit_notes']
                             )
                         -%]">[% attrs.author | html %]</a></td>
+                        <td class="item_list_padding" style="padding-left: 5px;">
+                        [% 
+                            copy = attrs.holdings.0;
+                            IF copy;
+                                # only show a relevant call number
+                                org = ctx.get_aou_by_shortname(copy.owner);
+                                IF  org.id == ctx.search_ou OR 
+                                    org.id == ctx.pref_ou OR
+                                    org.id == ctx.user.home_ou OR
+                                    org.id == ctx.physical_loc;
+                                        l('[_1] ([_2])', copy.label, org.name) | html;
+                                END;
+                            END;
+                        %]
+                        </td>
                     </tr>
                     [% END %]
                 </tbody>
index cb00059..2d2f299 100644 (file)
                         part_label => part_label,
                         location => loc.textContent,
                         library => circlib.textContent,
-                        status => status.textContent
-                        barcode => copy.getAttribute('barcode')
+                        status => status.textContent,
+                        barcode => copy.getAttribute('barcode'),
+                        owner => volume.getAttribute('lib')
                     };
                     args.holdings.push(holding);
                     part_label = '';