]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/authors.tt2
2208cf06874db2637d18f1f75bffc3530022e28b
[Evergreen.git] / Open-ILS / src / templates / opac / parts / record / authors.tt2
1 [%-  
2
3 PROCESS "opac/parts/relators.tt2";
4
5 author_cnt = 0;
6 authors = [
7     {
8         type => 'author', 
9         label => l('Author'),
10         xpath => '//*[@tag="100"]|//*[@tag="110"]|//*[@tag="111"]'
11     }, {
12         type => 'added', 
13         label => l('Added Author'),
14         xpath => '//*[@tag="700"]|//*[@tag="710"]|//*[@tag="711"]'
15     }, {
16         type => 'cast', 
17         label => l('Cast'),
18         xpath => '//*[@tag="508"]'
19     }, {
20         type => 'notes', 
21         label => l('Author Notes: '),
22         xpath => '' # Comes from added content...
23     }
24 ];
25
26 BLOCK normalize_qterm;
27     subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ');
28     subfield.textContent.replace('\s{2,}', ' ');
29 END;
30
31 BLOCK normalize_authors;
32     link_term = link_term _ ' ' _ sf;
33     sf_raw = PROCESS normalize_qterm;
34     qterm = qterm _ ' ' _ sf_raw;
35     indexed_term = 1;
36 END;
37
38 BLOCK build_author_links;
39     FOR node IN ctx.marc_xml.findnodes(xpath);
40         author_cnt = author_cnt + 1;
41         contrib_ref = '#schemacontrib' _ author_cnt;
42         iprop = ''; # schema.org item type / property
43         link_term = ''; # Linked term (e.g. Personal name + Fuller form of name)
44         supp_term = ''; # Supplementary terms
45         qterm = ''; # Search query
46         tlabels = [];
47         birthdate = '';
48         deathdate = '';
49         graphics = [];
50         tag = node.getAttribute('tag');
51         FOR subfield IN node.childNodes;
52             indexed_term = '';
53             NEXT UNLESS subfield.nodeName == "subfield";
54             code = subfield.getAttribute('code');
55             IF code == '4';
56                 relcode = subfield.textContent.substr(0,3);
57                 tlabels.push( relators.$relcode || label );
58             END;
59             IF code == 'e';
60                 tlabels.push( subfield.textContent() );
61                 indexed_term = 1;
62             END;
63             IF code == '6';
64                target_field = tag;
65                linked_fields = [subfield.textContent()];
66                get_linked_880s;
67             END;
68             NEXT UNLESS code.match('[a-z]');
69             sf = subfield.textContent | html;
70
71             # Only Persons have birth/death dates in schema.org
72             # Match personal/corporate/conference MODS subfields
73             IF tag.substr(1,2) == '00';
74                 IF code.match('[abcqu]');
75                     PROCESS normalize_authors;
76                 END;
77                 IF code.match('d');
78                     IF subfield.textContent.match('^\s*\d{4}');
79                         birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
80                     END;
81                     IF subfield.textContent.match('-\d{4}.*$');
82                         deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4}).*$', '$1');
83                     END;
84                     indexed_term = 1;
85                     sf_raw = PROCESS normalize_qterm;
86                     qterm = qterm _ sf_raw;
87                 END;
88             ELSIF tag.substr(1,2) == '10';
89                 IF code.match('[abcdn]');
90                     PROCESS normalize_authors;
91                 END;
92             ELSIF code.match('[acdeq]');
93                 PROCESS normalize_authors;
94             END;
95             UNLESS indexed_term;
96                 supp_term = supp_term _ ' ' _ sf;
97             END;
98         END;
99         url = mkurl(ctx.opac_root _ '/results', {query => qterm.replace('^\s*(.*?)\s*$', '$1'), qtype => 'author'}, stop_parms.merge(expert_search_parms, general_search_parms, browse_search_parms, facet_search_parms));
100         tlabel = tlabels.join(', ');
101         tlabels = [];
102         author_type = (tlabel || label) | html;
103         
104         # schema.org changes
105         IF type == 'author';
106             IF tag.substr(1,2) == '10' && args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
107                 iprop = ' typeof="MusicGroup" property="byArtist"';
108             ELSIF tag.substr(1,2) == '00';
109                 iprop = ' typeof="Person" property="author"';
110             ELSE;
111                 iprop = ' typeof="Organization" property="author"';
112             END;
113         ELSIF type == 'added';
114             IF tag.substr(1,2) == '00';
115                 iprop = ' typeof="Person" property="contributor';
116             ELSE;
117                 iprop = ' typeof="Organization" property="contributor';
118             END;
119             IF relcode;
120                 iprop = iprop _ ' http://id.loc.gov/vocabulary/relators/' _ relcode;
121             END;
122             iprop = iprop _ '"';
123         END;
124         authtml = ' <span class="rdetail-author-div"' _ iprop _ ' resource="' _ contrib_ref _ '"><a href="' _ url _ '"><span resource="' _ contrib_ref _ '">';
125         IF iprop; authtml = authtml _ '<span property="name">'; END;
126         authtml = authtml _ link_term.replace('^\s+', '');
127         IF iprop; authtml = authtml _ '</span>'; END;
128         IF birthdate;
129             authtml = authtml _ ' <span property="birthDate">' _ birthdate _ '</span>-';
130         END;
131         IF deathdate;
132             authtml = authtml _ '<span property="deathDate">' _ deathdate _ '</span>';
133         END;
134         authtml = authtml _ '</span></a>'; # End search link
135
136         # Display supplemental terms (mostly about the author's work)
137         IF supp_term;
138             authtml = authtml _ ' ' _ supp_term;
139         END;
140
141         # Display linked 880 fields
142         FOREACH link880 IN graphics;
143             diratt = '';
144             IF link880.dir;
145                 diratt = ' dir="' _ link880.dir _ '"';
146             END;
147             authtml = authtml _ ' <span class="graphic880"' _ diratt _ '>';
148             link880.value | html;
149             authtml = authtml _ '</span>';
150         END;
151         authtml = authtml _ ' (<span property="description">' _ author_type _ '</span>). ';
152         authtml = authtml _ '</span>'; # End author span
153         authlist.push(authtml);
154     END;
155 END;
156 %]
157
158 <div class='rdetail_authors_div'>
159 [%- FOREACH author IN authors;
160     NEXT UNLESS author.xpath; 
161     authlist = [];
162     PROCESS build_author_links(
163         xpath=author.xpath, label=author.label, type=author.type
164     );
165     IF authlist.size;
166         FOREACH authtml IN authlist;
167             authtml;
168         END;
169     END;
170 END %]
171 </div>
172
173