Revision 9f9fe101
Added by Andreas Kohlbecker over 3 years ago
modules/cdm_dataportal/includes/descriptions.inc | ||
---|---|---|
453 | 453 |
return $config; |
454 | 454 |
} |
455 | 455 |
|
456 |
/** |
|
457 |
* @param $entity |
|
458 |
* @param $config array |
|
459 |
* An associative array to configure the display of the annotations and |
|
460 |
* sources. The array has the following keys |
|
461 |
* - sources_as_content |
|
462 |
* - link_to_name_used_in_source |
|
463 |
* - link_to_reference |
|
464 |
* - add_footnote_keys |
|
465 |
* - bibliography_aware |
|
466 |
* Valid values are 1 or 0. |
|
467 |
* @param $inline_text_prefix |
|
468 |
* Only used to decide if the source references should be enclosed in |
|
469 |
* brackets or not when displayed inline. This text will not be included into |
|
470 |
* the response. |
|
471 |
* @param $footnote_list_key_suggestion string |
|
472 |
* optional parameter. If this paramter is left empty (null, 0, "") the |
|
473 |
* footnote key will be determined by the nested method calls by calling |
|
474 |
* RenderHints::getFootnoteListKey(). NOTE: the footnore key for annotations |
|
475 |
* will be set to RenderHints::getFootnoteListKey().FOOTNOTE_KEY_SUFFIX_ANNOTATIONS. |
|
476 |
* @return array |
|
477 |
* an associative array with the following elements: |
|
478 |
* - foot_note_keys: all footnote keys as markup |
|
479 |
* - source_references: an array of the source references citations |
|
480 |
* - names used in source: an associative array of the names in source, |
|
481 |
* the name in source strings are de-duplicated |
|
482 |
* !!!NOTE!!!!: this field will most probably be removed soon (TODO) |
|
483 |
* |
|
484 |
*/ |
|
485 |
function handle_annotations_and_sources($entity, $config, $inline_text_prefix, $footnote_list_key_suggestion) { |
|
486 |
|
|
487 |
$annotations_and_sources = array( |
|
488 |
'foot_note_keys' => NULL, |
|
489 |
'source_references' => [], |
|
490 |
'names_used_in_source' => [] |
|
491 |
); |
|
492 |
|
|
493 |
// some entity types only have single sources: |
|
494 |
$sources = cdm_entity_sources_sorted($entity); |
|
495 |
|
|
496 |
if ($config['sources_as_content'] == 1) { |
|
497 |
foreach ($sources as $source) { |
|
498 |
if (_is_original_source_type($source)) { |
|
499 |
$reference_citation = render_original_source( |
|
500 |
$source, |
|
501 |
$config['link_to_reference'] == 1, |
|
502 |
$config['link_to_name_used_in_source'] == 1 |
|
503 |
); |
|
504 |
|
|
505 |
if ($reference_citation) { |
|
506 |
if (empty($inline_text_prefix)) { |
|
507 |
$annotations_and_sources['source_references'][] = $reference_citation; |
|
508 |
} else { |
|
509 |
$annotations_and_sources['source_references'][] = ' (' . $reference_citation . ')'; |
|
510 |
} |
|
511 |
} |
|
512 |
|
|
513 |
// also put the name in source into the array, these are already included in the $reference_citation but are |
|
514 |
// still required to be available separately in some contexts. |
|
515 |
$name_in_source_render_array = compose_name_in_source( |
|
516 |
$source, |
|
517 |
$config['link_to_name_used_in_source'] == 1 |
|
518 |
); |
|
519 |
|
|
520 |
if (!empty($name_in_source_render_array)) { |
|
521 |
$annotations_and_sources['names_used_in_source'][$name_in_source_render_array['#_plaintext']] = drupal_render($name_in_source_render_array); |
|
522 |
} |
|
523 |
} |
|
524 |
} // END of loop over sources |
|
525 |
|
|
526 |
// annotations footnotes separate from sources |
|
527 |
$annotations_and_sources['foot_note_keys'] = render_footnote_keys( |
|
528 |
cdm_entity_annotations_as_footnote_keys($entity, $footnote_list_key_suggestion), ', ' |
|
529 |
); |
|
530 |
|
|
531 |
} // END of references inline |
|
532 |
|
|
533 |
// footnotes for sources and annotations or put into into bibliography if requested ... |
|
534 |
if ($config['add_footnote_keys'] == 1) { |
|
535 |
$annotations_and_sources['foot_note_keys'] = render_entity_footnotes( |
|
536 |
$entity, ',', |
|
537 |
$footnote_list_key_suggestion, |
|
538 |
$config['link_to_reference'] == 1, |
|
539 |
$config['link_to_name_used_in_source'] == 1, |
|
540 |
!empty($config['bibliography_aware']) |
|
541 |
); |
|
542 |
} |
|
543 |
|
|
544 |
return $annotations_and_sources; |
|
545 |
} |
|
546 |
|
|
547 |
/** |
|
548 |
* Get the source or the sources from a cdm entity and return them ordered by see compare_original_sources() |
|
549 |
* (Some entity types only have single sources) |
|
550 |
* @param $entity |
|
551 |
* |
|
552 |
* @return array |
|
553 |
*/ |
|
554 |
function cdm_entity_sources_sorted($entity) { |
|
555 |
if (isset($entity->source) && is_object($entity->source)) { |
|
556 |
$sources = [$entity->source]; |
|
557 |
} |
|
558 |
else if (isset($entity->sources)) { |
|
559 |
$sources = $entity->sources; |
|
560 |
} |
|
561 |
else { |
|
562 |
$sources = []; |
|
563 |
} |
|
564 |
usort($sources, 'compare_original_sources'); |
|
565 |
return $sources; |
|
566 |
} |
|
567 |
|
|
568 |
|
|
569 |
/** |
|
570 |
* This method determines the footnote key for original sources to be shown in the bibliography block |
|
571 |
* |
|
572 |
* The footnote key depends on the value of the 'enabled' value of the bibliography_settings |
|
573 |
* - enabled == 1 -> "BIBLIOGRAPHY" |
|
574 |
* - enabled == 0 -> "BIBLIOGRAPHY-$key_suggestion" |
|
575 |
* |
|
576 |
* @see get_bibliography_settings() and @see constant BIBLIOGRAPHY_FOOTNOTE_KEY |
|
577 |
* |
|
578 |
* @param $key_suggestion string |
|
579 |
* optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be retrieved by |
|
580 |
* calling RenderHints::getFootnoteListKey(). |
|
581 |
|
|
582 |
* |
|
583 |
* @return string |
|
584 |
* the footnote_list_key |
|
585 |
*/ |
|
586 |
function bibliography_footnote_list_key($key_suggestion = null) { |
|
587 |
if(!$key_suggestion){ |
|
588 |
$key_suggestion = RenderHints::getFootnoteListKey(); |
|
589 |
} |
|
590 |
$bibliography_settings = get_bibliography_settings(); |
|
591 |
$footnote_list_key = $bibliography_settings['enabled'] == 1 ? BIBLIOGRAPHY_FOOTNOTE_KEY : BIBLIOGRAPHY_FOOTNOTE_KEY . '-' . $key_suggestion; |
|
592 |
return $footnote_list_key; |
|
593 |
} |
|
594 |
|
|
595 | 456 |
/** |
596 | 457 |
* Provides the according tag name for the description element markup which |
597 | 458 |
* fits the $feature_block_settings['as_list'] value |
... | ... | |
1672 | 1533 |
* The CDM CommonTaxonName entity. |
1673 | 1534 |
* @param $feature_block_settings |
1674 | 1535 |
* |
1675 |
* @param $footnote_key_suggestion |
|
1676 |
* |
|
1677 |
* @param $element_tag_name |
|
1536 |
* @param $footnote_key |
|
1678 | 1537 |
* |
1679 | 1538 |
* @return array |
1680 | 1539 |
* Drupal render array |
1681 | 1540 |
* |
1682 | 1541 |
* @ingroup compose |
1683 | 1542 |
*/ |
1684 |
function compose_description_element_common_taxon_name($element, $feature_block_settings, $footnote_key_suggestion = NULL)
|
|
1543 |
function compose_description_element_common_taxon_name($element, $feature_block_settings, $footnote_key = NULL) |
|
1685 | 1544 |
{ |
1686 | 1545 |
|
1687 |
if(!$footnote_key_suggestion) {
|
|
1688 |
$footnote_key_suggestion = $element->feature->uuid;
|
|
1546 |
if(!$footnote_key) { |
|
1547 |
$footnote_key = $element->feature->uuid; |
|
1689 | 1548 |
} |
1690 | 1549 |
|
1691 | 1550 |
$name = ''; |
... | ... | |
1694 | 1553 |
} |
1695 | 1554 |
|
1696 | 1555 |
|
1697 |
return compose_description_element($element, $feature_block_settings, $name, $footnote_key_suggestion);
|
|
1556 |
return compose_description_element($element, $feature_block_settings, $name, $footnote_key); |
|
1698 | 1557 |
} |
1699 | 1558 |
|
1700 | 1559 |
/** |
Also available in: Unified diff
ref #8543 refactoring: renaming variables & moving functions to other files