Project

General

Profile

« Previous | Next » 

Revision 9f9fe101

Added by Andreas Kohlbecker over 3 years ago

ref #8543 refactoring: renaming variables & moving functions to other files

View differences:

modules/cdm_dataportal/includes/common.inc
890 890
function icon_link($path, $fragment = '') {
891 891
  $iconlink = l(custom_icon_font_markup('icon-interal-link-alt-solid', ['class' => ['superscript']]), $path, ['html' => TRUE, 'fragment' => $fragment] );
892 892
  return $iconlink;
893
}
893
}
894

  
895

  
896
/**
897
 * @param $entity
898
 * @param $config array
899
 *   An associative array to configure the display of the annotations and
900
 *   sources. The array has the following keys
901
 *   - sources_as_content
902
 *   - link_to_name_used_in_source
903
 *   - link_to_reference
904
 *   - add_footnote_keys
905
 *   - bibliography_aware
906
 *   Valid values are 1 or 0.
907
 * @param $inline_text_prefix
908
 *   Only used to decide if the source references should be enclosed in
909
 *   brackets or not when displayed inline. This text will not be included into
910
 *   the response.
911
 * @param $footnote_list_key_suggestion string
912
 *    optional parameter. If this paramter is left empty (null, 0, "") the
913
 *   footnote key will be determined by the nested method calls by calling
914
 *   RenderHints::getFootnoteListKey(). NOTE: the footnore key for annotations
915
 *   will be set to RenderHints::getFootnoteListKey().FOOTNOTE_KEY_SUFFIX_ANNOTATIONS.
916
 * @return array
917
 * an associative array with the following elements:
918
 *   - foot_note_keys: all footnote keys as markup
919
 *   - source_references: an array of the source references citations
920
 *   - names used in source: an associative array of the names in source,
921
 *        the name in source strings are de-duplicated
922
 *        !!!NOTE!!!!: this field will most probably be removed soon (TODO)
923
 *
924
 */
925
function handle_annotations_and_sources($entity, $config, $inline_text_prefix, $footnote_list_key_suggestion) {
926

  
927
  $annotations_and_sources = array(
928
    'foot_note_keys' => NULL,
929
    'source_references' => [],
930
    'names_used_in_source' => []
931
  );
932

  
933
  // some entity types only have single sources:
934
  $sources = cdm_entity_sources_sorted($entity);
935

  
936
  if ($config['sources_as_content'] == 1) {
937
    foreach ($sources as $source) {
938
      if (_is_original_source_type($source)) {
939
        $reference_citation = render_original_source(
940
          $source,
941
          $config['link_to_reference'] == 1,
942
          $config['link_to_name_used_in_source'] == 1
943
        );
944

  
945
        if ($reference_citation) {
946
          if (empty($inline_text_prefix)) {
947
            $annotations_and_sources['source_references'][] = $reference_citation;
948
          } else {
949
            $annotations_and_sources['source_references'][] = ' (' . $reference_citation . ')';
950
          }
951
        }
952

  
953
        // also put the name in source into the array, these are already included in the $reference_citation but are
954
        // still required to be available separately in some contexts.
955
        $name_in_source_render_array = compose_name_in_source(
956
          $source,
957
          $config['link_to_name_used_in_source'] == 1
958
        );
959

  
960
        if (!empty($name_in_source_render_array)) {
961
          $annotations_and_sources['names_used_in_source'][$name_in_source_render_array['#_plaintext']] = drupal_render($name_in_source_render_array);
962
        }
963
      }
964
    } // END of loop over sources
965

  
966
    // annotations footnotes separate from sources
967
    $annotations_and_sources['foot_note_keys'] = render_footnote_keys(
968
      cdm_entity_annotations_as_footnote_keys($entity, $footnote_list_key_suggestion), ', '
969
    );
970

  
971
  } // END of references inline
972

  
973
  // footnotes for sources and annotations or put into into bibliography if requested ...
974
  if ($config['add_footnote_keys'] == 1) {
975
    $annotations_and_sources['foot_note_keys'] = render_entity_footnotes(
976
      $entity, ',',
977
      $footnote_list_key_suggestion,
978
      $config['link_to_reference'] == 1,
979
      $config['link_to_name_used_in_source'] == 1,
980
      !empty($config['bibliography_aware'])
981
    );
982
  }
983

  
984
  return $annotations_and_sources;
985
}
986

  
987
/**
988
 * Get the source or the sources from a cdm entity and return them ordered by see compare_original_sources()
989
 * (Some entity types only have single sources)
990
 * @param $entity
991
 *
992
 * @return array
993
 */
