]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/authors.tt2
6d25b3c51ccabfb415c8287b24bd3d324ec65d5a
[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}.*$');
59                     deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4}).*$', '$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 tag.substr(1,2) == '10' && args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
71                 iprop = ' typeof="MusicGroup" property="byArtist"';
72             ELSIF tag.substr(1,2) == '00';
73                 iprop = ' typeof="Person" property="author"';
74             ELSE;
75                 iprop = ' typeof="Organization" property="author"';
76             END;
77         ELSIF type == 'added';
78             IF tag.substr(1,2) == '00';
79                 iprop = ' typeOf="Person" property="contributor"';
80             ELSE;
81                 iprop = ' typeOf="Organization" property="contributor"';
82             END;
83         END;
84         '<a href="' _ url _ '"' _ iprop _ '>';
85         IF iprop; '<span property="name">'; END;
86         term.replace('^\s+', '');
87         IF iprop; '</span>'; END;
88         IF birthdate;
89             ' <span property="birthDate">' _ birthdate _ '</span>-';
90         END;
91         IF deathdate;
92             '<span property="deathDate">' _ deathdate _ '</span>';
93         END;
94         '</a>';
95         FOREACH link880 IN graphics;
96             diratt = '';
97             IF link880.dir;
98                 diratt = ' dir="' _ link880.dir _ '"';
99             END;
100             ' <span class="graphic880"' _ diratt _ '>';
101             link880.value | html;
102             '</span>';
103         END;
104         ' (' _ author_type _ '). ';
105     END;
106 END;
107 %]
108
109 <div class='rdetail_authors_div'>
110 [%- FOREACH author IN authors;
111     NEXT UNLESS author.xpath; 
112     links = PROCESS build_author_links(
113         xpath=author.xpath, label=author.label, type=author.type
114     );
115     IF links.match('\S') %]
116     <span class='rdetail-author-div'>[% links %]</span>
117     [%- END %]
118 [%- END %]
119 </div>
120
121