LP#1284864 TPAC metarecord display record count in results
authorBill Erickson <berick@esilibrary.com>
Tue, 25 Feb 2014 21:47:03 +0000 (16:47 -0500)
committerMike Rylander <mrylander@gmail.com>
Mon, 10 Mar 2014 16:29:51 +0000 (12:29 -0400)
Next to each metarecord containing more than one record, display the
count of constituent records next to the record title in parentheses.
This allows the user to see at a glance if a record is really grouped or
simply a single-record "group".

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/templates/opac/parts/result/table.tt2

index 57e0bfb..092bf16 100644 (file)
@@ -502,6 +502,20 @@ sub load_rresults {
     # load temporary_list settings for user and ou:
     $self->_load_lists_and_settings if ($ctx->{user});
 
+    # fetch metarecord constituent counts for display
+    my $mr_counts = [];
+    if ($is_meta) {
+        $mr_counts = $e->json_query({
+            select => {mmrsm => [{
+                    column => 'id', transform => 'count', 
+                    alias => 'count', aggregate => 1
+                }, 'metarecord'
+            ]},
+            from => 'mmrsm',
+            where => {'+mmrsm' => {metarecord => $rec_ids}}
+        });
+    }
+
     # shove recs into context in search results order
     for my $rec_id (@$rec_ids) {
         my ($rec) = grep { $_->{$id_key} == $rec_id } @data;
@@ -510,10 +524,11 @@ sub load_rresults {
         $ctx->{metarecord_master} = $rec
             if $metarecord_master and $metarecord_master eq $rec_id;
 
-        # MR's with multiple constituent records will have a
-        # null value in position 2 of the result set.  
-        my ($res_rec) = grep { $_->[0] == $rec_id} @{$results->{ids}};
-        $rec->{mr_has_multi} = !$res_rec->[2];
+        if ($is_meta) {
+            # add the count of constituent records to the metarecord
+            my ($count) = grep {$_->{metarecord} == $rec_id} @$mr_counts;
+            $rec->{mr_constituent_count} = $count->{count};
+        }
     }
 
     if ($tag_circs) {
index b927de2..483d529 100644 (file)
@@ -40,7 +40,7 @@
                             # note: rec.id refers to the record identifier, regardless
                             # of the type of record. i.e. rec.id = mmr_id ? mmr_id : bre_id
                             IF rec.mmr_id;
-                                IF rec.mr_has_multi;
+                                IF rec.mr_constituent_count > 1;
                                     # metarecords link to record list page
                                     record_url = mkurl(ctx.opac_root _ '/results', 
                                         {metarecord => rec.mmr_id}, ['page']);
                                                     [% END %]
                                                     <a class='record_title search_link' name='record_[% rec.id %]'
                                                         href="[% record_url %]"
-                                                        [% html_text_attr('title', l('Display record details for "[_1]"', attrs.title)) %]
-                                                        >[% attrs.title | html %]</a>
+                                                        [% html_text_attr('title', l('Display record details for "[_1]"', attrs.title)) %]>
+                                                        [% attrs.title | html %]
+                                                     </a>
+                                                     [% IF rec.mr_constituent_count > 1 %]
+                                                     <span title="[% l('This group contains [_1] records', rec.mr_constituent_count) %]">
+                                                      ([% rec.mr_constituent_count %])
+                                                     </span>
+                                                     [% END %]
+
 [%-
 FOR entry IN attrs.graphic_titles;
     FOR alt IN entry.graphic;