]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/authors.tt2
lp1271198 Strip browse and facet parameters from links
[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         tlabel = '';
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                 tlabel = relators.$relcode || label;
57             END;
58             IF code == '6';
59                target_field = tag;
60                linked_fields = [subfield.textContent()];
61                get_linked_880s;
62             END;
63             NEXT UNLESS code.match('[a-z]');
64             sf = subfield.textContent | html;
65
66             # Only Persons have birth/death dates in schema.org
67             # Match personal/corporate/conference MODS subfields
68             IF tag.substr(1,2) == '00';
69                 IF code.match('[abcqu]');
70                     PROCESS normalize_authors;
71                 END;
72                 IF code.match('d');
73                     IF subfield.textContent.match('^\s*\d{4}');
74                         birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
75                     END;
76                     IF subfield.textContent.match('-\d{4}.*$');
77                         deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4}).*$', '$1');
78                     END;
79                     indexed_term = 1;
80                     sf_raw = PROCESS normalize_qterm;
81                     qterm = qterm _ sf_raw;
82                 END;
83             ELSIF tag.substr(1,2) == '10';
84                 IF code.match('[abcdn]');
85                     PROCESS normalize_authors;
86                 END;
87             ELSIF code.match('[acdeq]');
88                 PROCESS normalize_authors;
89             END;
90             UNLESS indexed_term;
91                 supp_term = supp_term _ ' ' _ sf;
92             END;
93         END;
94         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));
95         author_type = (tlabel || label) | html;
96         
97         # schema.org changes
98         IF type == 'author';
99             IF tag.substr(1,2) == '10' && args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
100                 iprop = ' typeof="MusicGroup" property="byArtist"';
101             ELSIF tag.substr(1,2) == '00';
102                 iprop = ' typeof="Person" property="author"';
103             ELSE;
104                 iprop = ' typeof="Organization" property="author"';
105             END;
106         ELSIF type == 'added';
107             IF tag.substr(1,2) == '00';
108                 iprop = ' typeof="Person" property="contributor"';
109             ELSE;
110                 iprop = ' typeof="Organization" property="contributor"';
111             END;
112         END;
113         authtml = ' <span class="rdetail-author-div"' _ iprop _ ' resource="' _ contrib_ref _ '"><a href="' _ url _ '"><span resource="' _ contrib_ref _ '">';
114         IF iprop; authtml = authtml _ '<span property="name">'; END;
115         authtml = authtml _ link_term.replace('^\s+', '');
116         IF iprop; authtml = authtml _ '</span>'; END;
117         IF birthdate;
118             authtml = authtml _ ' <span property="birthDate">' _ birthdate _ '</span>-';
119         END;
120         IF deathdate;
121             authtml = authtml _ '<span property="deathDate">' _ deathdate _ '</span>';
122         END;
123         authtml = authtml _ '</span></a>'; # End search link
124
125         # Display supplemental terms (mostly about the author's work)
126         IF supp_term;
127             authtml = authtml _ ' ' _ supp_term;
128         END;
129
130         # Display linked 880 fields
131         FOREACH link880 IN graphics;
132             diratt = '';
133             IF link880.dir;
134                 diratt = ' dir="' _ link880.dir _ '"';
135             END;
136             authtml = authtml _ ' <span class="graphic880"' _ diratt _ '>';
137             link880.value | html;
138             authtml = authtml _ '</span>';
139         END;
140         authtml = authtml _ ' (<span property="description">' _ author_type _ '</span>). ';
141         authtml = authtml _ '</span>'; # End author span
142         authlist.push(authtml);
143     END;
144 END;
145 %]
146
147 <div class='rdetail_authors_div'>
148 [%- FOREACH author IN authors;
149     NEXT UNLESS author.xpath; 
150     authlist = [];
151     PROCESS build_author_links(
152         xpath=author.xpath, label=author.label, type=author.type
153     );
154     IF authlist.size;
155         FOREACH authtml IN authlist;
156             authtml;
157         END;
158     END;
159 END %]
160 </div>
161
162