[open-ils-commits] r16854 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Search (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jul 6 12:14:36 EDT 2010


Author: erickson
Date: 2010-07-06 12:14:32 -0400 (Tue, 06 Jul 2010)
New Revision: 16854

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
Log:
added ability to tag bib record results from staged multiclass search as previously checked out by the user.  the code compares search results to the set of circs in the user's visible circulations history.  the ultimate goal is to provide the ability to style rows in search results so the patron can see if he/she already circulated the item (assuming some widget to turn this feature on/off for a search)

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm	2010-07-06 16:14:18 UTC (rev 16853)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm	2010-07-06 16:14:32 UTC (rev 16854)
@@ -910,6 +910,11 @@
     format  : The MARC format
     sort    : What field to sort the results on? [ author | title | pubdate ]
     sort_dir: What direction do we sort? [ asc | desc ]
+    tag_circulated_records : Boolean, if true, records that are in the user's visible checkout history
+        will be tagged with an additional value ("1") as the last value in the record ID array for
+        each record.  Requires the 'authtoken'
+    authtoken : Authentication token string;  When actions are performed that require a user login
+        (e.g. tagging circulated records), the authentication token is required
 
 The searches element is required, must have a hashref value, and the hashref must contain at least one 
 of the following classes as a key:
@@ -1170,6 +1175,10 @@
             # Create backwards-compatible result structures
             if($self->api_name =~ /biblio/) {
                 $results = [map {[$_->{id}]} @$results];
+
+                tag_circulated_records($search_hash->{authtoken}, $results) 
+                    if $search_hash->{tag_circulated_records} and $search_hash->{authtoken};
+
             } else {
                 $results = [map {[$_->{id}, $_->{rel}, $_->{record}]} @$results];
             }
@@ -1250,6 +1259,34 @@
     return undef;
 }
 
+sub tag_circulated_records {
+    my ($auth, $results) = @_;
+    my $e = new_editor(authtoken => $auth);
+    return $results unless $e->checkauth;
+
+    # Give me the distinct set of bib records that exist in the user's visible circulation history
+    my $circ_recs = $e->json_query({
+        select => {acn => [{column => 'record', transform => 'distinct'}]}, 
+        from => {acp => 'acn'}, 
+        where => {
+            '+acp' => {
+                id => {
+                    in => {
+                        from => ['action.usr_visible_circ_copies', $e->requestor->id]}
+                }
+            }
+        }
+    });
+
+    # if the record appears in the circ history, push a 1 onto 
+    # the rec array structure to indicate truthiness
+    for my $rec (@$results) {
+        push(@$rec, 1) if grep { $_->{record} eq $$rec[0] } @$circ_recs;
+    }
+
+    $results
+}
+
 # creates a unique token to represent the query in the cache
 sub search_cache_key {
     my $method = shift;



More information about the open-ils-commits mailing list