]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/authors.tt2
Fix schema.org mapping for MusicAlbum, add Map
[working/Evergreen.git] / Open-ILS / src / templates / opac / parts / record / authors.tt2
1 [%-  
2
3 PROCESS "opac/parts/relators.tt2";
4
5 authors = [
6     {
7         type => 'author', 
8         label => l('Author'),
9         xpath => '//*[@tag="100"]|//*[@tag="110"]|//*[@tag="111"]'
10     }, {
11         type => 'added', 
12         label => l('Added Author'),
13         xpath => '//*[@tag="700"]|//*[@tag="710"]|//*[@tag="711"]'
14     }, {
15         type => 'cast', 
16         label => l('Cast'),
17         xpath => '//*[@tag="508"]'
18     }, {
19         type => 'notes', 
20         label => l('Author Notes: '),
21         xpath => '' # Comes from added content...
22     }
23 ];
24
25 BLOCK build_author_links;
26     FOR node IN ctx.marc_xml.findnodes(xpath);
27         term = '';
28         qterm = '';
29         iprop = '';
30         tlabel = '';
31         graphics = [];
32         FOR subfield IN node.childNodes;
33             NEXT UNLESS subfield.nodeName == "subfield";
34             code = subfield.getAttribute('code');
35             IF code == '4';
36                 relcode = subfield.textContent.substr(0,3);
37                 tlabel = relators.$relcode || label;
38             END;
39             IF code == '6';
40                linked_fields = [subfield.textContent()];
41                target_field = node.getAttribute('tag');
42                get_linked_880s;
43             END;
44             NEXT UNLESS code.match('[a-z]');
45             sf = subfield.textContent | html;
46             term = term _ ' ' _ sf;
47             IF code.match('[acdq]');
48                 sf_raw = subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ');
49                 qterm = qterm _ ' ' _ sf_raw;
50             END;
51         END;
52         url = mkurl(ctx.opac_root _ '/results', {query => qterm, qtype => 'author'}, ['page', 'expand']);
53         author_type = (tlabel || label) | html;
54         
55         # schema.org changes
56         IF type == 'author';
57             IF args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
58                 iprop = ' itemtype="http://schema.org/MusicGroup" itemscope itemprop="byArtist"';
59             ELSE;
60                 iprop = ' itemprop="accountablePerson"';
61             END;
62         ELSIF type == 'added';
63             iprop = ' itemprop="contributor"';
64         END;
65         '<a href="' _ url _ '"' _ iprop _ '>';
66         IF iprop; '<span itemprop="name">'; END;
67         term.replace('^\s+', '');
68         IF iprop; '</span>'; END;
69         '</a>';
70         FOREACH link880 IN graphics;
71             diratt = '';
72             IF link880.dir;
73                 diratt = ' dir="' _ link880.dir _ '"';
74             END;
75             ' <span class="graphic880"' _ diratt _ '>';
76             link880.value | html;
77             '</span>';
78         END;
79         ' (' _ author_type _ '). ';
80     END;
81 END;
82 %]
83
84 <div class='rdetail_authors_div'>
85 [%- FOREACH author IN authors;
86     NEXT UNLESS author.xpath; 
87     links = PROCESS build_author_links(
88         xpath=author.xpath, label=author.label, type=author.type
89     );
90     IF links.match('\S') %]
91     <span class='rdetail-author-div'>[% links %]</span>
92     [%- END %]
93 [%- END %]
94 </div>
95
96