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