]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/templates/default/opac/parts/misc_util.tt2
Merge branch 'master' of git.evergreen-ils.org:Evergreen into template-toolkit-opac
[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.summary = xml.findnodes('//*[@tag="520"]/*[@code="a"]').textContent;
14         args.edition = xml.findnodes('//*[@tag="250"]/*[@code="a"]').textContent ||
15             xml.findnodes('//*[@tag="534"]/*[@code="b"]').textContent ||
16             xml.findnodes('//*[@tag="775"]/*[@code="b"]').textContent;
17         phys = xml.findnodes(
18             '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
19         );
20         phys_content = [];
21         FOR p IN phys; phys_content.push(p.textContent); END;
22         args.phys_desc = phys_content.join("");
23
24         # MARC Callnumber
25         args.marc_cn = xml.findnodes('//*[@tag="092" or @tag="099"]/*').textContent;
26
27         # clean up the ISBN
28         args.isbn_clean = args.isbn.replace('\ .*', '');
29
30         args.holdings = [];
31         FOR holding IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
32             args.holdings.push(
33                 holding.getAttribute('label')
34             );
35         END;
36
37         # Extract the copy count summary
38         count_type = (ctx.is_staff) ? 'staff' : 'public';
39         xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
40         FOR node IN xml.findnodes(xpath);
41             args.copy_counts = {};
42             FOR attr IN ['count', 'available', 'unshadow', 'transcendant']; 
43                 args.copy_counts.$attr = node.getAttribute(attr);
44             END;
45         END;
46
47         # "mattype" == "custom marc format specifier"
48         FOR icon_style IN ['mattype', 'item_type']; 
49             node = xml.findnodes(
50                 '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]');
51             IF node;
52                 args.format_label = node.getAttribute('coded-value')
53                 args.format_icon = ctx.media_prefix _ '/images/format_icons/' _ icon_style _ '/' _ node.textContent _ '.png';
54                 LAST;
55             END;
56         END;
57     END;
58
59     BLOCK get_hold_status;
60         IF hold.hold.status == 4;
61             l("Available");
62             IF ahr.shelf_expire_time;
63                 l('<br/>Expires [_1]', 
64                     date.format(ctx.parse_datetime(ahr.shelf_expire_time), DATE_FORMAT));
65             END;
66         ELSIF hold.hold.estimated_wait AND hold.hold.estimated_wait > 0;
67             # estimated wait is delivered as seconds.
68             SET hwait = POSIX.ceil(hold.hold.estimated_wait / 86400);
69             l("Estimated wait: [quant,_1,day,days]", hwait);
70         ELSIF hold.hold.status == 3;
71             l("In Transit");
72         ELSIF hold.hold.status < 3;
73             l("Waiting for copy");
74         END;
75     END;
76 %]