Add call number and location info to TPAC e-mail and print option
authorArt Rhyno <art632000@yahoo.ca>
Thu, 27 Sep 2012 02:34:48 +0000 (22:34 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 7 May 2013 19:57:58 +0000 (15:57 -0400)
I haven't figured out how to get the hostname properly, I am guessing
it needs to be passed as a parameter somehow. I also need to test
URIs but this is a start.

Open-ILS/src/sql/Pg/950.data.seed-values.sql

index a8ddf6a..e4266a3 100644 (file)
@@ -8791,7 +8791,8 @@ INSERT INTO action_trigger.event_definition (
         NULL,
         '00:00:00',
 $$
-[%- SET user = target.0.owner -%]
+[%- SET user = target.0.owner; 
+    SET print_limit = 500; #this is to limit the no. of copies, set to 0 for unlimited %]
 To: [%- params.recipient_email || user.email %]
 From: [%- params.sender_email || default_sender %]
 Subject: Bibliographic Records
@@ -8801,6 +8802,8 @@ Subject: Bibliographic Records
     bre_id = item.target_biblio_record_entry;
 
     bibxml = helpers.unapi_bre(bre_id, {flesh => '{mra}'});
+    holdingsxml = helpers.unapi_bre(bre_id, {flesh => '{holdings_xml,acp}'});
+
     FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
         title = title _ part.textContent;
     END;
@@ -8812,9 +8815,65 @@ Subject: Bibliographic Records
     isbn = bibxml.findnodes('//*[@tag="020"]/*[@code="a"]').textContent;
     issn = bibxml.findnodes('//*[@tag="022"]/*[@code="a"]').textContent;
     upc = bibxml.findnodes('//*[@tag="024"]/*[@code="a"]').textContent;
+
+    uris = [];
+    holdings = [];
+    part_label='';
+    FOR volume IN holdingsxml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
+        # Check volume visibility - could push this into XPath
+        vol.label = volume.getAttribute('label');
+
+        # Prepend prefix, if any
+        prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]');
+        IF prefix.getAttribute('label') != '';
+           vol.label = prefix.getAttribute('label') _ " " _ vol.label;
+        END;
+
+        # Append prefix, if any
+        suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]');
+        IF suffix.getAttribute('label') != '';
+           vol.label = vol.label _ " " _ suffix.getAttribute('label');
+        END;
+        IF vol.label == '##URI##';
+           FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]');
+               res = {};
+               res.href = uri.getAttribute('href');
+               res.link = uri.getAttribute('label');
+               res.note = uri.getAttribute('use_restriction');
+               uris.push(res);
+           END;
+           NEXT;
+        ELSE;
+           copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
+           FOR copy IN copies;
+               parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]');
+               FOREACH part IN parts;
+                       part_label = part.getAttribute('label');
+                       LAST IF part_label != '';
+               END;
+
+               NEXT IF (copy.getAttribute('deleted') == 'true' OR copy.getAttribute('opac_visible') == 'false');
+               loc = copy.findnodes('./*[local-name()="location"]');
+               circlib = copy.findnodes('./*[local-name()="circlib"]');
+               status = copy.findnodes('./*[local-name()="status"]');
+               holding = {
+                    label => vol.label,
+                    part_label => part_label,
+                    library => circlib.textContent,
+                    location => loc.textContent,
+                    status => status.textContent
+                    barcode => copy.getAttribute('barcode')
+               };
+               holdings.push(holding);
+               part_label = '';
+           END;
+        END;
+    END;
+
 %]
 
-[% loop.count %]/[% loop.size %].  Bib ID# [% bre_id %] 
+[% loop.count %]/[% loop.size %].  Bib ID# [% bre_id %]
+URL: [% params.hostname %]/eg/opac/record/[% bre_id %]
 [% IF isbn %]ISBN: [% isbn _ "\n" %][% END -%]
 [% IF issn %]ISSN: [% issn _ "\n" %][% END -%]
 [% IF upc  %]UPC:  [% upc _ "\n" %] [% END -%]
@@ -8823,6 +8882,22 @@ Author: [% author %]
 Publication Info: [% publisher %] [% pubdate %]
 Item Type: [% item_type %]
 
+[% IF holdings.size > 0 %]
+   [% IF holdings.size > print_limit AND print_limit > 0 %]
+      Showing [% print_limit %] of [% holdings.size %], use URL for full list of copies...
+   [% END %]
+   [% FOR holding IN holdings %]
+      Location: [% holding.library %] - [% holding.location _ "\n" %]
+      Call Number: [% holding.label _ "\n" %][% IF holding.part_label %][% holding.part_label _ "\n" %][% END -%]
+      Status: [% holding.status _ "\n" %]
+   [% END %]
+[% END %]
+[% IF uris.size > 0 %]
+   [% FOR uri IN uris %]
+      URL: [% uri.href _ "\n" %]
+   [% END %]
+[% END %]
+
 [% END %]
 [% END %]
 $$
