]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/templates/default/opac/parts/misc_util.tt2
More config docs for SFX resolver TTOPAC bits
[working/Evergreen.git] / Open-ILS / web / templates / default / opac / parts / misc_util.tt2
1 [% 
2     # Extract MARC fields from XML
3     #   get_marc_attrs( { marc_xml => doc } )
4     BLOCK get_marc_attrs;
5         xml = args.marc_xml;
6         args.isbn = xml.findnodes('//*[@tag="020"]/*[@code="a"]').shift.textContent;
7         args.upc = xml.findnodes('//*[@tag="024"]/*[@code="a"]').textContent;
8         args.issn = xml.findnodes('//*[@tag="022"]/*[@code="a"]').textContent;
9         args.title = xml.findnodes('//*[@tag="245"]/*[@code="a"]').textContent;
10         args.author = xml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
11         args.publisher = xml.findnodes('//*[@tag="260"]/*[@code="b"]').textContent;
12         args.pubdate = xml.findnodes('//*[@tag="260"]/*[@code="c"]').textContent;
13         args.edition = xml.findnodes('//*[@tag="250"]/*[@code="a"]').textContent ||
14             xml.findnodes('//*[@tag="534"]/*[@code="b"]').textContent ||
15             xml.findnodes('//*[@tag="775"]/*[@code="b"]').textContent;
16         phys = xml.findnodes(
17             '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
18         );
19         phys_content = [];
20         FOR p IN phys; phys_content.push(p.textContent); END;
21         args.phys_desc = phys_content.join("");
22
23         # MARC Callnumber
24         args.marc_cn = xml.findnodes('//*[@tag="092" or @tag="099"]/*').textContent;
25
26         # clean up the ISBN
27         args.isbn_clean = args.isbn.replace('\ .*', '');
28
29         args.holdings = [];
30         args.uris = [];
31         args.issns = [];
32
33         # we use $9 of ISBN and ISSN as a flag for e-version
34         sfx_isbn = xml.findnodes('//*[@tag="020"]/*[@code="9"]');
35         IF sfx_isbn;
36             IF sfx_isbn.textContent == "SFX";
37                 my_parent = sfx_isbn.parentNode();
38                 sfx_isbn = my_parent.findnodes('./*[@code="a"]');
39                 sfx_isbn.replace('-', '');
40                 args.resolver_isbn = sfx_isbn.replace('\ .*', '');
41             END;
42         END;
43
44         sfx_issn = xml.findnodes('//*[@tag="022"]/*[@code="9"]');
45         IF sfx_issn;
46             IF sfx_issn.textContent == "SFX";
47                 my_parent = sfx_issn.parentNode();
48                 sfx_issn = my_parent.findnodes('./*[@code="a"]');
49                 args.issns.push(
50                     sfx_issn.textContent.replace('[^\d\-X]', '')
51                 );
52             END;
53         END;
54
55         # we snag all issns if no SFX available
56         IF args.issns.size == 0;
57             FOR rawissn IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
58                 args.issns.push(
59                     rawissn.textContent.replace('[^\d\-X]', '')
60                 );
61             END;
62         END;
63
64         # URI info is in volumes/volume/uris/volume, instead of uri element
65         FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
66
67             # Check volume visibility - could push this into XPath
68             vol.label = volume.getAttribute('label');
69             vol.id = volume.getAttribute('id');
70             NEXT IF volume.getAttribute('opac_visible') == 'false';
71             NEXT IF volume.getAttribute('deleted') == 'true';
72
73             IF vol.label == '##URI##';
74                 FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="volume"]');
75                     res.href = uri.getAttribute('href');
76                     res.link = uri.getAttribute('label');
77                     res.note = uri.getAttribute('use_restriction');
78                     args.uris.push(res);
79                 END;
80                 NEXT;
81             ELSE;
82                 copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
83                 FOR copy IN copies;
84                     # Check copy visibility
85                     cp.deleted = copy.getAttribute('deleted');    
86                     cp.visible = copy.getAttribute('opac_visible');
87                     NEXT IF (cp.deleted == 'true' OR cp.visible == 'false');
88
89                     # Iterate through all of the children to determine visibility
90                     FOR node IN cp.childNodes;
91                         NEXT IF cp.visible == 'false';
92                         vis = node.getAttribute('opac_visible');
93                         del = node.getAttribute('deleted');
94                         IF vis == 'false' or del == 'true';
95                             cp.visible = 'false';
96                         END;
97                     END;
98
99                     NEXT IF cp.visible == 'false';
100                     
101                     loc = copy.findnodes('./*[local-name()="location"]');
102                     circlib = copy.findnodes('./*[local-name()="circlib"]');
103                     status = copy.findnodes('./*[local-name()="status"]');
104
105                     holding = {
106                         label => vol.label,
107                         location => loc.textContent,
108                         library => circlib.textContent,
109                         status => status.textContent
110                         barcode => copy.getAttribute('barcode')
111                     };
112                     args.holdings.push(holding);
113                 END;
114             END;
115         END;
116
117         # Extract the copy count summary
118         count_type = (ctx.is_staff) ? 'staff' : 'public';
119         xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
120         FOR node IN xml.findnodes(xpath);
121             args.copy_counts = {};
122             FOR attr IN ['count', 'available', 'unshadow', 'transcendant']; 
123                 args.copy_counts.$attr = node.getAttribute(attr);
124             END;
125         END;
126
127         # "mattype" == "custom marc format specifier"
128         FOR icon_style IN ['mattype', 'item_type']; 
129             node = xml.findnodes(
130                 '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]');
131             IF node;
132                 args.format_label = node.getAttribute('coded-value')
133                 args.format_icon = ctx.media_prefix _ '/images/format_icons/' _ icon_style _ '/' _ node.textContent _ '.png';
134                 LAST;
135             END;
136         END;
137     END;
138
139     BLOCK get_hold_status;
140         IF hold.hold.status == 4;
141             l("Available");
142             IF ahr.shelf_expire_time;
143                 l('<br/>Expires [_1]', 
144                     date.format(ctx.parse_datetime(ahr.shelf_expire_time), DATE_FORMAT));
145             END;
146         ELSIF hold.hold.estimated_wait AND hold.hold.estimated_wait > 0;
147             # estimated wait is delivered as seconds.
148             SET hwait = POSIX.ceil(hold.hold.estimated_wait / 86400);
149             l("Estimated wait: [quant,_1,day,days]", hwait);
150         ELSIF hold.hold.status == 3;
151             l("In Transit");
152         ELSIF hold.hold.status < 3;
153             l("Waiting for copy");
154         END;
155     END;
156 %]