1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Functions for dealing with CDM entities from the package model.name
|
5
|
*
|
6
|
* @copyright
|
7
|
* (C) 2007-2015 EDIT
|
8
|
* European Distributed Institute of Taxonomy
|
9
|
* http://www.e-taxonomy.eu
|
10
|
*
|
11
|
* The contents of this module are subject to the Mozilla
|
12
|
* Public License Version 1.1.
|
13
|
* @see http://www.mozilla.org/MPL/MPL-1.1.html
|
14
|
*
|
15
|
* @author
|
16
|
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
|
17
|
*/
|
18
|
|
19
|
/**
|
20
|
* @defgroup compose Compose functions
|
21
|
* @{
|
22
|
* Functions which are composing Drupal render arays
|
23
|
*
|
24
|
* The cdm_dataportal module needs to compose rather complex render arrays from
|
25
|
* the data returned by the CDM REST service. The compose functions are
|
26
|
* responsible for creating the render arrays.
|
27
|
*
|
28
|
* All these functions are also implementations of the compose_hook()
|
29
|
* which is used in the proxy_content() function.
|
30
|
* @}
|
31
|
*/
|
32
|
|
33
|
|
34
|
/**
|
35
|
* Provides the name render template to be used within the page elements identified the the $renderPath.
|
36
|
*
|
37
|
* The render templates arrays contains one or more name render templates to be used within the page elements identified the the
|
38
|
* renderPath. The renderPath is the key of the subelements whereas the value is the name render template.
|
39
|
*
|
40
|
* The render paths used for a cdm_dataportal page can be visualized by supplying the HTTP query parameter RENDER_PATH=1.
|
41
|
*
|
42
|
* It will be tried to find the best matching default RenderTemplate by stripping the dot separated render path
|
43
|
* element by element. If no matching template is found the DEFAULT will be used:
|
44
|
*
|
45
|
* - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
|
46
|
* - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
|
47
|
* - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
|
48
|
*
|
49
|
* A single render template can be used for multiple render paths. In this case the according key of the render templates
|
50
|
* array element should be the list of these render paths concatenated by ONLY a comma character without any whitespace.
|
51
|
*
|
52
|
* A render template is an associative array. The keys of this array are referring to the keys as defined in the part
|
53
|
* definitions array.
|
54
|
* @see get_partDefinition($taxonNameType) for more information
|
55
|
*
|
56
|
* The value of the render template element must be set to TRUE in order to let this part being rendered.
|
57
|
* The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
|
58
|
* element: array('#uri' => TRUE). The value of the #uri element will be replaced by the according
|
59
|
* links if the parameters $nameLink or $refenceLink are set.
|
60
|
*
|
61
|
* @param string $render_path
|
62
|
* The render path can consist of multiple dot separated elements
|
63
|
* @see RenderHints::getRenderPath()
|
64
|
* @param string $nameLink
|
65
|
* The link path or URL to be used for name parts if a link is forseen in the template
|
66
|
* matching the given $renderPath.
|
67
|
* @param string $referenceLink
|
68
|
* The link path ot URL to be used for nomenclatural reference parts if a link is forseen
|
69
|
* in the template matching the given $renderPath.
|
70
|
* @return array
|
71
|
* An associative array, the render template
|
72
|
*/
|
73
|
function get_nameRenderTemplate($render_path, $nameLink = NULL, $referenceLink = NULL) {
|
74
|
|
75
|
static $split_render_templates = NULL;
|
76
|
|
77
|
if($split_render_templates == NULL) {
|
78
|
$render_templates = variable_get(NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES, NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES_DEFAULT);
|
79
|
// needs to be converted to an array
|
80
|
$render_templates = (object_to_array($render_templates));
|
81
|
|
82
|
// separate render templates which are combined with a comma
|
83
|
$split_render_templates = array();
|
84
|
foreach($render_templates as $key => $template){
|
85
|
if(strpos($key, ',')){
|
86
|
foreach(explode(',', $key) as $path){
|
87
|
$split_render_templates[$path] = $template;
|
88
|
}
|
89
|
} else {
|
90
|
$split_render_templates[$key] = $template;
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
|
95
|
// get the base element of the renderPath
|
96
|
if (($separatorPos = strpos($render_path, '.')) > 0) {
|
97
|
$renderPath_base = substr($render_path, 0, $separatorPos);
|
98
|
} else {
|
99
|
$renderPath_base = $render_path;
|
100
|
}
|
101
|
|
102
|
$template = NULL;
|
103
|
// 1. try to find a template using the render path base element
|
104
|
if(array_key_exists($renderPath_base, $split_render_templates)){
|
105
|
$template = (array)$split_render_templates[$renderPath_base];
|
106
|
}
|
107
|
|
108
|
// 2. Find best matching default RenderTemplate
|
109
|
// by stripping the dot separated render path element by element
|
110
|
// if no matching template is found the DEFAULT will be used.
|
111
|
while (!is_array($template) && strlen($render_path) > 0) {
|
112
|
foreach ($split_render_templates as $path => $t) {
|
113
|
if ($path == $render_path) {
|
114
|
$template = $t;
|
115
|
break;
|
116
|
}
|
117
|
}
|
118
|
// shorten by one element
|
119
|
$render_path = substr($render_path, strrpos($render_path, '.') + 1, strlen($render_path));
|
120
|
}
|
121
|
|
122
|
|
123
|
// 3. Otherwise get default RenderTemplate from theme.
|
124
|
if (!is_array($template)) {
|
125
|
$template = $split_render_templates['#DEFAULT'];
|
126
|
}
|
127
|
|
128
|
// --- set the link uris to the according template fields if they exist
|
129
|
if(isset($template['nameAuthorPart']) && isset($template['nameAuthorPart']['#uri'])) {
|
130
|
if ($nameLink) {
|
131
|
$template['nameAuthorPart']['#uri'] = $nameLink;
|
132
|
}
|
133
|
else {
|
134
|
unset($template['nameAuthorPart']['#uri']);
|
135
|
}
|
136
|
}
|
137
|
|
138
|
if ($nameLink && isset($template['namePart']['#uri'])) {
|
139
|
$template['namePart']['#uri'] = $nameLink;
|
140
|
}
|
141
|
else {
|
142
|
unset($template['namePart']['#uri']);
|
143
|
}
|
144
|
|
145
|
if ($referenceLink && isset($template['referencePart']['#uri'])) {
|
146
|
$template['referencePart']['#uri'] = $referenceLink;
|
147
|
}
|
148
|
else {
|
149
|
unset($template['referencePart']['#uri']);
|
150
|
}
|
151
|
|
152
|
return $template;
|
153
|
}
|
154
|
|
155
|
/**
|
156
|
* The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
|
157
|
*
|
158
|
* A full taxon name plus additional information can consist of the following elements:
|
159
|
*
|
160
|
* - name: the taxon name inclugin rank nbut without author
|
161
|
* - authorTeam: The authors of a reference, also used in taxon names
|
162
|
* - authors: The authors of a reference, also used in taxon names
|
163
|
* - reference: the nomenclatural reference,
|
164
|
* - microreference: Volume, page number etc.
|
165
|
* - status: The nomenclatural status of a name
|
166
|
* - description: name descriptions like protologues etc ...
|
167
|
*
|
168
|
* These elements are combined in the part definitions array to from the specific parts to be rendered.
|
169
|
* Usually the following parts are formed:
|
170
|
*
|
171
|
* The name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example here:
|
172
|
* - namePart: the name and rank (in example: "Lapsana communis")
|
173
|
* - authorshipPart: the author (in example: "L.")
|
174
|
* - nameAuthorPart: the combination of name and author part (in example: "Lapsana communis L.").
|
175
|
* This is useful for zoological names where the authorshipPart belongs to the name and both should
|
176
|
* be combined when a link to the taxon is rendered.
|
177
|
* - referencePart: the nomencaltural reference (in example: "Sp. Pl. 1753")
|
178
|
* - microreferencePart: usually the page number (in example ": 811.")
|
179
|
* - statusPart: the nomenclatorical status
|
180
|
* - descriptionPart:
|
181
|
*
|
182
|
* Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
|
183
|
* specific parts part definitions:
|
184
|
*
|
185
|
* - BotanicalName
|
186
|
* - ZoologicalName
|
187
|
* - #DEFAULT: covers ViralNames and general NonViralNames
|
188
|
*
|
189
|
* An example:
|
190
|
* @code
|
191
|
* array(
|
192
|
* 'ZoologicalName' => array(
|
193
|
* 'namePart' => array('name' => TRUE),
|
194
|
* 'referencePart' => array('authorTeam' => TRUE),
|
195
|
* 'microreferencePart' => array('microreference' => TRUE),
|
196
|
* 'statusPart' => array('status' => TRUE),
|
197
|
* 'descriptionPart' => array('description' => TRUE),
|
198
|
* ),
|
199
|
* 'BotanicalName' => array(
|
200
|
* 'namePart' => array(
|
201
|
* 'name' => TRUE,
|
202
|
* 'authors' => TRUE,
|
203
|
* ),
|
204
|
* 'referencePart' => array(
|
205
|
* 'reference' => TRUE,
|
206
|
* 'microreference' => TRUE,
|
207
|
* ),
|
208
|
* 'statusPart' => array('status' => TRUE),
|
209
|
* 'descriptionPart' => array('description' => TRUE),
|
210
|
* ),
|
211
|
* );
|
212
|
* @endcode
|
213
|
*
|
214
|
* @param object $taxonNameType
|
215
|
* A cdm TaxonNameType entity
|
216
|
*
|
217
|
*/
|
218
|
function get_partDefinition($taxonNameType) {
|
219
|
|
220
|
static $part_definitions = null;
|
221
|
if (!isset($part_definitions)) {
|
222
|
$part_definitions = object_to_array(variable_get(NameRenderConfiguration::CDM_PART_DEFINITIONS, NameRenderConfiguration::CDM_PART_DEFINITIONS_DEFAULT));
|
223
|
}
|
224
|
|
225
|
$dtype = nameTypeToDTYPE($taxonNameType);
|
226
|
if (array_key_exists($taxonNameType, $part_definitions)) {
|
227
|
return $part_definitions[$taxonNameType];
|
228
|
} else if (array_key_exists($dtype, $part_definitions)) {
|
229
|
return $part_definitions[$dtype];
|
230
|
} else {
|
231
|
return $part_definitions['#DEFAULT']; // covers ViralNames and general NonViralNames
|
232
|
}
|
233
|
|
234
|
}
|
235
|
|
236
|
|
237
|
/**
|
238
|
* Renders the markup for a CDM TaxonName instance.
|
239
|
*
|
240
|
* The layout of the name representation is configured by the
|
241
|
* part_definitions and render_templates (see get_partDefinition() and
|
242
|
* get_nameRenderTemplate())
|
243
|
*
|
244
|
* @param $taxon_name_or_taxon_base
|
245
|
* A cdm TaxonBase or TaxonName entity
|
246
|
* @param $name_link
|
247
|
* URI to the taxon, the path provided by path_to_taxon() must be processed
|
248
|
* by url() before passing to this method
|
249
|
* @param $reference_link
|
250
|
* URI to the reference, the path provided by path_to_reference() must be
|
251
|
* processed by url() before passing to this method
|
252
|
* @param bool $show_taxon_name_annotations
|
253
|
* Enable the display of footnotes for annotations on the taxon and name
|
254
|
* (default: true)
|
255
|
* @param bool $is_type_designation
|
256
|
* To indicate that the supplied taxon name is a name type designation.
|
257
|
* (default: false)
|
258
|
* @param array $skip_render_template_parts
|
259
|
* The render template elements matching these part names will bes skipped.
|
260
|
* This parameter should only be used in rare cases like for suppressing
|
261
|
* the sec reference of synonyms. Normally the configuration of the
|
262
|
* name appearance should only be done via the render templates themselves. (default: [])
|
263
|
* @param bool $is_invalid
|
264
|
* Indicates that this taxon is invalid. In this case the name part will be shown in double quotes.
|
265
|
* This is useful when rendering taxon relation ships. (default: false)
|
266
|
*
|
267
|
* @return string
|
268
|
* The markup for a taxon name.
|
269
|
*/
|
270
|
function render_taxon_or_name($taxon_name_or_taxon_base, $name_link = NULL, $reference_link = NULL,
|
271
|
$show_taxon_name_annotations = true, $is_type_designation = false, $skip_render_template_parts = [], $is_invalid = false) {
|
272
|
|
273
|
$is_doubtful = false;
|
274
|
$taxon_base = null;
|
275
|
$nom_status_fkey = null; // FootNoteKey
|
276
|
if($taxon_name_or_taxon_base->class == 'Taxon' || $taxon_name_or_taxon_base->class == 'Synonym'){
|
277
|
$taxon_base = $taxon_name_or_taxon_base;
|
278
|
if(isset($taxon_name_or_taxon_base->name)){
|
279
|
$taxon_name = $taxon_name_or_taxon_base->name;
|
280
|
} else {
|
281
|
$taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', array($taxon_name_or_taxon_base->uuid));
|
282
|
}
|
283
|
$is_doubtful = $taxon_name_or_taxon_base->doubtful;
|
284
|
// use the TaxonBase.tagged_title so we have the secRef
|
285
|
$tagged_title = $taxon_name_or_taxon_base->taggedTitle;
|
286
|
} else {
|
287
|
// assuming this is a TaxonName
|
288
|
$taxon_name = $taxon_name_or_taxon_base;
|
289
|
if(isset($taxon_name->taggedFullTitle)){
|
290
|
$tagged_title = $taxon_name_or_taxon_base->taggedFullTitle;
|
291
|
} else {
|
292
|
$tagged_title = $taxon_name_or_taxon_base->taggedName;
|
293
|
}
|
294
|
}
|
295
|
|
296
|
|
297
|
$renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $name_link, $reference_link);
|
298
|
$partDefinition = get_partDefinition($taxon_name->nameType);
|
299
|
|
300
|
// Apply definitions to template.
|
301
|
foreach ($renderTemplate as $part => $uri) {
|
302
|
|
303
|
if (isset($partDefinition[$part])) {
|
304
|
$renderTemplate[$part] = $partDefinition[$part];
|
305
|
}
|
306
|
if (is_array($uri) && isset($uri['#uri'])) {
|
307
|
$renderTemplate[$part]['#uri'] = $uri['#uri'];
|
308
|
}
|
309
|
}
|
310
|
|
311
|
foreach($skip_render_template_parts as $part){
|
312
|
unset($renderTemplate[$part]);
|
313
|
}
|
314
|
|
315
|
$secref_tagged_text = tagged_text_extract_reference_and_detail($tagged_title);
|
316
|
// taxon names will have the nomenclatural reference in the tagged full title:
|
317
|
$nomref_tagged_text = tagged_text_extract_reference($tagged_title);
|
318
|
$nom_status_tagged_text = tagged_text_extract_nomstatus($tagged_title);
|
319
|
$appended_phrase_tagged_text = array(); // this is filled later
|
320
|
|
321
|
normalize_tagged_text($tagged_title);
|
322
|
|
323
|
$is_valid_tagged_title =
|
324
|
isset($tagged_title)
|
325
|
&& is_array($tagged_title)
|
326
|
&& isset($tagged_title[0]->text)
|
327
|
&& is_string($tagged_title[0]->text)
|
328
|
&& $tagged_title[0]->text != ''
|
329
|
&& isset($tagged_title[0]->type);
|
330
|
$lastAuthorElementString = FALSE;
|
331
|
|
332
|
$name_encasement = $is_invalid ? '"' : '';
|
333
|
$doubtful_marker = $is_doubtful ? '? ' : ''; //   = NARROW NO-BREAK SPACE
|
334
|
$doubtful_marker_markup = '';
|
335
|
|
336
|
if($doubtful_marker){
|
337
|
$doubtful_marker_markup = '<span class="doubtful">' . $doubtful_marker . '</span>';
|
338
|
if($tagged_title[0]->text == '?' ){
|
339
|
// remove the first tagged text element
|
340
|
unset($tagged_title[0]);
|
341
|
}
|
342
|
}
|
343
|
|
344
|
// split off all appendedPhrase item from the end of the array (usually there only should be one)
|
345
|
while($tagged_title[count($tagged_title)-1]->type == "appendedPhrase"){
|
346
|
$appended_phrase_tagged_text[] = array_pop($tagged_title);
|
347
|
}
|
348
|
|
349
|
// Got to use second entry as first one, see ToDo comment below ...
|
350
|
if ($is_valid_tagged_title) {
|
351
|
|
352
|
$taggedName = $tagged_title;
|
353
|
$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
|
354
|
$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
|
355
|
|
356
|
|
357
|
if (!(($hasNamePart_with_Authors) || ($hasNameAuthorPart_with_Authors))) {
|
358
|
// Find author and split off from name.
|
359
|
// TODO expecting to find the author as the last element.
|
360
|
/*
|
361
|
if($taggedName[count($taggedName)- 1]->type == 'authors'){
|
362
|
$authorTeam = $taggedName[count($taggedName)- 1]->text;
|
363
|
unset($taggedName[count($taggedName)- 1]);
|
364
|
}
|
365
|
*/
|
366
|
|
367
|
// Remove all authors.
|
368
|
$taggedNameNew = array();
|
369
|
foreach ($taggedName as $element) {
|
370
|
if ($element->type != 'authors') {
|
371
|
$taggedNameNew[] = $element;
|
372
|
}
|
373
|
else {
|
374
|
$lastAuthorElementString = $element->text;
|
375
|
}
|
376
|
}
|
377
|
$taggedName = $taggedNameNew;
|
378
|
unset($taggedNameNew);
|
379
|
}
|
380
|
$name = '<span class="' . $taxon_name->class . '">' . $doubtful_marker_markup . $name_encasement . cdm_tagged_text_to_markup($taggedName) . $name_encasement . '</span>';
|
381
|
}
|
382
|
else {
|
383
|
// use titleCache instead
|
384
|
$name = '<span class="' . $taxon_name->class . '_titleCache">' . $doubtful_marker_markup . $name_encasement . $taxon_name->titleCache . $name_encasement . '</span>';
|
385
|
}
|
386
|
|
387
|
|
388
|
if(isset($appended_phrase_tagged_text[0])){
|
389
|
$name .= ' <span class="appended-phrase">'. cdm_tagged_text_to_markup($appended_phrase_tagged_text) . '</span>';
|
390
|
}
|
391
|
|
392
|
// Fill name into $renderTemplate.
|
393
|
array_setr('name', $name , $renderTemplate);
|
394
|
|
395
|
// Fill with authorTeam.
|
396
|
/*
|
397
|
if($authorTeam){
|
398
|
$authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
|
399
|
array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
|
400
|
}
|
401
|
*/
|
402
|
|
403
|
// Fill with reference.
|
404
|
if (isset($renderTemplate['referencePart']) && !$is_type_designation) {
|
405
|
|
406
|
$registrations = cdm_ws_get(CDM_WS_NAME, array($taxon_name->uuid, "registrations"));
|
407
|
$registration_markup = render_registrations($registrations);
|
408
|
|
409
|
// default separator
|
410
|
$separator = '';
|
411
|
|
412
|
// [Eckhard]:"Komma nach dem Taxonnamen ist grundsätzlich falsch,
|
413
|
// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
|
414
|
if (isset($renderTemplate['referencePart']['reference']) && isset($taxon_name->nomenclaturalSource)) {
|
415
|
$microreference = $taxon_name->nomenclaturalSource->citationMicroReference;
|
416
|
if(count($nomref_tagged_text) == 0 && isset($taxon_name->nomenclaturalSource->citation)){
|
417
|
// drupal message for debugging of #9599
|
418
|
// drupal_set_message("reference/$0/nomenclaturalCitation' must no longer be used (type: "
|
419
|
// . $taxon_name_or_taxon_base->class . (isset($taxon_name_or_taxon_base->type) ? " - " +$taxon_name_or_taxon_base->type : "" . ")"), "error");
|
420
|
$citation = cdm_ws_getNomenclaturalReference($taxon_name->nomenclaturalSource->citation->uuid, $microreference);
|
421
|
// Find preceding element of the reference.
|
422
|
$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
|
423
|
if (str_beginsWith($citation, ", in")) {
|
424
|
$citation = substr($citation, 2);
|
425
|
$separator = ' ';
|
426
|
}
|
427
|
elseif (!str_beginsWith($citation, "in") && $precedingKey == 'authors') {
|
428
|
$separator = ', ';
|
429
|
} else {
|
430
|
$separator = ' ';
|
431
|
}
|
432
|
$referenceArray['#separator'] = $separator;
|
433
|
$referenceArray['#html'] = '<span class="reference">' . $citation . '</span>' . $registration_markup;
|
434
|
} else {
|
435
|
// this is the case for taxon names
|
436
|
$referenceArray['#html'] = cdm_tagged_text_to_markup($nomref_tagged_text);
|
437
|
}
|
438
|
|
439
|
array_setr('reference', $referenceArray, $renderTemplate);
|
440
|
}
|
441
|
|
442
|
// If authors have been removed from the name part the last named authorteam
|
443
|
// should be added to the reference citation, otherwise, keep the separator
|
444
|
// out of the reference.
|
445
|
if (isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString) {
|
446
|
// If the nomenclaturalReference citation is not included in the
|
447
|
// reference part but display of the microreference
|
448
|
// is wanted, append the microreference to the authorTeam.
|
449
|
$citation = '';
|
450
|
if (!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])) {
|
451
|
$separator = ": ";
|
452
|
$citation = $taxon_name->nomenclaturalMicroReference;
|
453
|
}
|
454
|
$referenceArray['#html'] = ' <span class="reference">' . $lastAuthorElementString . $separator . $citation . '</span>';
|
455
|
array_setr('authors', $referenceArray, $renderTemplate);
|
456
|
}
|
457
|
}
|
458
|
|
459
|
$is_reference_year = false;
|
460
|
if (isset($renderTemplate['referenceYearPart']['reference.year'])) {
|
461
|
if(isset($taxon_name->nomenclaturalSource->citation->datePublished)){
|
462
|
$referenceArray['#html'] = ' <span class="reference">' . timePeriodToString($taxon_name->nomenclaturalSource->citation->datePublished) . '</span>';
|
463
|
array_setr('reference.year', $referenceArray, $renderTemplate);
|
464
|
$is_reference_year = true;
|
465
|
}
|
466
|
}
|
467
|
|
468
|
// Fill with status.
|
469
|
if(isset($renderTemplate['statusPart']['status'])){
|
470
|
if (isset($nom_status_tagged_text[0])) {
|
471
|
$tt_to_markup_options = array('html' => false);
|
472
|
foreach ($nom_status_tagged_text as &$tt){
|
473
|
if($tt->type == 'nomStatus'&& isset($tt->entityReference)) {
|
474
|
$nom_status = cdm_ws_get(CDM_WS_NOMENCLATURALSTATUS, array($tt->entityReference->uuid));
|
475
|
$nom_status_fkey = handle_nomenclatural_status_as_footnote($nom_status);
|
476
|
$tt_to_markup_options['html'] = true;
|
477
|
}
|
478
|
}
|
479
|
array_setr(
|
480
|
'status',
|
481
|
'<span class="nomenclatural_status">' . cdm_tagged_text_to_markup($nom_status_tagged_text, array('postSeparator'), 'span', $tt_to_markup_options) . '</span>',
|
482
|
$renderTemplate);
|
483
|
}
|
484
|
}
|
485
|
|
486
|
if (isset($renderTemplate['secReferencePart'])){
|
487
|
if(isset($secref_tagged_text[1])){
|
488
|
$post_separator_markup = $is_reference_year ? '.': '';
|
489
|
if(isset($nom_status_tagged_text[count($nom_status_tagged_text) - 1]) && ($nom_status_tagged_text[count($nom_status_tagged_text) - 1]->type == 'postSeparator')){
|
490
|
$post_separator_markup = cdm_tagged_text_to_markup(array($nom_status_tagged_text[count($nom_status_tagged_text) - 1 ]));
|
491
|
};
|
492
|
array_setr('secReference',
|
493
|
$post_separator_markup
|
494
|
. ' <span class="sec_reference">'
|
495
|
. join('', cdm_tagged_text_values($secref_tagged_text))
|
496
|
. '</span>', $renderTemplate);
|
497
|
}
|
498
|
}
|
499
|
|
500
|
// Fill with protologues etc...
|
501
|
$protologue_links = [];
|
502
|
if (array_setr('description', TRUE, $renderTemplate)) {
|
503
|
$external_links = cdm_ws_get(CDM_WS_NAME_PROTOLOGUE_LINKS, $taxon_name->uuid);
|
504
|
if($external_links){
|
505
|
foreach ($external_links as $link) {
|
506
|
if (!empty($link->uri)) {
|
507
|
// for the link see also cdm_external_uri()
|
508
|
$protologue_links[] = l(font_awesome_icon_markup('fa-book'), $link->uri, ['html' => true]);
|
509
|
}
|
510
|
}
|
511
|
}
|
512
|
|
513
|
// ---------------
|
514
|
|
515
|
$additional_pub_markup = '';
|
516
|
$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxon_name->uuid);
|
517
|
if($descriptions) {
|
518
|
foreach ($descriptions as $description) {
|
519
|
if (!empty($description)) {
|
520
|
$additional_citations = [];
|
521
|
$additional_data = [];
|
522
|
foreach ($description->elements as $description_element) {
|
523
|
if (isset($description_element->multilanguageText_L10n) && $description_element->multilanguageText_L10n->text) {
|
524
|
RenderHints::setAnnotationsAndSourceConfig(synonymy_annotations_and_source_config());
|
525
|
$annotations_and_sources = handle_annotations_and_sources($description_element);
|
526
|
// synonymy_annotations_and_source_config() has 'sources_as_content' => FALSE, so no need to handle inline sources here
|
527
|
$element_media = cdm_description_element_media(
|
528
|
$description_element,
|
529
|
[
|
530
|
'application/pdf',
|
531
|
'image/png',
|
532
|
'image/jpeg',
|
533
|
'image/gif',
|
534
|
'text/html',
|
535
|
]
|
536
|
);
|
537
|
if (isset($description_element->feature) && $description_element->feature->uuid == UUID_ADDITIONAL_PUBLICATION) {
|
538
|
$additional_citations[] = ' [& ' . trim($description_element->multilanguageText_L10n->text) . $element_media . $annotations_and_sources->footNoteKeysMarkup() .']';
|
539
|
} else {
|
540
|
$additional_data[] = ' [' . trim($description_element->multilanguageText_L10n->text) . $element_media . $annotations_and_sources->footNoteKeysMarkup(). ']';
|
541
|
}
|
542
|
}
|
543
|
}
|
544
|
// merge
|
545
|
$additional_citations = array_merge($additional_citations, $additional_data);
|
546
|
$additional_pub_markup .= join(',', $additional_citations);
|
547
|
}
|
548
|
}
|
549
|
}
|
550
|
if($additional_pub_markup){
|
551
|
$additional_pub_markup = ' ' . $additional_pub_markup . '. '; // surround with space etc.
|
552
|
}
|
553
|
array_setr('description', $additional_pub_markup . join(', ', $protologue_links), $renderTemplate);
|
554
|
array_replace_keyr('description', 'protologue', $renderTemplate); // in preparation for #9319
|
555
|
}
|
556
|
|
557
|
// Render.
|
558
|
$out = '';
|
559
|
if(isset($_REQUEST['RENDER_PATH'])){
|
560
|
// developer option to show the render path with each taxon name
|
561
|
$out .= '<span class="render-path">' . RenderHints::getRenderPath() . '</span>';
|
562
|
}
|
563
|
$out .= '<span class="' . html_class_attribute_ref($taxon_name_or_taxon_base)
|
564
|
// . '" data-cdm-ref="/name/' . $taxon_name->uuid . '" data-cdm-render-path="' . RenderHints::getRenderPath() .'">';
|
565
|
. '" data-cdm-ref="/name/' . $taxon_name->uuid . '">';
|
566
|
foreach ($renderTemplate as $partName => $part) {
|
567
|
$separator = '';
|
568
|
$partHtml = '';
|
569
|
$uri = FALSE;
|
570
|
if (!is_array($part)) {
|
571
|
continue;
|
572
|
}
|
573
|
if (isset($part['#uri']) && is_string($part['#uri'])) {
|
574
|
$uri = $part['#uri'];
|
575
|
unset($part['#uri']);
|
576
|
}
|
577
|
foreach ($part as $part => $content) {
|
578
|
$html = '';
|
579
|
if (is_array($content)) {
|
580
|
$html = $content['#html'];
|
581
|
if(isset($content['#separator'])) {
|
582
|
$separator = $content['#separator'];
|
583
|
}
|
584
|
}
|
585
|
elseif (is_string($content)) {
|
586
|
$html = $content;
|
587
|
}
|
588
|
if($html){ // skip empty elements
|
589
|
$partHtml .= '<span class="' . $part . '">' . $html . '</span>';
|
590
|
}
|
591
|
}
|
592
|
if ($uri) {
|
593
|
// cannot use l() here since the #uri already should have been processed through uri() at this point
|
594
|
$out .= $separator . '<a href="' . $uri . '" class="' . $partName . '">' . $partHtml . '</a>';
|
595
|
|
596
|
}
|
597
|
else {
|
598
|
$out .= $separator . $partHtml;
|
599
|
}
|
600
|
}
|
601
|
$out .= '</span>';
|
602
|
|
603
|
$annotations_and_sources = new AnnotationsAndSources();
|
604
|
if($nom_status_fkey){
|
605
|
// the nomenclatural status footnote key refers to the source citation
|
606
|
$annotations_and_sources->addFootNoteKey($nom_status_fkey);
|
607
|
}
|
608
|
if ($show_taxon_name_annotations) {
|
609
|
if($taxon_base){
|
610
|
$annotations_and_sources = handle_annotations_and_sources($taxon_base,
|
611
|
null, null, $annotations_and_sources);
|
612
|
}
|
613
|
$annotations_and_sources = handle_annotations_and_sources($taxon_name,
|
614
|
null, null, $annotations_and_sources);
|
615
|
}
|
616
|
$out .= $annotations_and_sources->footNoteKeysMarkup();
|
617
|
return $out;
|
618
|
}
|
619
|
|
620
|
|
621
|
|
622
|
/**
|
623
|
* Composes information for a registration from a dto object.
|
624
|
*
|
625
|
* Registrations which are not yet published are suppressed.
|
626
|
*
|
627
|
* @param $registration_dto
|
628
|
* @param $with_citation
|
629
|
* Whether to show the citation.
|
630
|
*
|
631
|
* @return array
|
632
|
* A drupal render array with the elements:
|
633
|
* - 'name'
|
634
|
* - 'name-relations'
|
635
|
* - 'specimen_type_designations'
|
636
|
* - 'name_type_designations'
|
637
|
* - 'citation'
|
638
|
* - 'registration_date_and_institute'
|
639
|
* @ingroup compose
|
640
|
*/
|
641
|
function compose_registration_dto_full($registration_dto, $with_citation = true)
|
642
|
{
|
643
|
$render_array = array(
|
644
|
'#prefix' => '<div class="registration">',
|
645
|
'#suffix' => '</div>'
|
646
|
);
|
647
|
|
648
|
if(!(isset($registration_dto->identifier) && $registration_dto->status == 'PUBLISHED')){
|
649
|
return $render_array;
|
650
|
}
|
651
|
|
652
|
$render_array['sub_headline'] = markup_to_render_array(join(", ", registration_types($registration_dto)),-10, '<h3 class="registration_type">' . t('Event: '), '</h3>' );
|
653
|
$render_array['nomenclatural_act'] = array(
|
654
|
'#weight' => 0,
|
655
|
'#prefix' => '<div class="nomenclatural_act">',
|
656
|
|
657
|
'#suffix' => '</div>'
|
658
|
);
|
659
|
|
660
|
$typified_name = null;
|
661
|
|
662
|
// Nomenclatural act block element
|
663
|
$last_footnote_listkey = RenderHints::setFootnoteListKey("nomenclatural_act");
|
664
|
// name
|
665
|
$name_relations = null;
|
666
|
if(isset($registration_dto->nameRef) && $registration_dto->nameRef){
|
667
|
$name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->nameRef->uuid);
|
668
|
cdm_load_tagged_full_title($name);
|
669
|
$render_array['nomenclatural_act']['published_name'] = markup_to_render_array('<div class="published-name">' . render_taxon_or_name($name, url(path_to_name($name->uuid))) . '</div>', 0);
|
670
|
$name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
|
671
|
// need to create the name relationships later, so that the foot notes are in correct order, see section // name relations
|
672
|
} else {
|
673
|
// in this case the registration must have a
|
674
|
// typified name will be rendered later
|
675
|
$typified_name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->typifiedNameRef->uuid);
|
676
|
|
677
|
}
|
678
|
|
679
|
// typedesignation in detail
|
680
|
if(is_object($registration_dto->orderedTypeDesignationWorkingSets)) {
|
681
|
$field_unit_uuids = array();
|
682
|
$specimen_type_designation_refs = array();
|
683
|
$name_type_designation_refs = array();
|
684
|
foreach ((array)$registration_dto->orderedTypeDesignationWorkingSets as $workingset_ref => $obj) {
|
685
|
$tokens = explode("#", $workingset_ref);
|
686
|
$types_in_fieldunit = get_object_vars($obj); // convert into associative array
|
687
|
|
688
|
if ($tokens[0] == 'NameTypeDesignation') {
|
689
|
foreach ($types_in_fieldunit as $type_status => $entity_reference_list) {
|
690
|
if(!isset($name_type_designation_refs[$type_status])){
|
691
|
$name_type_designation_refs[$type_status] = $entity_reference_list;
|
692
|
} else {
|
693
|
$specimen_type_designation_refs[$type_status] = array_merge($specimen_type_designation_refs[$type_status], $entity_reference_list);
|
694
|
}
|
695
|
}
|
696
|
} else if ($tokens[0] == 'FieldUnit'){
|
697
|
$field_unit_uuids[] = $tokens[1];
|
698
|
foreach ($types_in_fieldunit as $type_status => $entity_reference_list) {
|
699
|
if(!isset($specimen_type_designation_refs[$type_status])){
|
700
|
$specimen_type_designation_refs[$type_status] = $entity_reference_list;
|
701
|
} else {
|
702
|
array_push($specimen_type_designation_refs[$type_status], $entity_reference_list);
|
703
|
}
|
704
|
}
|
705
|
} else {
|
706
|
drupal_set_message("Unimplemented type: " . $tokens[0], 'error');
|
707
|
}
|
708
|
}
|
709
|
// type designations which are in this nomenclatural act.
|
710
|
if (count($name_type_designation_refs) > 0) {
|
711
|
$render_array['nomenclatural_act']['name_type_designations'] = compose_name_type_designations($name_type_designation_refs);
|
712
|
$render_array['nomenclatural_act']['name_type_designations']['#prefix'] = '<p class="name_type_designations">';
|
713
|
$render_array['nomenclatural_act']['name_type_designations']['#suffix'] = '</p>';
|
714
|
$render_array['nomenclatural_act']['name_type_designations']['#weight'] = 20;
|
715
|
}
|
716
|
if (count($field_unit_uuids) > 0) {
|
717
|
$specimen_type_designations_array = compose_specimen_type_designations($specimen_type_designation_refs, true);
|
718
|
$render_array['nomenclatural_act']['specimen_type_designations'] = $specimen_type_designations_array['type_designations'];
|
719
|
$render_array['map'] = $specimen_type_designations_array['map'];
|
720
|
$render_array['map']['#weight'] = $render_array['nomenclatural_act']['#weight'] + 20;
|
721
|
}
|
722
|
}
|
723
|
|
724
|
// name relations
|
725
|
if($name_relations){
|
726
|
$render_array['nomenclatural_act']['name_relations'] = compose_name_relationships_list($name_relations, $registration_dto->nameRef->uuid, null);
|
727
|
$render_array['nomenclatural_act']['name_relations']['#weight'] = 10;
|
728
|
}
|
729
|
|
730
|
// citation
|
731
|
if ($with_citation) {
|
732
|
$render_array['citation'] = markup_to_render_array(
|
733
|
"<div class=\"citation nomenclatural_act_citation" . html_class_attribute_ref(new TypedEntityReference("Reference", $registration_dto->citationUuid)) . "\">"
|
734
|
. "<span class=\"label\">published in: </span>"
|
735
|
. $registration_dto->bibliographicInRefCitationString
|
736
|
. l(custom_icon_font_markup('icon-interal-link-alt-solid', array('class' => array('superscript'))), path_to_reference($registration_dto->citationUuid), array('html' => true))
|
737
|
. "</div>",
|
738
|
$render_array['nomenclatural_act']['#weight'] + 10 );
|
739
|
}
|
740
|
|
741
|
$render_array['nomenclatural_act']['footnotes'] = markup_to_render_array(render_footnotes(),100);
|
742
|
|
743
|
// END of nomenclatural act block
|
744
|
RenderHints::setFootnoteListKey($last_footnote_listkey );
|
745
|
|
746
|
if($typified_name){
|
747
|
$render_array['typified_name'] = markup_to_render_array('<p class="typified-name">for ' . render_taxon_or_name($typified_name, url(path_to_name($typified_name->uuid))) . '</p>', 40);
|
748
|
}
|
749
|
|
750
|
// registration date and office
|
751
|
$registration_date_insitute_markup = render_registration_date_and_institute($registration_dto);
|
752
|
if($registration_date_insitute_markup){
|
753
|
$render_array['registration_date_and_institute'] = markup_to_render_array(
|
754
|
$registration_date_insitute_markup . '</p>',
|
755
|
100);
|
756
|
}
|
757
|
|
758
|
$render_array['page_footnotes'] = markup_to_render_array(render_footnotes(), 110);
|
759
|
|
760
|
return $render_array;
|
761
|
}
|
762
|
|
763
|
|
764
|
/**
|
765
|
* Composes a compact representation for a registrationDTO object
|
766
|
*
|
767
|
* Registrations which are not yet published are suppressed.
|
768
|
*
|
769
|
* @param $registration_dto
|
770
|
* @param $style string
|
771
|
* The style of how to compose the 'identifier' and 'registration_date_and_institute' part with the summary
|
772
|
* - 'citation': Similar to the appearance of nomenclatural acts in print media
|
773
|
* - 'list-item' : style suitable for result lists etc
|
774
|
*
|
775
|
* @return array
|
776
|
* A drupal render array with the elements:
|
777
|
* - 'registration-metadata' when $style == 'list-item'
|
778
|
* - 'summary'
|
779
|
* @ingroup compose
|
780
|
*/
|
781
|
function compose_registration_dto_compact($registration_dto, $style = 'citation', $tag_enclosing_summary = 'p')
|
782
|
{
|
783
|
$render_array = array();
|
784
|
$media_link_map = array();
|
785
|
|
786
|
if(!(isset($registration_dto->identifier) && $registration_dto->status == 'PUBLISHED')){
|
787
|
return $render_array;
|
788
|
}
|
789
|
|
790
|
$registration_date_institute_markup = render_registration_date_and_institute($registration_dto, 'span');
|
791
|
$identifier_markup = render_link_to_registration($registration_dto->identifier);
|
792
|
|
793
|
$tagged_text_options = array();
|
794
|
if(isset($registration_dto->nameRef)){
|
795
|
$tagged_text_options[] = array(
|
796
|
'filter-type' => 'name',
|
797
|
'prefix' => '<span class="registered_name">',
|
798
|
'suffix' => '</span>',
|
799
|
);
|
800
|
} else {
|
801
|
$tagged_text_options[] = array(
|
802
|
'filter-type' => 'name',
|
803
|
'prefix' => '<span class="referenced_typified_name">',
|
804
|
'suffix' => '</span>',
|
805
|
);
|
806
|
}
|
807
|
cdm_tagged_text_add_options($registration_dto->summaryTaggedText, $tagged_text_options);
|
808
|
$tagged_text_cropped = tagged_text_crop_at($registration_dto->summaryTaggedText, 'reference', '/[dD]esignated\s+[bB]y/');
|
809
|
$tagged_text_expanded = cdm_tagged_text_expand_entity_references($tagged_text_cropped);
|
810
|
foreach ($tagged_text_expanded as $tagged_text){
|
811
|
if(isset($tagged_text->entityReference->type) && $tagged_text->entityReference->type == 'SpecimenTypeDesignation') {
|
812
|
$mediaDTOs = cdm_ws_get('typedesignation/$0/media', array($tagged_text->entityReference->uuid));
|
813
|
if(isset($mediaDTOs[0]->uri)){
|
814
|
$media_url_key = '{link-' . $mediaDTOs[0]->uuid . '}';
|
815
|
$tagged_text->text = str_replace('[icon]', '[icon]' . $media_url_key, $tagged_text->text);
|
816
|
$media_link_map[$media_url_key] = cdm_external_uri($mediaDTOs[0]->uri, true);
|
817
|
}
|
818
|
}
|
819
|
}
|
820
|
$registation_markup = cdm_tagged_text_to_markup($tagged_text_expanded);
|
821
|
foreach($media_link_map as $media_url_key => $link){
|
822
|
$registation_markup = str_replace($media_url_key, $link, $registation_markup);
|
823
|
}
|
824
|
if($style == 'citation') {
|
825
|
$registation_markup = $registation_markup . ' ' . $identifier_markup . ' ' . $registration_date_institute_markup;
|
826
|
} else {
|
827
|
$render_array['registration-metadata'] = markup_to_render_array('<div class="registration-metadata">' . $identifier_markup . ' ' . $registration_date_institute_markup. "</div>", -10);
|
828
|
}
|
829
|
$render_array['summary'] = markup_to_render_array('<' . $tag_enclosing_summary . ' class="registration-summary">' . $registation_markup . '</' . $tag_enclosing_summary . '>', 0);
|
830
|
|
831
|
return $render_array;
|
832
|
}
|
833
|
|
834
|
/**
|
835
|
* Renders the registrationDate and institutionTitleCache of the $registration_dto as markup.
|
836
|
*
|
837
|
* @param $registration_dto
|
838
|
* @return string
|
839
|
* The markup or an empty string
|
840
|
*/
|
841
|
function render_registration_date_and_institute($registration_dto, $enclosing_tag = 'p') {
|
842
|
$registration_date_institute_markup = '';
|
843
|
if ($registration_dto->registrationDate) {
|
844
|
$date_string = format_datetime($registration_dto->registrationDate);
|
845
|
if (isset($registration_dto->institutionTitleCache) && $registration_dto->institutionTitleCache) {
|
846
|
$registration_date_institute_markup =
|
847
|
t("Registration on @date in @institution", array(
|
848
|
'@date' => $date_string,
|
849
|
'@institution' => $registration_dto->institutionTitleCache,
|
850
|
));
|
851
|
} else {
|
852
|
$registration_date_institute_markup =
|
853
|
t("Registration on @date", array(
|
854
|
'@date' => $date_string
|
855
|
));
|
856
|
}
|
857
|
$registration_date_institute_markup = '<' .$enclosing_tag . ' class="registration-date-and-institute">'. $registration_date_institute_markup . '</' .$enclosing_tag . '>';
|
858
|
}
|
859
|
return $registration_date_institute_markup;
|
860
|
}
|
861
|
|
862
|
|
863
|
/**
|
864
|
* @param $registrations
|
865
|
* @return string
|
866
|
*/
|
867
|
function render_registrations($registrations)
|
868
|
{
|
869
|
$registration_markup = '';
|
870
|
$registration_markup_array = array();
|
871
|
if ($registrations) {
|
872
|
foreach ($registrations as $reg) {
|
873
|
$registration_markup_array[] = render_registration($reg);
|
874
|
}
|
875
|
$registration_markup = " Registration" . (count($registration_markup_array) > 1 ? 's: ' : ': ')
|
876
|
. join(', ', $registration_markup_array);
|
877
|
}
|
878
|
return $registration_markup;
|
879
|
}
|
880
|
|
881
|
|
882
|
/**
|
883
|
* Renders a registration
|
884
|
*
|
885
|
* TODO replace by compose_registration_dto_compact
|
886
|
* @param $registration
|
887
|
*/
|
888
|
function render_registration($registration){
|
889
|
$markup = '';
|
890
|
|
891
|
if(isset($registration->identifier) && $registration->status == 'PUBLISHED'){
|
892
|
$office_class_attribute = '';
|
893
|
if(isset($registration->institution->titleCache)){
|
894
|
$office_class_attribute = registration_institution_class_attribute($registration);
|
895
|
}
|
896
|
$markup = "<span class=\"registration $office_class_attribute\">" . render_link_to_registration($registration->identifier) . ', '
|
897
|
. preg_replace('/^([^T]*)(.*)$/', '${1}', $registration->registrationDate)
|
898
|
. '</span>';
|
899
|
}
|
900
|
return $markup;
|
901
|
}
|
902
|
|
903
|
/**
|
904
|
* @param $registration
|
905
|
* @return string
|
906
|
*/
|
907
|
function registration_institution_class_attribute($registration_dto)
|
908
|
{
|
909
|
if(isset($registration_dto->institutionTitleCache)){
|
910
|
$institutionTitleCache = $registration_dto->institutionTitleCache;
|
911
|
} else {
|
912
|
// fall back option to also support cdm entities
|
913
|
$institutionTitleCache = @$registration_dto->institution->titleCache;
|
914
|
}
|
915
|
return $institutionTitleCache ? 'registration-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '-', $institutionTitleCache)) : '';
|
916
|
}
|
917
|
|
918
|
|
919
|
/**
|
920
|
* Renders and array of CDM TypeDesignations
|
921
|
*
|
922
|
* - NameTypeDesignation
|
923
|
* - SpecimenTypeDesignation
|
924
|
* - TextualTypeDesignation
|
925
|
*
|
926
|
* @param array $type_designations an array of cdm TypeDesignation entities
|
927
|
* to render
|
928
|
* @param string $enclosing_tag the tag element type to enclose the whole list
|
929
|
* of type designation with. By default this DOM element is <ul>
|
930
|
* @param string $element_tag the tag element type to be used for each
|
931
|
* type designation item.
|
932
|
* @param bool $link_to_specimen_page whether a specimen in type designation element
|
933
|
* should be a link or not.
|
934
|
*
|
935
|
* @return string The markup.
|
936
|
*
|
937
|
* @InGroup Render
|
938
|
*/
|
939
|
function render_type_designations($type_designations, $enclosing_tag = 'ul', $element_tag = 'li', $link_to_specimen_page = true) {
|
940
|
|
941
|
// need to add element to render path since type designations
|
942
|
// need other name render template
|
943
|
RenderHints::pushToRenderStack('typedesignations');
|
944
|
|
945
|
$out = '<' . $enclosing_tag .' class="typeDesignations">';
|
946
|
$specimen_type_designations = array();
|
947
|
$name_type_designations = array();
|
948
|
$textual_type_designations = array();
|
949
|
$separator = ',';
|
950
|
|
951
|
foreach ($type_designations as $type_designation) {
|
952
|
switch ($type_designation->class) {
|
953
|
case 'SpecimenTypeDesignation':
|
954
|
$specimen_type_designations[] = $type_designation;
|
955
|
break;
|
956
|
case 'NameTypeDesignation':
|
957
|
$name_type_designations[] = $type_designation;
|
958
|
break;
|
959
|
case 'TextualTypeDesignation':
|
960
|
$textual_type_designations[] = $type_designation;
|
961
|
break;
|
962
|
default: throw new Exception('Unknown type designation class: ' . $type_designation->class);
|
963
|
}
|
964
|
}
|
965
|
|
966
|
// NameTypeDesignation ..................................
|
967
|
if(!empty($name_type_designations)){
|
968
|
usort($name_type_designations, "compare_type_designations_by_status");
|
969
|
foreach($name_type_designations as $name_type_designation){
|
970
|
if ($name_type_designation->notDesignated) {
|
971
|
$out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' . type_designation_status_label_markup($name_type_designation) . ': '
|
972
|
. t('not designated') . '</'. $element_tag .'>';
|
973
|
}
|
974
|
elseif (isset($name_type_designation->typeName)) {
|
975
|
$link_to_name_page = url(path_to_name($name_type_designation->typeName->uuid));
|
976
|
$out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' . type_designation_status_label_markup($name_type_designation) ;
|
977
|
|
978
|
if (!empty($name_type_designation->designationSource->citation)) {
|
979
|
$out .= type_designation_citation_layout($name_type_designation, $separator); // TODO type_designation_citation_layout() needs most probably to be replaced
|
980
|
|
981
|
}
|
982
|
$referenceUri = '';
|
983
|
if (isset($name_type_designation->typeName->nomenclaturalSource->citation)) {
|
984
|
$referenceUri = url(path_to_reference($name_type_designation->typeName->nomenclaturalSource->citation->uuid));
|
985
|
}
|
986
|
$out .= ': ' . render_taxon_or_name($name_type_designation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
|
987
|
}
|
988
|
RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
|
989
|
$annotations_and_sources = handle_annotations_and_sources($name_type_designation);
|
990
|
$out .= $annotations_and_sources->footNoteKeysMarkup();
|
991
|
}
|
992
|
} // END NameTypeDesignation
|
993
|
|
994
|
// SpecimenTypeDesignation ...................................
|
995
|
if (!empty($specimen_type_designations)) {
|
996
|
usort($specimen_type_designations, "compare_specimen_type_designation");
|
997
|
foreach ($specimen_type_designations as $specimen_type_designation) {
|
998
|
$type_citation_markup = '';
|
999
|
if ($specimen_type_designation->notDesignated) {
|
1000
|
$out .= '<' . $element_tag . ' class="' . html_class_attribute_ref($specimen_type_designation) . '">' . type_designation_status_label_markup($specimen_type_designation) . ': '
|
1001
|
. t('not designated') . '</' . $element_tag . '>';
|
1002
|
}
|
1003
|
else {
|
1004
|
|
1005
|
if (!empty($specimen_type_designation->designationSource->citation)) {
|
1006
|
|
1007
|
$citation_footnote_str = cdm_reference_markup($specimen_type_designation->designationSource->citation, NULL, FALSE, TRUE);
|
1008
|
$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $specimen_type_designation->designationSource->citation->uuid);
|
1009
|
|
1010
|
if (!empty($author_team->titleCache)) {
|
1011
|
$year = @timePeriodToString($specimen_type_designation->designationSource->citation->datePublished, TRUE, 'YYYY');
|
1012
|
$authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
|
1013
|
if ($authorteam_str == $specimen_type_designation->designationSource->citation->titleCache) {
|
1014
|
$citation_footnote_str = '';
|
1015
|
}
|
1016
|
}
|
1017
|
else {
|
1018
|
$authorteam_str = $citation_footnote_str;
|
1019
|
// no need for a footnote in case in case it is used as replacement for missing author teams
|
1020
|
$citation_footnote_str = '';
|
1021
|
}
|
1022
|
|
1023
|
// for being registered a typedesignation MUST HAVE a citation, so we safely can handle the
|
1024
|
// Registration output under the checked condition that the citation is present
|
1025
|
$registration_markup = render_registrations($specimen_type_designation->registrations);
|
1026
|
$citation_footnote_str .= ($citation_footnote_str ? ' ' : '') . $registration_markup;
|
1027
|
|
1028
|
$footnote_key_markup = '';
|
1029
|
if ($citation_footnote_str) {
|
1030
|
// footnotes should be rendered in the parent element so we
|
1031
|
// are relying on the FootnoteListKey set there
|
1032
|
$_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
|
1033
|
$footnote_key_markup = render_footnote_key($_fkey2, $separator, TRUE);
|
1034
|
}
|
1035
|
|
1036
|
$type_citation_markup .= ' (' . t('designated by') . ' <span class="typeReference">' . $authorteam_str . '</span>';
|
1037
|
if (!empty($specimen_type_designation->designationSource->citationMicroReference)) {
|
1038
|
$type_citation_markup .= ': ' . trim($specimen_type_designation->designationSource->citationMicroReference);
|
1039
|
}
|
1040
|
$type_citation_markup .= $footnote_key_markup . ')';
|
1041
|
}
|
1042
|
|
1043
|
$out .= '<' . $element_tag . ' class="' . html_class_attribute_ref($specimen_type_designation) . '">';
|
1044
|
$out .= type_designation_status_label_markup($specimen_type_designation) . $type_citation_markup;
|
1045
|
|
1046
|
|
1047
|
$derived_unit_dto = NULL;
|
1048
|
if (isset($specimen_type_designation->typeSpecimen)) {
|
1049
|
$derived_unit_dto = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE_AS_DTO, $specimen_type_designation->typeSpecimen->uuid);
|
1050
|
}
|
1051
|
|
1052
|
if (!empty($derived_unit_dto->summaryLabel)) {
|
1053
|
$specimen_markup = $derived_unit_dto->summaryLabel;
|
1054
|
if ($link_to_specimen_page && isset($derived_unit_dto->mostSignificantIdentifier) && $derived_unit_dto->mostSignificantIdentifier) {
|
1055
|
$specimen_markup = str_replace($derived_unit_dto->mostSignificantIdentifier, l($derived_unit_dto->mostSignificantIdentifier, path_to_specimen($specimen_type_designation->typeSpecimen->uuid)), $specimen_markup);
|
1056
|
}
|
1057
|
$media_sources_markup = '';
|
1058
|
if (isset_not_empty($derived_unit_dto->listOfMedia)) {
|
1059
|
foreach ($derived_unit_dto->listOfMedia as $media_dto) {
|
1060
|
// adding the source citations
|
1061
|
if (isset_not_empty($media_dto->sources)) {
|
1062
|
foreach ($media_dto->sources as $source_dto) {
|
1063
|
$media_sources_markup .= source_dto_markup($source_dto);
|
1064
|
}
|
1065
|
}
|
1066
|
}
|
1067
|
}
|
1068
|
if ($media_sources_markup) {
|
1069
|
$specimen_markup .= ' in ' . $media_sources_markup;
|
1070
|
}
|
1071
|
RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
|
1072
|
$annotations_and_sources = handle_annotations_and_sources($derived_unit_dto);
|
1073
|
$out .= ': <span class="' . html_class_attribute_ref($specimen_type_designation->typeSpecimen) . '">'
|
1074
|
. $specimen_markup
|
1075
|
. '</span>'; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
|
1076
|
if (!empty($derived_unit_dto->preferredStableUri)) {
|
1077
|
$out .= ' ' . l($derived_unit_dto->preferredStableUri, $derived_unit_dto->preferredStableUri, ['absolute' => TRUE]);
|
1078
|
}
|
1079
|
$out .= $annotations_and_sources->footNoteKeysMarkup();
|
1080
|
}
|
1081
|
|
1082
|
$out .= '</' . $element_tag . '>';
|
1083
|
}
|
1084
|
}
|
1085
|
} // END Specimen type designations
|
1086
|
|
1087
|
// TextualTypeDesignation .........................
|
1088
|
usort($textual_type_designations, 'compare_textual_type_designation');
|
1089
|
if(!empty($textual_type_designations)) {
|
1090
|
RenderHints::setAnnotationsAndSourceConfig([
|
1091
|
// these settings differ from those provided by annotations_and_sources_config_typedesignations()
|
1092
|
// TODO is this by purpose? please document the reason for the difference
|
1093
|
'sources_as_content' => false, // as footnotes
|
1094
|
'link_to_name_used_in_source' => false,
|
1095
|
'link_to_reference' => true,
|
1096
|
'add_footnote_keys' => true,
|
1097
|
'bibliography_aware' => false
|
1098
|
]
|
1099
|
);
|
1100
|
foreach ($textual_type_designations as $textual_type_designation) {
|
1101
|
$annotations_and_sources = handle_annotations_and_sources($textual_type_designation);
|
1102
|
$encasement = $textual_type_designation->verbatim ? '"' : '';
|
1103
|
$out .= '<' . $element_tag . ' class="' . html_class_attribute_ref($textual_type_designation) . '">' . type_designation_status_label_markup(null)
|
1104
|
. ': ' . $encasement . trim($textual_type_designation->text_L10n->text) . $encasement . $annotations_and_sources->footNoteKeysMarkup() .'</' . $element_tag . '>';
|
1105
|
// if($annotations_and_sources->hasSourceReferences())){
|
1106
|
// $citation_markup = join(', ', getSourceReferences());
|
1107
|
// }
|
1108
|
// $out .= $citation_markup;
|
1109
|
}
|
1110
|
}
|
1111
|
|
1112
|
// Footnotes for citations, collection acronyms.
|
1113
|
// footnotes should be rendered in the parent element so we
|
1114
|
// are relying on the FootnoteListKey set there
|
1115
|
$_fkey = FootnoteManager::addNewFootnote(
|
1116
|
RenderHints::getFootnoteListKey(),
|
1117
|
(isset($derived_unit_dto->collection->titleCache) ? $derived_unit_dto->collection->titleCache : FALSE)
|
1118
|
);
|
1119
|
$out .= render_footnote_key($_fkey, $separator);
|
1120
|
$out .= '</' . $enclosing_tag .'>';
|
1121
|
|
1122
|
RenderHints::popFromRenderStack();
|
1123
|
|
1124
|
return $out;
|
1125
|
}
|
1126
|
|
1127
|
/**
|
1128
|
* @param $source_dto
|
1129
|
*
|
1130
|
* @return string
|
1131
|
*/
|
1132
|
function source_dto_markup($source_dto, $as_nom_ref = false) {
|
1133
|
$source_dto_markup = '';
|
1134
|
if (isset_not_empty($source_dto->citation->abbrevTitleCache)) {
|
1135
|
$source_dto_markup .= $source_dto->citation->abbrevTitleCache;
|
1136
|
}
|
1137
|
if (isset_not_empty($source_dto->citationDetail)) {
|
1138
|
$source_dto_markup .= ': ' . $source_dto->citationDetail;
|
1139
|
}
|
1140
|
return $source_dto_markup;
|
1141
|
}
|
1142
|
|
1143
|
/**
|
1144
|
* Creates markup for a list of SpecimenTypedesignationDTO
|
1145
|
*
|
1146
|
* @param array $specimen_typedesignation_dtos
|
1147
|
* The SpecimenTypedesignationDTOs to be rendered
|
1148
|
*
|
1149
|
* @param bool $show_type_specimen
|
1150
|
*
|
1151
|
* @param string $enclosing_tag
|
1152
|
* @param string $element_tag
|
1153
|
*
|
1154
|
* @return string
|
1155
|
* The markup.
|
1156
|
*/
|
1157
|
function render_specimen_typedesignation_dto($specimen_typedesignation_dtos, $show_type_specimen = FALSE, $enclosing_tag = 'ul', $element_tag = 'li'){
|
1158
|
|
1159
|
// need to add element to render path since type designations
|
1160
|
// need other name render template
|
1161
|
RenderHints::pushToRenderStack('typedesignations');
|
1162
|
|
1163
|
$out = '<' . $enclosing_tag .' class="typeDesignations">';
|
1164
|
$separator = ',';
|
1165
|
|
1166
|
if (!empty($specimen_typedesignation_dtos)) {
|
1167
|
// usort($specimen_type_designations, "compare_specimen_type_designation"); // FIXME create compare function for SpecimenTypedesignationDTO
|
1168
|
foreach ($specimen_typedesignation_dtos as $std_dto) {
|
1169
|
$type_citation_markup = '';
|
1170
|
|
1171
|
if (!empty($std_dto->designationSource->citation)) {
|
1172
|
// TODO this now can be simplified since SourceDTO has the label field, see #9896
|
1173
|
$citation_footnote_str = cdm_reference_markup($std_dto->designationSource->citation, null, false, true);
|
1174
|
$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std_dto->designationSource->citation->uuid);
|
1175
|
|
1176
|
if (!empty($author_team->titleCache)) {
|
1177
|
$year = @timePeriodToString($std_dto->designationSource->citation->datePublished, true, 'YYYY');
|
1178
|
$authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
|
1179
|
if ($authorteam_str == $std_dto->designationSource->citation->label) {
|
1180
|
$citation_footnote_str = '';
|
1181
|
}
|
1182
|
} else {
|
1183
|
$authorteam_str = $citation_footnote_str;
|
1184
|
// no need for a footnote in case it is used as replacement for missing author teams
|
1185
|
$citation_footnote_str = '';
|
1186
|
}
|
1187
|
|
1188
|
// for being registered a typedesignation MUST HAVE a citation, so it is save to handle the
|
1189
|
// Registration output in the conditional block which has been checked that the citation is present
|
1190
|
$registration_markup = render_registrations($std_dto->registrations);
|
1191
|
$citation_footnote_str .= ($citation_footnote_str ? ' ' : '') . $registration_markup;
|
1192
|
|
1193
|
$footnote_key_markup = '';
|
1194
|
if ($citation_footnote_str) {
|
1195
|
// footnotes should be rendered in the parent element so we
|
1196
|
// are relying on the FootnoteListKey set there
|
1197
|
$_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
|
1198
|
$footnote_key_markup = render_footnote_key($_fkey2, $separator, TRUE);
|
1199
|
}
|
1200
|
|
1201
|
$type_citation_markup .= ' (' . t('designated by') . ' <span class="typeReference">' . $authorteam_str . '</span>';
|
1202
|
if (!empty($std_dto->designationSource->citationMicroReference)) {
|
1203
|
$type_citation_markup .= ': ' . trim($std_dto->designationSource->citationMicroReference);
|
1204
|
}
|
1205
|
$type_citation_markup .= $footnote_key_markup . ')';
|
1206
|
}
|
1207
|
|
1208
|
$out .= '<'. $element_tag .' class="' . html_class_attribute_ref($std_dto) . '">';
|
1209
|
$out .= type_designation_dto_status_label_markup($std_dto) . $type_citation_markup;
|
1210
|
|
1211
|
if($show_type_specimen){
|
1212
|
$derived_unit_dto = null;
|
1213
|
if (isset($std_dto->typeSpecimen)) {
|
1214
|
$derived_unit_dto = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE_AS_DTO, $std_dto->typeSpecimen->uuid);
|
1215
|
}
|
1216
|
|
1217
|
if (!empty($derived_unit_dto->summaryLabel)) {
|
1218
|
$specimen_markup = $derived_unit_dto->summaryLabel;
|
1219
|
if(isset($derived_unit_dto->mostSignificantIdentifier) && $derived_unit_dto->mostSignificantIdentifier){
|
1220
|
$specimen_markup = str_replace($derived_unit_dto->mostSignificantIdentifier, l($derived_unit_dto->mostSignificantIdentifier, path_to_specimen($std_dto->typeSpecimen->uuid)), $specimen_markup);
|
1221
|
}
|
1222
|
RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
|
1223
|
$annotations_and_sources = handle_annotations_and_sources($derived_unit_dto);
|
1224
|
$out .= ': <span class="' . html_class_attribute_ref($std_dto->typeSpecimen) . '">'
|
1225
|
. $specimen_markup
|
1226
|
. '</span>'; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
|
1227
|
if(!empty($derived_unit_dto->preferredStableUri)){
|
1228
|
$out .= ' ' . l($derived_unit_dto->preferredStableUri, $derived_unit_dto->preferredStableUri, array('absolute' => true));
|
1229
|
}
|
1230
|
$out .= $annotations_and_sources->footNoteKeysMarkup();
|
1231
|
}
|
1232
|
}
|
1233
|
|
1234
|
$out .= '</'. $element_tag .'>';
|
1235
|
}
|
1236
|
RenderHints::popFromRenderStack();
|
1237
|
}
|
1238
|
return $out;
|
1239
|
}
|
1240
|
|
1241
|
|
1242
|
/**
|
1243
|
* Composes the textual representation for the type designation of taxon name identified by the uuid in with a map for the location data.
|
1244
|
*
|
1245
|
* @param $taxon_name_uuid
|
1246
|
* @param $show_specimen_details
|
1247
|
* @return array
|
1248
|
* A drupal render array with the following elements:
|
1249
|
* - 'type_designations'
|
1250
|
* - 'map'
|
1251
|
* - 'specimens'
|
1252
|
*
|
1253
|
* @ingroup compose
|
1254
|
*/
|
1255
|
function compose_type_designations($taxon_name_uuid, $show_specimen_details = false)
|
1256
|
{
|
1257
|
$render_array = array(
|
1258
|
'type_designations' => array(),
|
1259
|
'map' => array(),
|
1260
|
);
|
1261
|
$type_designations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $taxon_name_uuid);
|
1262
|
if ($type_designations) {
|
1263
|
usort($type_designations, 'compare_specimen_type_designation');
|
1264
|
$render_array['type_designations'] = markup_to_render_array(
|
1265
|
render_type_designations($type_designations, 'div', 'div')
|
1266
|
);
|
1267
|
|
1268
|
$render_array['map'] = compose_type_designations_map($type_designations);
|
1269
|
}
|
1270
|
return $render_array;
|
1271
|
}
|
1272
|
|
1273
|
|
1274
|
/**
|
1275
|
* Composes the TypedEntityReference to name type designations passed as associatve array.
|
1276
|
*
|
1277
|
* @param $type_entity_refs_by_status array
|
1278
|
* an associative array of name type type => TypedEntityReference for name type designations as
|
1279
|
* produced by the eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager
|
1280
|
*
|
1281
|
* @ingroup compose
|
1282
|
*/
|
1283
|
function compose_name_type_designations($type_entity_refs_by_status){
|
1284
|
$render_array = array();
|
1285
|
$preferredStableUri = '';
|
1286
|
foreach($type_entity_refs_by_status as $type_status => $name_type_entityRefs){
|
1287
|
foreach ($name_type_entityRefs as $name_type_entity_ref){
|
1288
|
$type_designation = cdm_ws_get(CDM_WS_TYPEDESIGNATION, array($name_type_entity_ref->uuid, 'preferredUri'));
|
1289
|
$footnote_keys = '';
|
1290
|
|
1291
|
if(isset($type_designation->typeSpecimen->preferredStableUri) && $type_designation->typeSpecimen->preferredStableUri){
|
1292
|
$preferredStableUri = $type_designation->typeSpecimen->preferredStableUri;
|
1293
|
}
|
1294
|
// annotations and sources for the $derived_unit_facade_dto
|
1295
|
RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
|
1296
|
$annotations_and_sources = handle_annotations_and_sources($name_type_entity_ref);
|
1297
|
|
1298
|
$render_array[] = markup_to_render_array('<div class="name_type_designation ' . html_class_attribute_ref($name_type_entity_ref) .
|
1299
|
'"><span class="type-status">'. ucfirst($type_status) . "</span>: "
|
1300
|
. cdm_tagged_text_to_markup($name_type_entity_ref->taggedText)
|
1301
|
. ($preferredStableUri ? " ". l($preferredStableUri, $preferredStableUri) : '')
|
1302
|
. $annotations_and_sources->footNoteKeysMarkup()
|
1303
|
. '</div>');
|
1304
|
}
|
1305
|
}
|
1306
|
return $render_array;
|
1307
|
}
|
1308
|
|
1309
|
/**
|
1310
|
* Composes the specimen type designations with map from the the $type_entity_refs
|
1311
|
*
|
1312
|
* @param $type_entity_refs array
|
1313
|
* an associative array of specimen type type => TypedEntityReference for specimen type designations as
|
1314
|
* produced by the eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager
|
1315
|
*
|
1316
|
* @param $show_media_specimen
|
1317
|
* @return array
|
1318
|
* A drupal render array with the following elements:
|
1319
|
* - 'type_designations'
|
1320
|
* - 'map'
|
1321
|
*
|
1322
|
* @ingroup compose
|
1323
|
*
|
1324
|
*/
|
1325
|
function compose_specimen_type_designations($type_entity_refs, $show_media_specimen){
|
1326
|
|
1327
|
$render_array = array();
|
1328
|
|
1329
|
$type_designation_list = array();
|
1330
|
uksort($type_entity_refs, "compare_type_designation_status_labels");
|
1331
|
foreach($type_entity_refs as $type_status => $type_designation_entity_refs){
|
1332
|
foreach($type_designation_entity_refs as $type_designation_entity_ref){
|
1333
|
|
1334
|
$type_designation = cdm_ws_get(CDM_WS_PORTAL_TYPEDESIGNATION, array($type_designation_entity_ref->uuid));
|
1335
|
$type_designation_list[] = $type_designation; // collect for the map
|
1336
|
|
1337
|
$derived_unit_facade_dto = cdm_ws_get(CDM_WS_PORTAL_DERIVEDUNIT_FACADE, $type_designation->typeSpecimen->uuid);
|
1338
|
// the media specimen is not contained in the $type_designation returned by CDM_PORTAL_TYPEDESIGNATION, so we need to fetch it separately
|
1339
|
$mediaSpecimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($type_designation->typeSpecimen->uuid, 'mediaSpecimen'));
|
1340
|
|
1341
|
|
1342
|
$preferredStableUri = '';
|
1343
|
$citation_markup = '';
|
1344
|
$media = '';
|
1345
|
|
1346
|
// annotations and sources for the $derived_unit_facade_dto
|
1347
|
RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
|
1348
|
$annotations_and_sources = handle_annotations_and_sources($derived_unit_facade_dto);
|
1349
|
$source_citations = $annotations_and_sources->getSourceReferences();
|
1350
|
$foot_note_keys = $annotations_and_sources->footNoteKeysMarkup();
|
1351
|
|
1352
|
// preferredStableUri
|
1353
|
if(isset($type_designation->typeSpecimen->preferredStableUri) && $type_designation->typeSpecimen->preferredStableUri){
|
1354
|
$preferredStableUri = $type_designation->typeSpecimen->preferredStableUri;
|
1355
|
}
|
1356
|
|
1357
|
if($show_media_specimen && $mediaSpecimen){
|
1358
|
// compose output
|
1359
|
// mediaURI
|
1360
|
if(isset($mediaSpecimen->representations[0])) {
|
1361
|
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
|
1362
|
$captionElements = array(
|
1363
|
'#uri' => t('open media'),
|
1364
|
'elements' => array('-none-'),
|
1365
|
'sources_as_content' => true
|
1366
|
);
|
1367
|
$media = compose_cdm_media_gallery(array(
|
1368
|
'mediaList' => array($mediaSpecimen),
|
1369
|
'galleryName' => CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME . '_' . $type_designation_entity_ref->uuid,
|
1370
|
'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
|
1371
|
'cols' => $gallery_settings['cdm_dataportal_media_cols'],
|
1372
|
'captionElements' => $captionElements,
|
1373
|
));
|
1374
|
}
|
1375
|
// citation and detail for the media specimen
|
1376
|
RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
|
1377
|
$annotations_and_sources = handle_annotations_and_sources($mediaSpecimen);
|
1378
|
if($annotations_and_sources->hasSourceReferences()){
|
1379
|
$source_citations = array_merge($source_citations, $annotations_and_sources->getSourceReferences());
|
1380
|
}
|
1381
|
if($annotations_and_sources->hasFootnoteKeys()){
|
1382
|
$foot_note_keys .= ', ' . $annotations_and_sources->footNoteKeysMarkup();
|
1383
|
}
|
1384
|
}
|
1385
|
|
1386
|
$citation_markup = join(', ', $source_citations);
|
1387
|
|
1388
|
$specimen_markup = $derived_unit_facade_dto->titleCache;
|
1389
|
if(isset($derived_unit_facade_dto->specimenLabel) && $derived_unit_facade_dto->specimenLabel){
|
1390
|
$specimen_markup = str_replace(
|
1391
|
$derived_unit_facade_dto->specimenLabel,
|
1392
|
l($derived_unit_facade_dto->specimenLabel, path_to_specimen($type_designation->typeSpecimen->uuid)), $specimen_markup);
|
1393
|
}
|
1394
|
|
1395
|
$type_designation_render_array = markup_to_render_array(
|
1396
|
'<div class="type_designation_entity_ref ' . html_class_attribute_ref($type_designation_entity_ref) . '">
|
1397
|
<span class="type-status">' . ucfirst($type_status) . "</span>: "
|
1398
|
. $specimen_markup . $foot_note_keys
|
1399
|
. ($citation_markup ? ' '. $citation_markup : '')
|
1400
|
. ($preferredStableUri ? " ". l($preferredStableUri, $preferredStableUri) : '')
|
1401
|
. $media
|
1402
|
. '</div>');
|
1403
|
|
1404
|
$render_array['type_designations'][] = $type_designation_render_array;
|
1405
|
}
|
1406
|
}
|
1407
|
if(count($type_designation_list) > 0 ){
|
1408
|
$render_array['map'] = compose_type_designations_map($type_designation_list);
|
1409
|
} else {
|
1410
|
$render_array['map'] = array();
|
1411
|
}
|
1412
|
return $render_array;
|
1413
|
}
|
1414
|
|
1415
|
/**
|
1416
|
* Creates the markup for the given name relationship.
|
1417
|
*
|
1418
|
* For the footnotes see handle_annotations_and_sources().
|
1419
|
*
|
1420
|
* @param $other_name
|
1421
|
* The other name from the NameRelationship see get_other_name()
|
1422
|
* @param $current_taxon_uuid
|
1423
|
* @param $show_name_cache_only
|
1424
|
* The nameCache will be shown instead of the titleCache if this parameter is true.
|
1425
|
* @return null|string
|
1426
|
* The markup or null
|
1427
|
*
|
1428
|
* @see \get_other_name
|
1429
|
*/
|
1430
|
function name_relationship_markup($current_name_uuid, $name_rel, $current_taxon_uuid, $show_name_cache_only = false){
|
1431
|
|
1432
|
$relationship_markup = null;
|
1433
|
|
1434
|
$other_name = get_other_name($current_name_uuid, $name_rel);
|
1435
|
|
1436
|
cdm_load_tagged_full_title($other_name);
|
1437
|
|
1438
|
$highlited_synonym_uuid = isset ($other_name->taxonBases[0]->uuid) ? $other_name->taxonBases[0]->uuid : '';
|
1439
|
if($show_name_cache_only){
|
1440
|
$relationship_markup = l(
|
1441
|
'<span class="' . html_class_attribute_ref($other_name) . '"">' . $other_name->nameCache . '</span>',
|
1442
|
path_to_name($other_name->uuid, $current_taxon_uuid, $highlited_synonym_uuid, false),
|
1443
|
array('html' => true)
|
1444
|
);
|
1445
|
$annotations_and_sources = handle_annotations_and_sources($other_name);
|
1446
|
$relationship_markup .= $annotations_and_sources->footNoteKeysMarkup();
|
1447
|
} else {
|
1448
|
$relationship_markup = render_taxon_or_name($other_name,
|
1449
|
url(path_to_name($other_name->uuid, $current_taxon_uuid, $highlited_synonym_uuid, false))
|
1450
|
);
|
1451
|
}
|
1452
|
|
1453
|
return $relationship_markup;
|
1454
|
}
|
1455
|
|
1456
|
/**
|
1457
|
* Determined the other name which is contained in the NameRelationship entity.
|
1458
|
*
|
1459
|
* @param $current_name_uuid
|
1460
|
* The uuid of this name.
|
1461
|
* @param $name_rel
|
1462
|
* The cdm NameRelationship entity
|
1463
|
*
|
1464
|
* @return object
|
1465
|
* The other cdm Name entity.
|
1466
|
*/
|
1467
|
function get_other_name($current_name_uuid, $name_rel) {
|
1468
|
$current_name_is_toName = $current_name_uuid == $name_rel->toName->uuid;
|
1469
|
|
1470
|
if ($current_name_is_toName) {
|
1471
|
$name = $name_rel->fromName;
|
1472
|
}
|
1473
|
else {
|
1474
|
$name = $name_rel->toName;
|
1475
|
}
|
1476
|
return $name;
|
1477
|
}
|
1478
|
|
1479
|
|
1480
|
/**
|
1481
|
* Composes an inline representation of selected name relationships
|
1482
|
*
|
1483
|
* The output of this function will be usually appended to taxon name representations.
|
1484
|
* Only the following types are displayed: LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR, ORTHOGRAPHIC_VARIANT
|
1485
|
*
|
1486
|
* LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR are displayed as
|
1487
|
* non {titleCache} nec {titleCache} nec {titleCache} whereas the related names
|
1488
|
* are ordered alphabetically.
|
1489
|
*
|
1490
|
* ORTHOGRAPHIC_VARIANT is displayed as 'ort. var. {nameCache}'
|
1491
|
*
|
1492
|
* Related issues:
|
1493
|
* - https://dev.e-taxonomy.eu/redmine/issues/5697 "Show name conserved against as [non xxx]"
|
1494
|
* - https://dev.e-taxonomy.eu/redmine/issues/6678 "How to correctly show name relationship "orth. var." in dataportal"
|
1495
|
* - https://dev.e-taxonomy.eu/redmine/issues/5857
|
1496
|
* - https://dev.e-taxonomy.eu/redmine/issues/2001 "[Cichorieae Portal] Name Relationship -> blocking name are not shown"
|
1497
|
*
|
1498
|
* @param $name_relations
|
1499
|
* The list of CDM NameRelationsips
|
1500
|
* @param $current_name_uuid
|
1501
|
* The Uuid of the name for which the relations are to be rendered, the current name will be hidden when
|
1502
|
* rendering the relation an only the other name is shown. Parameter is REQUIRED.
|
1503
|
* @param $suppress_if_current_name_is_source
|
1504
|
* The display of the relation will be
|
1505
|
* suppressed is the current name is on the source of the relation edge.
|
1506
|
* That is if it is on the from side of the relation. Except for 'blocking name for' which is
|
1507
|
* an inverse relation. For this relation type the toName is taken in to account.
|
1508
|
* @param $current_taxon_uuid
|
1509
|
* The taxon to be omitted from related taxa. This is only used to create links, see path_to_name()
|
1510
|
* @return array
|
1511
|
* A drupal render array
|
1512
|
*
|
1513
|
* @ingroup Compose
|
1514
|
*/
|
1515
|
function compose_name_relationships_inline($name_relations, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source = true) {
|
1516
|
|
1517
|
RenderHints::pushToRenderStack('homonym');
|
1518
|
// the render stack element homonyms is being used in the default render templates !!!, see NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES_DEFAULT
|
1519
|
|
1520
|
$selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT));
|
1521
|
$name_rel_type_filter = array('direct' => array(), 'inverse' => array());
|
1522
|
foreach ($selected_name_rel_uuids as $uuid){
|
1523
|
$name_rel_type_filter['direct'][$uuid] = $uuid;
|
1524
|
if($uuid != UUID_NAMERELATIONSHIPTYPE_MISSPELLING){
|
1525
|
$name_rel_type_filter['inverse'][$uuid] = $uuid;
|
1526
|
}
|
1527
|
}
|
1528
|
|
1529
|
$list_prefix = '<span class="name_relationships">[';
|
1530
|
$list_suffix = ']</span>';
|
1531
|
$item_prefix = '<span class="item">';
|
1532
|
$item_suffix = '</span> ';
|
1533
|
$render_array = compose_name_relationships($name_relations, $name_rel_type_filter, $current_name_uuid, $current_taxon_uuid, $list_prefix, $list_suffix, $item_prefix, $item_suffix);
|
1534
|
|
1535
|
// remove the glue space from the last item element which has been added by the $item_suffix = '</span> '
|
1536
|
$items_ctn = count($render_array['list']['items']);
|
1537
|
if($items_ctn){
|
1538
|
$render_array['list']['items'][$items_ctn - 1]['#suffix'] = '</span>';
|
1539
|
}
|
1540
|
|
1541
|
RenderHints::popFromRenderStack();
|
1542
|
return $render_array;
|
1543
|
}
|
1544
|
|
1545
|
/**
|
1546
|
* Composes an list representation of the name relationships.
|
1547
|
*
|
1548
|
* The output of this function will be usually appended to taxon name representations.
|
1549
|
*
|
1550
|
* Related issues:
|
1551
|
* - https://dev.e-taxonomy.eu/redmine/issues/5697 "Show name conserved against as [non xxx]"
|
1552
|
* - https://dev.e-taxonomy.eu/redmine/issues/6678 "How to correctly show name relationship "orth. var." in dataportal"
|
1553
|
* - https://dev.e-taxonomy.eu/redmine/issues/5857
|
1554
|
*
|
1555
|
* @param $name_relations
|
1556
|
* The list of CDM NameRelationsips
|
1557
|
* @param $current_name_uuid
|
1558
|
* The Uuid of the name for which the relations are to be rendered, the current name will be hidden when
|
1559
|
* rendering the relation an only the other name is shown. Parameter is REQUIRED.
|
1560
|
* @param $current_taxon_uuid
|
1561
|
* The taxon to be omitted from related taxa. This is only used to create links, see path_to_name()
|
1562
|
* @return array
|
1563
|
* A drupal render array
|
1564
|
*
|
1565
|
* @ingroup Compose
|
1566
|
*/
|
1567
|
function compose_name_relationships_list($name_relations, $current_name_uuid, $current_taxon_uuid) {
|
1568
|
|
1569
|
// $ordered_name_relation_type_uuids = array_keys(cdm_terms_by_type_as_option('NameRelationshipType', CDM_ORDER_BY_ORDER_INDEX_ASC));
|
1570
|
|
1571
|
$key = 'name_relationships';
|
1572
|
RenderHints::pushToRenderStack($key);
|
1573
|
if(RenderHints::isUnsetFootnoteListKey()){
|
1574
|
RenderHints::setFootnoteListKey($key);
|
1575
|
}
|
1576
|
// the render stack element homonyms is being used in the default render templates !!!, see CDM_NAME_RENDER_TEMPLATES_DEFAULT
|
1577
|
|
1578
|
$selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE));
|
1579
|
$name_rel_type_filter = array('direct' => array(), 'inverse' => array());
|
1580
|
foreach ($selected_name_rel_uuids as $uuid){
|
1581
|
$name_rel_type_filter['direct'][$uuid] = $uuid;
|
1582
|
$name_rel_type_filter['inverse'][$uuid] = $uuid;
|
1583
|
}
|
1584
|
|
1585
|
$list_prefix = '<div class="relationships_list name_relationships">';
|
1586
|
$list_suffix = '</div>';
|
1587
|
$item_prefix = '<div class="item">';
|
1588
|
$item_suffix = '</div>';
|
1589
|
|
1590
|
$render_array = compose_name_relationships($name_relations, $name_rel_type_filter, $current_name_uuid, $current_taxon_uuid, $list_prefix, $list_suffix, $item_prefix, $item_suffix);
|
1591
|
|
1592
|
RenderHints::popFromRenderStack();
|
1593
|
if(RenderHints::getFootnoteListKey() == $key) {
|
1594
|
$render_array['footnotes'] = markup_to_render_array(render_footnotes(RenderHints::getFootnoteListKey()));
|
1595
|
RenderHints::clearFootnoteListKey();
|
1596
|
}
|
1597
|
return $render_array;
|
1598
|
}
|
1599
|
|
1600
|
/**
|
1601
|
* @param $name_relations
|
1602
|
* @param $name_rel_type_filter
|
1603
|
* Associative array with two keys:
|
1604
|
* - 'direct': the relationship type uuids for the direct direction of the relation edge to be included
|
1605
|
* - 'inverse': the relationship type uuids for the direct direction of the relation edge to be included
|
1606
|
* @param $current_name_uuid
|
1607
|
* @param $current_taxon_uuid
|
1608
|
* @param $list_prefix
|
1609
|
* @param $list_suffix
|
1610
|
* @param $item_prefix
|
1611
|
* @param $item_suffix
|
1612
|
* @return array
|
1613
|
*
|
1614
|
* @ingroup Compose
|
1615
|
*/
|
1616
|
function compose_name_relationships($name_relations, $name_rel_type_filter, $current_name_uuid, $current_taxon_uuid,
|
1617
|
$list_prefix, $list_suffix, $item_prefix, $item_suffix)
|
1618
|
{
|
1619
|
$non_nec_name_reltype_uuids = array(UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
|
1620
|
UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
|
1621
|
UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST,
|
1622
|
UUID_NAMERELATIONSHIPTYPE_MISSPELLING,
|
1623
|
UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
|
1624
|
|
1625
|
$render_array = array(
|
1626
|
'list' => array(
|
1627
|
'#prefix' => $list_prefix,
|
1628
|
'#suffix' => $list_suffix,
|
1629
|
'items' => array()
|
1630
|
),
|
1631
|
'footnotes' => array()
|
1632
|
);
|
1633
|
|
1634
|
if ($name_relations) {
|
1635
|
|
1636
|
// remove all relations which are not selected in the settings and
|
1637
|
// separate all LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR relations and ORTHOGRAPHIC_VARIANTs
|
1638
|
// for special handling
|
1639
|
$filtered_name_rels = array();
|
1640
|
$non_nec_name_rels = array();
|
1641
|
$orthographic_variants = array();
|
1642
|
foreach ($name_relations as $name_rel) {
|
1643
|
$rel_type_uuid = $name_rel->type->uuid;
|
1644
|
$is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
|
1645
|
if ((!$is_inverse_relation && isset($name_rel_type_filter['direct'][$rel_type_uuid]) && $name_rel_type_filter['direct'][$rel_type_uuid])
|
1646
|
||($is_inverse_relation && isset($name_rel_type_filter['inverse'][$rel_type_uuid]) && $name_rel_type_filter['inverse'][$rel_type_uuid])) {
|
1647
|
|
1648
|
if (array_search($rel_type_uuid, $non_nec_name_reltype_uuids) !== false && (
|
1649
|
$current_name_uuid == $name_rel->fromName->uuid && $rel_type_uuid != UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
|
1650
|
|| $current_name_uuid == $name_rel->toName->uuid && $rel_type_uuid == UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
|
1651
|
)
|
1652
|
){
|
1653
|
$non_nec_name_rels[] = $name_rel;
|
1654
|
} else if (UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT == $rel_type_uuid) {
|
1655
|
$orthographic_variants[] = $name_rel;
|
1656
|
} else {
|
1657
|
|
1658
|
$filtered_name_rels[] = $name_rel;
|
1659
|
}
|
1660
|
}
|
1661
|
}
|
1662
|
$name_relations = $filtered_name_rels;
|
1663
|
|
1664
|
usort($name_relations, 'compare_name_relations_by_term_order_index');
|
1665
|
|
1666
|
// compose
|
1667
|
$show_name_cache_only = FALSE;
|
1668
|
foreach ($name_relations as $name_rel) {
|
1669
|
|
1670
|
$is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
|
1671
|
$rel_footnote_key_markup = render_footnote_key(handle_name_relationship_as_footnote($name_rel),'');
|
1672
|
$relationship_markup = name_relationship_markup($current_name_uuid, $name_rel, $current_taxon_uuid, $show_name_cache_only);
|
1673
|
$label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
|
1674
|
|
1675
|
$symbol = cdm_relationship_type_term_symbol($name_rel->type, $is_inverse_relation);
|
1676
|
$symbol_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span>' . $rel_footnote_key_markup . ' ';
|
1677
|
$relationship_markup = $symbol_markup . $relationship_markup;
|
1678
|
if ($relationship_markup) {
|
1679
|
$render_array['list']['items'][] = markup_to_render_array($relationship_markup,
|
1680
|
null,
|
1681
|
$item_prefix,
|
1682
|
$item_suffix);
|
1683
|
}
|
1684
|
}
|
1685
|
|
1686
|
// name relationships to be displayed as non nec
|
1687
|
if (count($non_nec_name_rels) > 0) {
|
1688
|
$non_nec_markup = '';
|
1689
|
$show_name_cache_only = FALSE;
|
1690
|
foreach ($non_nec_name_rels as $name_rel) {
|
1691
|
|
1692
|
$is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
|
1693
|
$rel_footnote_key_markup = render_footnote_key(handle_name_relationship_as_footnote($name_rel),'');
|
1694
|
$relationship_markup = name_relationship_markup($current_name_uuid, $name_rel, $current_taxon_uuid, $show_name_cache_only);
|
1695
|
$label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
|
1696
|
|
1697
|
$symbol = $non_nec_markup ? ' nec ' : 'non';
|
1698
|
$symbol_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span>' . $rel_footnote_key_markup . ' ';
|
1699
|
$non_nec_markup .= $symbol_markup . $relationship_markup;
|
1700
|
}
|
1701
|
if ($non_nec_markup) {
|
1702
|
$render_array['list']['items'][] = markup_to_render_array($non_nec_markup,
|
1703
|
null,
|
1704
|
$item_prefix,
|
1705
|
$item_suffix);
|
1706
|
}
|
1707
|
}
|
1708
|
|
1709
|
// orthographic variants
|
1710
|
if (count($orthographic_variants) > 0) {
|
1711
|
$show_name_cache_only = TRUE;
|
1712
|
foreach ($orthographic_variants as $name_rel) {
|
1713
|
|
1714
|
$is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
|
1715
|
$rel_footnote_key_markup = render_footnote_key(handle_name_relationship_as_footnote($name_rel),'');
|
1716
|
$relationship_markup = name_relationship_markup($current_name_uuid, $name_rel, $current_taxon_uuid, $show_name_cache_only);
|
1717
|
$label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
|
1718
|
$symbol = cdm_relationship_type_term_symbol($name_rel->type, $is_inverse_relation);
|
1719
|
$symbol_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span>' . $rel_footnote_key_markup . ' ';
|
1720
|
$relationship_markup = $symbol_markup . $relationship_markup;
|
1721
|
}
|
1722
|
if (isset($relationship_markup) && $relationship_markup) {
|
1723
|
$render_array['list']['items'][] = markup_to_render_array($relationship_markup,
|
1724
|
null,
|
1725
|
$item_prefix,
|
1726
|
$item_suffix);
|
1727
|
}
|
1728
|
}
|
1729
|
}
|
1730
|
return $render_array;
|
1731
|
}
|
1732
|
|
1733
|
|
1734
|
|
1735
|
/**
|
1736
|
* @param $taxon
|
1737
|
* @return array
|
1738
|
*/
|
1739
|
function cdm_name_relationships_for_taxon($taxon)
|
1740
|
{
|
1741
|
$from_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS, $taxon->uuid);
|
1742
|
$to_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
|
1743
|
$name_relations = array_merge($from_name_relations, $to_name_relations);
|
1744
|
return $name_relations;
|
1745
|
}
|
1746
|
|
1747
|
|
1748
|
/**
|
1749
|
* Recursively searches the array for the $key and sets the given value.
|
1750
|
*
|
1751
|
* Expects the key to be used only once in nested array structures.
|
1752
|
*
|
1753
|
* @param mixed $key
|
1754
|
* Key to search for.
|
1755
|
* @param mixed $value
|
1756
|
* Value to set.'
|
1757
|
* @param array $array
|
1758
|
* Array to search in.
|
1759
|
*
|
1760
|
* @return array
|
1761
|
* The array the key has been found.
|
1762
|
*/
|
1763
|
function &array_setr($key, $value, array &$array) {
|
1764
|
$res = NULL;
|
1765
|
foreach ($array as $k => &$v) {
|
1766
|
if ($key == $k) {
|
1767
|
$v = $value;
|
1768
|
return $array;
|
1769
|
}
|
1770
|
elseif (is_array($v)) {
|
1771
|
$innerArray = array_setr($key, $value, $v);
|
1772
|
if ($innerArray) {
|
1773
|
return $array;
|
1774
|
}
|
1775
|
}
|
1776
|
}
|
1777
|
return $res;
|
1778
|
}
|
1779
|
|
1780
|
/**
|
1781
|
* Recursively searches the array for the $key and sets is to $new_key
|
1782
|
*
|
1783
|
* Expects the key to be used only once in nested array structures.
|
1784
|
*
|
1785
|
* @param mixed $key
|
1786
|
* Key to search for.
|
1787
|
* @param mixed $new_key
|
1788
|
* The new key to use
|
1789
|
* @param array $array
|
1790
|
* Array to search in.
|
1791
|
*
|
1792
|
* @return bool
|
1793
|
* True if the key has been found.
|
1794
|
*/
|
1795
|
function array_replace_keyr($key, $new_key, array &$array) {
|
1796
|
$res = NULL;
|
1797
|
if(array_key_exists($key, $array)){
|
1798
|
$value = $array[$key];
|
1799
|
unset($array[$key]);
|
1800
|
$array[$new_key] = $value;
|
1801
|
return true;
|
1802
|
} else {
|
1803
|
// search in next level
|
1804
|
foreach ($array as &$v) {
|
1805
|
if (is_array($v)) {
|
1806
|
array_replace_keyr($key, $new_key, $v);
|
1807
|
}
|
1808
|
}
|
1809
|
}
|
1810
|
|
1811
|
return false;
|
1812
|
}
|
1813
|
|
1814
|
/**
|
1815
|
* @todo Please document this function.
|
1816
|
* @see http://drupal.org/node/1354
|
1817
|
*/
|
1818
|
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate) {
|
1819
|
$res = NULL;
|
1820
|
$precedingElement = NULL;
|
1821
|
foreach ($renderTemplate as &$part) {
|
1822
|
foreach ($part as $key => &$element) {
|
1823
|
if ($key == $contentElementKey) {
|
1824
|
return $precedingElement;
|
1825
|
}
|
1826
|
$precedingElement = $element;
|
1827
|
}
|
1828
|
}
|
1829
|
return $res;
|
1830
|
}
|
1831
|
|
1832
|
/**
|
1833
|
* @todo Please document this function.
|
1834
|
* @see http://drupal.org/node/1354
|
1835
|
*/
|
1836
|
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate) {
|
1837
|
$res = NULL;
|
1838
|
$precedingKey = NULL;
|
1839
|
foreach ($renderTemplate as &$part) {
|
1840
|
if (is_array($part)) {
|
1841
|
foreach ($part as $key => &$element) {
|
1842
|
if ($key == $contentElementKey) {
|
1843
|
return $precedingKey;
|
1844
|
}
|
1845
|
if (!str_beginsWith($key, '#')) {
|
1846
|
$precedingKey = $key;
|
1847
|
}
|
1848
|
}
|
1849
|
}
|
1850
|
}
|
1851
|
return $res;
|
1852
|
}
|
1853
|
|
1854
|
function nameTypeToDTYPE($dtype){
|
1855
|
static $nameTypeLabelMap = array(
|
1856
|
"ICNB" => "BacterialName",
|
1857
|
"ICNAFP" => "BotanicalName",
|
1858
|
"ICNCP" => "CultivarPlantName",
|
1859
|
"ICZN" => "ZoologicalName",
|
1860
|
"ICVCN" => "ViralName",
|
1861
|
"Any taxon name" => "TaxonName",
|
1862
|
"NonViral" => "TaxonName",
|
1863
|
"Fungus" => "BotanicalName",
|
1864
|
"Plant" => "BotanicalName",
|
1865
|
"Algae" => "BotanicalName",
|
1866
|
);
|
1867
|
return $nameTypeLabelMap[$dtype];
|
1868
|
|
1869
|
}
|
1870
|
|
1871
|
|
1872
|
function compare_name_relations_by_term_order_index($name_rel1, $name_rel2){
|
1873
|
return compare_terms_by_order_index($name_rel1->type, $name_rel2->type);
|
1874
|
}
|
1875
|
|
1876
|
/**
|
1877
|
* Provides an array with the different registration types covered by the passed registration.
|
1878
|
*
|
1879
|
* The labels in the returned array are translatable.
|
1880
|
*
|
1881
|
* See also https://dev.e-taxonomy.eu/redmine/issues/8016
|
1882
|
*
|
1883
|
* @param $registration_dto
|
1884
|
* @return array
|
1885
|
* An array of the labels describing the different registration types covered by the passed registration.
|
1886
|
*/
|
1887
|
function registration_types($registration_dto){
|
1888
|
$reg_type_labels = array();
|
1889
|
if(isset($registration_dto->nameRef)){
|
1890
|
$reg_type_labels["name"] = t("new name");
|
1891
|
$reg_type_labels["taxon"] = t("new taxon");
|
1892
|
$name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
|
1893
|
$is_new_combination = true;
|
1894
|
foreach($name_relations as $name_rel){
|
1895
|
if(isset($name_rel->type->uuid)){
|
1896
|
$name_is_from_name = $registration_dto->nameRef->uuid == $name_rel->fromName->uuid;
|
1897
|
switch($name_rel->type->uuid) {
|
1898
|
case UUID_NAMERELATIONSHIPTYPE_BASIONYM:
|
1899
|
if(!$name_is_from_name){
|
1900
|
$reg_type_labels["basionym"] = t("new combination");
|
1901
|
$is_new_combination = true;
|
1902
|
}
|
1903
|
break;
|
1904
|
case UUID_NAMERELATIONSHIPTYPE_REPLACED_SYNONYM:
|
1905
|
if(!$name_is_from_name) {
|
1906
|
$is_new_combination = true;
|
1907
|
}
|
1908
|
break;
|
1909
|
case UUID_NAMERELATIONSHIPTYPE_VALIDATED_BY_NAME:
|
1910
|
if(!$name_is_from_name) {
|
1911
|
$reg_type_labels["validation"] = t("validation");
|
1912
|
}
|
1913
|
break;
|
1914
|
case UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT:
|
1915
|
if(!$name_is_from_name) {
|
1916
|
$reg_type_labels["orth_var"] = t("orthographical correction");
|
1917
|
}break;
|
1918
|
default:
|
1919
|
// NOTHING
|
1920
|
}
|
1921
|
}
|
1922
|
}
|
1923
|
if($is_new_combination){
|
1924
|
unset($reg_type_labels["taxon"]);
|
1925
|
}
|
1926
|
}
|
1927
|
if(isset($registration_dto->orderedTypeDesignationWorkingSets)){
|
1928
|
$reg_type_labels[] = t("new nomenclatural type");
|
1929
|
}
|
1930
|
return $reg_type_labels;
|
1931
|
}
|
1932
|
|
1933
|
/**
|
1934
|
* Collects and deduplicates the type designations associated with the passes synonyms.
|
1935
|
*
|
1936
|
* @param $synonymy_group
|
1937
|
* An array containing a homotypic or heterotypic group of names.
|
1938
|
* @param $accepted_taxon_name_uuid
|
1939
|
* The uuid of the accepted taxon name. Optional parameter which is required when composing
|
1940
|
* the information for the homotypic group. In this case the accepted taxon is not included
|
1941
|
* in the $synonymy_group and must therefor passed in this second parameter.
|
1942
|
*
|
1943
|
* @return array
|
1944
|
* The CDM TypeDesignation entities
|
1945
|
*/
|
1946
|
function type_designations_for_synonymy_group($synonymy_group, $accepted_taxon_name_uuid = null)
|
1947
|
{
|
1948
|
if (count($synonymy_group) > 0) {
|
1949
|
$name_uuid = array_pop($synonymy_group)->name->uuid;
|
1950
|
} else {
|
1951
|
$name_uuid = $accepted_taxon_name_uuid;
|
1952
|
}
|
1953
|
if ($name_uuid) {
|
1954
|
$type_designations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS_IN_HOMOTYPICAL_GROUP, $name_uuid);
|
1955
|
if ($type_designations) {
|
1956
|
return $type_designations;
|
1957
|
}
|
1958
|
}
|
1959
|
|
1960
|
return array();
|
1961
|
}
|
1962
|
|
1963
|
|
1964
|
/**
|
1965
|
* Compares two SpecimenTypeDesignations
|
1966
|
*
|
1967
|
* @param object $a
|
1968
|
* A SpecimenTypeDesignation.
|
1969
|
* @param object $b
|
1970
|
* SpecimenTypeDesignation.
|
1971
|
*/
|
1972
|
function compare_specimen_type_designation($a, $b) {
|
1973
|
|
1974
|
$cmp_by_status = compare_type_designations_by_status($a,$b);
|
1975
|
if($cmp_by_status !== 0){
|
1976
|
return $cmp_by_status;
|
1977
|
}
|
1978
|
|
1979
|
$aQuantifier = FALSE;
|
1980
|
$bQuantifier = FALSE;
|
1981
|
if ($aQuantifier == $bQuantifier) {
|
1982
|
// Sort alphabetically.
|
1983
|
$a_text = isset($a->typeSpecimen->titleCache) ? preg_replace('/[\[\]\"]/', '', $a->typeSpecimen->titleCache) : '';
|
1984
|
$b_text = isset($b->typeSpecimen->titleCache) ? preg_replace('/[\[\]\"]/', '', $b->typeSpecimen->titleCache) : '';
|
1985
|
return strcasecmp($a_text, $b_text);
|
1986
|
}
|
1987
|
return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
|
1988
|
}
|
1989
|
|
1990
|
/**
|
1991
|
* Compares the status of two TypeDesignations
|
1992
|
*
|
1993
|
* @param object $a
|
1994
|
* A TypeDesignation
|
1995
|
* @param object $b
|
1996
|
* TypeDesignation
|
1997
|
*/
|
1998
|
function compare_type_designations_by_status($a, $b) {
|
1999
|
$status_a = isset($a->typeStatus) ? $a->typeStatus : null;
|
2000
|
$status_b = isset($b->typeStatus) ? $b->typeStatus : null;
|
2001
|
return compare_type_designation_status($status_a, $status_b);
|
2002
|
}
|
2003
|
|
2004
|
/**
|
2005
|
* Compares two TypeDesignationStatusBase
|
2006
|
*
|
2007
|
* @param object $a
|
2008
|
* A TypeDesignationStatusBase.
|
2009
|
* @param object $b
|
2010
|
* TypeDesignationStatusBase.
|
2011
|
*/
|
2012
|
function compare_type_designation_status($a, $b) {
|
2013
|
$type_status_order = type_status_order();
|
2014
|
$aQuantifier = FALSE;
|
2015
|
$bQuantifier = FALSE;
|
2016
|
if (isset($a->label) && isset($b->label)) {
|
2017
|
$aQuantifier = array_search($a->label, $type_status_order);
|
2018
|
$bQuantifier = array_search($b->label, $type_status_order);
|
2019
|
}
|
2020
|
return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
|
2021
|
}
|
2022
|
|
2023
|
/**
|
2024
|
* Compares the two TextualTypeDesignations
|
2025
|
*
|
2026
|
* @param object $a
|
2027
|
* A TextualTypeDesignations.
|
2028
|
* @param object $b
|
2029
|
* TextualTypeDesignations.
|
2030
|
*/
|
2031
|
function compare_textual_type_designation($a, $b) {
|
2032
|
|
2033
|
$cmp_by_status = compare_type_designations_by_status($a,$b);
|
2034
|
if($cmp_by_status !== 0){
|
2035
|
return $cmp_by_status;
|
2036
|
}
|
2037
|
|
2038
|
$aQuantifier = FALSE;
|
2039
|
$bQuantifier = FALSE;
|
2040
|
if ($aQuantifier == $bQuantifier) {
|
2041
|
// Sort alphabetically.
|
2042
|
$a_text = isset($a->text_L10n->text) ? $a->text_L10n->text : '';
|
2043
|
$b_text = isset($b->text_L10n->text) ? $b->text_L10n->text : '';
|
2044
|
return strcasecmp($a_text, $b_text);
|
2045
|
}
|
2046
|
return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
|
2047
|
}
|
2048
|
|
2049
|
|
2050
|
/**
|
2051
|
* Compares two SpecimenTypeDesignation status labels
|
2052
|
*
|
2053
|
* @param string $a
|
2054
|
* A TypeDesignationStatus label.
|
2055
|
* @param string $b
|
2056
|
* A TypeDesignationStatus label.
|
2057
|
*/
|
2058
|
function compare_type_designation_status_labels($a, $b) {
|
2059
|
|
2060
|
$type_status_order = type_status_order();
|
2061
|
|
2062
|
$aQuantifier = FALSE;
|
2063
|
$bQuantifier = FALSE;
|
2064
|
if (isset($a) && isset($b)) {
|
2065
|
$aQuantifier = array_search(ucfirst($a), $type_status_order);
|
2066
|
$bQuantifier = array_search(ucfirst($b), $type_status_order);
|
2067
|
}
|
2068
|
return ($aQuantifier < $bQuantifier) ? -1 : 1;
|
2069
|
}
|
2070
|
|
2071
|
/**
|
2072
|
* Preliminary implementation of a preset to define a sort order for
|
2073
|
* type designation status.
|
2074
|
*
|
2075
|
* TODO this is only preliminary and may break in future,
|
2076
|
* see https://dev.e-taxonomy.eu/redmine/issues/8402?issue_count=96&issue_position=4&next_issue_id=8351&prev_issue_id=7966#note-4
|
2077
|
* @return array
|
2078
|
* The array of orderd type labels
|
2079
|
*/
|
2080
|
function type_status_order()
|
2081
|
{
|
2082
|
/*
|
2083
|
This is the desired sort order as of now: Holotype Isotype Lectotype
|
2084
|
Isolectotype Syntype.
|
2085
|
TODO Basically, what we are trying to do is, we define
|
2086
|
an ordered array of TypeDesignation-states and use the index of this array
|
2087
|
for comparison. This array has to be filled with the cdm- TypeDesignation
|
2088
|
states and the order should be parameterisable inside the dataportal.
|
2089
|
*/
|
2090
|
static $type_status_order = array(
|
2091
|
'Epitype',
|
2092
|
'Holotype',
|
2093
|
'Isotype',
|
2094
|
'Lectotype',
|
2095
|
'Isolectotype',
|
2096
|
'Syntype',
|
2097
|
'Paratype'
|
2098
|
);
|
2099
|
return $type_status_order;
|
2100
|
}
|
2101
|
|
2102
|
/**
|
2103
|
* Return HTML for the lectotype citation with the correct layout.
|
2104
|
*
|
2105
|
* This function prints the lectotype citation with the correct layout.
|
2106
|
* Lectotypes are renderized in the synonymy tab of a taxon if they exist.
|
2107
|
*
|
2108
|
* @param mixed $typeDesignation
|
2109
|
* Object containing the lectotype citation to print.
|
2110
|
*
|
2111
|
* @return string
|
2112
|
* Valid html string.
|
2113
|
*/
|
2114
|
function type_designation_citation_layout($typeDesignation, $footnote_separator = ',') {
|
2115
|
$res = '';
|
2116
|
$citation = $typeDesignation->designationSource->citation;
|
2117
|
$pages = $typeDesignation->designationSource->citationMicroReference;
|
2118
|
if(isset($typeDesignation->typeStatus->uuid) && isset($typeDesignation->typeStatus->representation_L10n)) {
|
2119
|
if ( $typeDesignation->typeStatus->uuid == UUID_NTD_ORIGINAL_DESIGNATION || $typeDesignation->typeStatus->uuid == UUID_NTD_MONOTYPY) {
|
2120
|
$res = ' (' . $typeDesignation->typeStatus->representation_L10n . ')';
|
2121
|
return $res;
|
2122
|
}
|
2123
|
}
|
2124
|
|
2125
|
if ($citation) {
|
2126
|
// $type = $typeDesignation_citation->type;
|
2127
|
$year = isset($citation->datePublished->start) ? substr($citation->datePublished->start, 0, 4) : '';
|
2128
|
$author = isset($citation->authorship->titleCache) ? $citation->authorship->titleCache : '';
|
2129
|
$res .= ' (designated by ';
|
2130
|
$res .= $author;
|
2131
|
$res .= ($year ? ' ' . $year : '');
|
2132
|
$res .= ($pages ? ': ' . $pages : '');
|
2133
|
// $res .= ')';
|
2134
|
|
2135
|
// footnotes should be rendered in the parent element so we
|
2136
|
// are relying on the FootnoteListKey set there
|
2137
|
$fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation->titleCache);
|
2138
|
$res .= render_footnote_key($fkey_typeDesignation, $footnote_separator,TRUE) . ')';
|
2139
|
}
|
2140
|
return $res;
|
2141
|
}
|
2142
|
|
2143
|
/**
|
2144
|
* Creates markup for the status of a type designation. In case the status or its representation is missing the label will be set to "Type"
|
2145
|
*
|
2146
|
* @param $type_designation
|
2147
|
* @return string
|
2148
|
*/
|
2149
|
function type_designation_status_label_markup($type_designation)
|
2150
|
{
|
2151
|
return '<span class="type-status">'
|
2152
|
. ((isset($type_designation->typeStatus->representation_L10n)) ? ucfirst($type_designation->typeStatus->representation_L10n) : t('Type')) . '</span>'
|
2153
|
;
|
2154
|
}
|
2155
|
|
2156
|
/**
|
2157
|
* Creates markup for the status of a type designation DTO.
|
2158
|
* In case the status or its representation is missing the label will be set to "Type"
|
2159
|
*
|
2160
|
* @param $type_designation
|
2161
|
* @return string
|
2162
|
*/
|
2163
|
function type_designation_dto_status_label_markup($type_designation)
|
2164
|
{
|
2165
|
return '<span class="type-status">'
|
2166
|
. ((isset($type_designation->typeStatus_L10n)) ? ucfirst($type_designation->typeStatus_L10n) : t('Type')) . '</span>'
|
2167
|
;
|
2168
|
}
|