@@ -8844,11 +8919,13 @@ $$
 <div>
     <style> li { padding: 8px; margin 5px; }</style>
     <ol>
+    [% SET print_limit = 500; #this is to limit the no. of copies, set to 0 for unlimited %]
     [% FOR cbreb IN target %]
     [% FOR item IN cbreb.items;
         bre_id = item.target_biblio_record_entry;
 
         bibxml = helpers.unapi_bre(bre_id, {flesh => '{mra}'});
+        holdingsxml = helpers.unapi_bre(bre_id, {flesh => '{holdings_xml,acp}'});
         FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
             title = title _ part.textContent;
         END;
@@ -8858,14 +8935,99 @@ $$
         publisher = bibxml.findnodes('//*[@tag="260"]/*[@code="b"]').textContent;
         pubdate = bibxml.findnodes('//*[@tag="260"]/*[@code="c"]').textContent;
         isbn = bibxml.findnodes('//*[@tag="020"]/*[@code="a"]').textContent;
+        issn = bibxml.findnodes('//*[@tag="022"]/*[@code="a"]').textContent;
+
+        uris = [];
+        holdings = [];
+        part_label='';
+        FOR volume IN holdingsxml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
+            vol.label = volume.getAttribute('label');
+
+            prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]');
+            IF prefix.getAttribute('label') != '';
+                vol.label = prefix.getAttribute('label') _ " " _ vol.label;
+            END;
+
+            # Append prefix, if any
+            suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]');
+            IF suffix.getAttribute('label') != '';
+                vol.label = vol.label _ " " _ suffix.getAttribute('label');
+            END;
+            IF vol.label == '##URI##';
+                FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]');
+                    res = {};
+                    res.href = uri.getAttribute('href');
+                    res.link = uri.getAttribute('label');
+                    res.note = uri.getAttribute('use_restriction');
+                    uris.push(res);
+                END;
+                NEXT;
+            ELSE;
+                copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
+                FOR copy IN copies;
+                    parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]');
+                    FOREACH part IN parts;
+                        part_label = part.getAttribute('label');
+                        LAST IF part_label != '';
+                    END;
+
+                    NEXT IF (copy.getAttribute('deleted') == 'true' OR copy.getAttribute('opac_visible') == 'false');
+                    loc = copy.findnodes('./*[local-name()="location"]');
+                    circlib = copy.findnodes('./*[local-name()="circlib"]');
+                    status = copy.findnodes('./*[local-name()="status"]');
+                    holding = {
+                        label => vol.label,
+                        part_label => part_label,
+                        library => circlib.textContent,
+                        location => loc.textContent,
+                        status => status.textContent
+                        barcode => copy.getAttribute('barcode')
+                    };
+                    holdings.push(holding);
+                    part_label = '';
+                END;
+            END;
+        END;
+
         %]
 
         <li>
-            Bib ID# [% bre_id %] ISBN: [% isbn %]<br />
+            Bib ID# [% bre_id %] [% IF isbn %]ISBN: [% isbn | html %]<br/>[% END -%] [% IF issn %]ISSN: [% issn | html %]<br/>[% END -%] <br />
             Title: [% title %]<br />
             Author: [% author %]<br />
             Publication Info: [% publisher %] [% pubdate %]<br/>
-            Item Type: [% item_type %]
+            Item Type: [% item_type %]<br/>
+            
+            [% IF upc  %]UPC:  [% upc  | html %]<br/>[% END -%]
+            [% IF holdings.size > 0 %]
+               [% IF holdings.size > print_limit AND print_limit > 0 %]
+                  Showing <strong>[% print_limit %] of [% holdings.size %]</strong>...<br />
+               [% END %]
+
+               <ul>
+               [% FOR holding IN holdings %]
+                  [% IF loop.count() > print_limit; LAST; END %]
+                  <li>Location: [% holding.library | html %] - [% holding.location | html %]<br/>
+                  Barcode: [% holding.barcode | html %]<br/>
+                  Call Number: [% holding.label | html %][% holding.part_label | html %] <br/>
+                  Status: [% holding.status | html %]</li>
+               [% END %]
+               </ul>
+            [% END %]
+            [% IF uris.size > 0 %]
+               <ul>
+               [% FOR uri IN uris %]
+                  <li>URL: [% uri.href | html %]<br/>
+                  [% IF uri.link.length > 0 %]
+                     Label: [% uri.href | html %]<br />
+                  [% END %]
+                  [% IF uri.note.length > 0 %]
+                     Note: [% uri.note | html %]<br />
+                  [% END %]
+                  </li>
+               [% END %]
+               </ul>
+            [% END %]
         </li>
     [% END %]
     [% END %]