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