]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/authors.tt2
94a887b7db694388c0962bbe5563da8385ae2e75
[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         birthdate = '';
32         deathdate = '';
33         graphics = [];
34         tag = node.getAttribute('tag');
35         FOR subfield IN node.childNodes;
36             NEXT UNLESS subfield.nodeName == "subfield";
37             code = subfield.getAttribute('code');
38             IF code == '4';
39                 relcode = subfield.textContent.substr(0,3);
40                 tlabel = relators.$relcode || label;
41             END;
42             IF code == '6';
43                target_field = tag;
44                linked_fields = [subfield.textContent()];
45                get_linked_880s;
46             END;
47             NEXT UNLESS code.match('[a-z]');
48             sf = subfield.textContent | html;
49             IF code.match('[acdq]');
50                 sf_raw = subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ');
51                 qterm = qterm _ ' ' _ sf_raw;
52             END;
53             # Only Persons have birth/death dates in schema.org
54             IF code.match('d') && tag.substr(1,2) == '00';
55                 IF subfield.textContent.match('^\s*\d{4}');
56                     birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
57                 END;
58                 IF subfield.textContent.match('-\d{4}\s*$');
59                     deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4})\s*$', '$1');
60                 END;
61             ELSE;
62                 term = term _ ' ' _ sf;
63             END;
64         END;
65         url = mkurl(ctx.opac_root _ '/results', {query => qterm, qtype => 'author'}, ['page', 'expand']);
66         author_type = (tlabel || label) | html;
67         
68         # schema.org changes
69         IF type == 'author';
70             IF args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
71                 iprop = ' itemtype="http://schema.org/MusicGroup" itemscope itemprop="byArtist"';
72             ELSE;
73                 iprop = ' itemtype="http://schema.org/Person" itemscope itemprop="author"';
74             END;
75         ELSIF type == 'added';
76             iprop = ' itemprop="contributor"';
77         END;
78         '<a href="' _ url _ '"' _ iprop _ '>';
79         IF iprop; '<span itemprop="name">'; END;
80         term.replace('^\s+', '');
81         IF iprop; '</span>'; END;
82         IF birthdate;
83             ' <span itemprop="birthDate">' _ birthdate _ '</span>-';
84         END;
85         IF deathdate;
86             '<span itemprop="deathDate">' _ deathdate _ '</span>';
87         END;
88         '</a>';
89         FOREACH link880 IN graphics;
90             diratt = '';
91             IF link880.dir;
92                 diratt = ' dir="' _ link880.dir _ '"';
93             END;
94             ' <span class="graphic880"' _ diratt _ '>';
95             link880.value | html;
96             '</span>';
97         END;
98         ' (' _ author_type _ '). ';
99     END;
100 END;
101 %]
102
103 <div class='rdetail_authors_div'>
104 [%- FOREACH author IN authors;
105     NEXT UNLESS author.xpath; 
106     links = PROCESS build_author_links(
107         xpath=author.xpath, label=author.label, type=author.type
108     );
109     IF links.match('\S') %]
110     <span class='rdetail-author-div'>[% links %]</span>
111     [%- END %]
112 [%- END %]
113 </div>
114
115