994
function cdm_entity_sources_sorted($entity) {
995
  if (isset($entity->source) && is_object($entity->source)) {
996
    $sources = [$entity->source];
997
  }
998
  else if (isset($entity->sources)) {
999
    $sources = $entity->sources;
1000
  }
1001
  else {
1002
    $sources = [];
1003
  }
1004
  usort($sources, 'compare_original_sources');
1005
  return $sources;
1006
}
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
/**
modules/cdm_dataportal/includes/footnotes.inc
20 20
 * Creates the footnotes for the given CDM instance.
21 21
 *
22 22
 * Footnotes are created for annotations and original sources whereas the resulting footnote keys depend on the
23
 * parameters $footnote_list_key_suggestion and $is_bibliography_aware, see parameter $footnote_list_key_suggestion
23
 * parameters $footnote_list_key and $is_bibliography_aware, see parameter $footnote_list_key
24 24
 * for more details.
25 25
 *
26 26
 * possible keys for annotation and source footnotes:
27
 *       - $footnote_list_key_suggestion
27
 *       - $footnote_list_key
28 28
 *       - RenderHints::getFootnoteListKey()
29 29
 *     - original source footnotes
30 30
 *       - "BIBLIOGRAPHY" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 1 )
31
 *       - "BIBLIOGRAPHY-$footnote_list_key_suggestion" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 )
32
 *       - $footnote_list_key_suggestion (when $is_bibliography_aware)
31
 *       - "BIBLIOGRAPHY-$footnote_list_key" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 )
32
 *       - $footnote_list_key (when $is_bibliography_aware)
33 33
 *
34 34
 * @param $cdm_entity
35 35
 *   A CDM entity
36 36
 * @param string $separator
37 37
 *   Optional parameter. The separator string to concatenate the footnote ids, default is ','
38
 * @param $footnote_list_key_suggestion string
38
 * @param $footnote_list_key string
39 39
 *    Optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined by the nested
40 40
 *    method calls by calling RenderHints::getFootnoteListKey().
41
 *    For original sources the $footnote_list_key_suggestion will be overwritten by bibliography_footnote_list_key() when
41
 *    For original sources the $footnote_list_key will be overwritten by bibliography_footnote_list_key() when
42 42
 *    $is_bibliography_aware is set TRUE.
43 43
 * @param bool $do_link_to_reference
44 44
 *    Create a link to the reference pages for sources when TRUE.
......
46 46
 *    Create a link to the name pages for name in source when TRUE.
47 47
 * @param bool $is_bibliography_aware
48 48
 *    Put source references into the bibliography when this param is TRUE.
49
 *    For original sources the $footnote_list_key_suggestion will be overwritten
49
 *    For original sources the $footnote_list_key will be overwritten
50 50
 *    by bibliography_footnote_list_key() when
51 51
 *    $is_bibliography_aware is set TRUE.
52 52
 * @return String
......
57 57
function render_entity_footnotes(
58 58
  $cdm_entity,
59 59
  $separator = ',',
60
  $footnote_list_key_suggestion = null,
60
  $footnote_list_key = null,
61 61
  $do_link_to_reference = FALSE,
62 62
  $do_link_to_name_used_in_source = FALSE,
63 63
  $is_bibliography_aware = FALSE
......
65 65

  
66 66
  $sources = cdm_entity_sources_sorted($cdm_entity);
67 67

  
68
  if (!isset($footnote_list_key_suggestion) || !$footnote_list_key_suggestion) {
69
    $footnote_list_key_suggestion = RenderHints::getFootnoteListKey();
68
  if (!isset($footnote_list_key) || !$footnote_list_key) {
69
    $footnote_list_key = RenderHints::getFootnoteListKey();
70 70
  }
71 71

  
72 72
  // Annotations as footnotes.
73
  $footnote_keys = cdm_entity_annotations_as_footnote_keys($cdm_entity, $footnote_list_key_suggestion);
73
  $footnote_keys = cdm_entity_annotations_as_footnote_keys($cdm_entity, $footnote_list_key);
74 74

  
75 75
  // Source references as footnotes.
76 76
  if($is_bibliography_aware){
77 77
    $bibliography_settings = get_bibliography_settings();
78
    $sources_footnote_list_key = bibliography_footnote_list_key($footnote_list_key_suggestion);
78
    $sources_footnote_list_key = bibliography_footnote_list_key($footnote_list_key);
79 79
    $original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // null will cause bibliography_footnote_list_key to use the default
80 80
  } else {
81
    $sources_footnote_list_key = $footnote_list_key_suggestion;
81
    $sources_footnote_list_key = $footnote_list_key;
82 82
    $original_source_footnote_tag = NULL;
83 83
  }
84 84

  
......
238 238
  return $out;
239 239
}
240 240

  
241
/**
242
 * This method determines the footnote key for original sources to be shown in the bibliography block
243
 *
244
 * The footnote key depends on the value of the 'enabled' value of the bibliography_settings
245
 *    - enabled == 1 -> "BIBLIOGRAPHY"
246
 *    - enabled == 0 -> "BIBLIOGRAPHY-$key_suggestion"
247
 *
248
 * @see get_bibliography_settings() and @see constant BIBLIOGRAPHY_FOOTNOTE_KEY
249
 *
250
 * @param $key_suggestion string
251
 *    optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be retrieved by
252
 *    calling RenderHints::getFootnoteListKey().
253

  
254
 *
255
 * @return string
256
 *  the footnote_list_key
257
 */
258
function bibliography_footnote_list_key($key_suggestion = null) {
259
  if(!$key_suggestion){
260
    $key_suggestion = RenderHints::getFootnoteListKey();
261
  }
262
  $bibliography_settings = get_bibliography_settings();
263
  $footnote_list_key = $bibliography_settings['enabled'] == 1 ? BIBLIOGRAPHY_FOOTNOTE_KEY : BIBLIOGRAPHY_FOOTNOTE_KEY . '-' . $key_suggestion;
264
  return $footnote_list_key;
265
}
266

  
267

  

Also available in: Unified diff