Project

General

Profile

« Previous | Next » 

Revision 38a98e54

Added by Andreas Kohlbecker about 3 years ago

ref #6866 showing unit annotations (AnnotationsAndSources supports annotations a content now)

View differences:

modules/cdm_dataportal/classes/AnnotationsAndSources.php
20 20
   */
21 21
  private $sourceReferences = [];
22 22

  
23
  /**
24
   * This field is being used when annotations are not handled as footnotes
25
   *
26
   * @var array
27
   *  an array of the annotations markup
28
   */
29
  private $annotations = [];
30

  
31
  /**
32
   * @return array
33
   */
34
  public function getAnnotations() {
35
    return $this->annotations;
36
  }
37

  
38
  /**
39
   * @param array $annotations
40
   */
41
  public function setAnnotations($annotations) {
42
    $this->annotations = $annotations;
43
  }
44

  
23 45
  /**
24 46
   * @var array an associative array of the names in source,
25 47
   *        the name in source strings are de-duplicated
modules/cdm_dataportal/classes/footnote.php
45 45

  
46 46
    return render_footnote($this->key, $this->object, $enclosing_tag, $footnote_list_key);
47 47
  }
48

  
49
  /**
50
   * @return string
51
   *  The footnote text or markup
52
   */
53
  public function getContent(){
54
    return $this->object;
55
  }
48 56
}
modules/cdm_dataportal/classes/footnotemanager.php
103 103
    return $out;
104 104
  }
105 105

  
106
  /**
107
   * Provides the content of foot notes
108
   *
109
   * @param string $footnoteListKey
110
   *
111
   * @return array
112
   *   The content of foot notes or an empty array if the $footnoteListKey is
113
   *   blocked
114
   */
115
  public static function footnoteListContents($footnoteListKey) {
116

  
117
    if(self::isBlockedFootnoteListKey($footnoteListKey)){
118
      // the footnote key is blocked, don't render it!
119
      return [];
120
    }
121
    $content_list = [];
122
    if (array_key_exists($footnoteListKey, self::$fnstore)) {
123
      foreach (self::$fnstore[$footnoteListKey] as $fn) {
124
        $content_list[] = $fn->getContent();
125
      }
126
    }
127
    return $content_list;
128
  }
129

  
106 130
  /**
107 131
   * Add a new footnote.
108 132
   *
modules/cdm_dataportal/includes/footnotes.inc
49 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
 * @param bool $add_annotations
53
 *    Footnotes for annotations will not be created if this is FALSE
54
 *
52 55
 * @return array
53 56
 *   An array of the footnote keys for the supplied cdm entity
54 57
 *
......
59 62
  $footnote_list_key = NULL,
60 63
  $do_link_to_reference = FALSE,
61 64
  $do_link_to_name_used_in_source = FALSE,
62
  $is_bibliography_aware = FALSE
65
  $is_bibliography_aware = FALSE,
66
  $add_annotations = TRUE
63 67
){
64 68

  
65 69
  $sources = cdm_entity_sources_sorted($cdm_entity);
......
69 73
  }
70 74

  
71 75
  // Annotations as footnotes.
72
  $footnote_keys = cdm_entity_annotations_as_footnote_keys($cdm_entity, $footnote_list_key);
76
  if($add_annotations){
77
    $footnote_keys = cdm_entity_annotations_as_footnote_keys($cdm_entity, $footnote_list_key);
78
  }
73 79

  
74 80
  // Source references as footnotes.
75 81
  if($is_bibliography_aware){
......
139 145
  return $foot_note_keys;
140 146
}
141 147

  
148
/**
149
 * Fetches the list of visible annotations for the cdm entity or for the comparable
150
 * object and returns a list of the annotation texts
151
 *
152
 * @param stdClass $cdm_entity
153
 *   A single CdmBase instance ore comparable object.
154
 *
155
 * @see cdm_fetch_visible_annotations()
156
 */
157
function cdm_entity_annotations_as_content(stdClass $cdm_entity) {
158

  
159
  $annotation_texts = [];
160
  $annotations = cdm_fetch_visible_annotations($cdm_entity);
161
  if (is_array($annotations)) {
162
    foreach ($annotations as $annotation) {
163
      if($annotation->text){
164
        $annotation_texts[] = $annotation->text;
165
      }
166
    }
167
  }
168
  return $annotation_texts;
169
}
170

  
142 171
/**
143 172
 * Creates markup for an array of foot note keys
144 173
 *
......
346 375

  
347 376
const ANNOTATIONS_AND_SOURCE_CONFIG_DEFAULT = [
348 377
  'sources_as_content' => FALSE,
378
  'annotations_as_content' => FALSE,
349 379
  'link_to_name_used_in_source' => TRUE,
350 380
  'link_to_reference' => TRUE,
351 381
  'add_footnote_keys' => TRUE,
......
528 558
  } // END of references inline
529 559

  
530 560
  // footnotes for sources and annotations or put into into bibliography if requested ...
561
  $do_foonotes_as_content = isset($config['annotations_as_content']) && $config['annotations_as_content'];
562
  if($do_foonotes_as_content){
563
    $annotationsAndSources->setAnnotations(cdm_entity_annotations_as_content($entity));
564
  }
531 565
  if ($config['add_footnote_keys']) {
532 566
    $annotationsAndSources->addAllFootNoteKeys(cdm_entity_footnotes(
533 567
      $entity,
534 568
      $footnote_list_key_suggestion,
535 569
      $config['link_to_reference'],
536 570
      $config['link_to_name_used_in_source'],
537
      (!empty($config['bibliography_aware']) ? $config['bibliography_aware'] : FALSE)
571
      (!empty($config['bibliography_aware']) ? $config['bibliography_aware'] : FALSE),
572
      !$do_foonotes_as_content
538 573
    ));
539 574
  }
540 575
  return $annotationsAndSources;
......
557 592
  else {
558 593
    // try to load the sources
559 594
    if(isset_not_empty($entity->uuid)){
560
      $sources = cdm_ws_fetch_all(cdm_compose_ws_url('portal/' . cdm_ws_base_uri($entity->class), [ $entity->uuid, 'sources']));
595
      $sources = cdm_ws_fetch_all(cdm_compose_url('portal/' . cdm_ws_base_uri($entity->class), [ $entity->uuid, 'sources']));
561 596
    } else {
562 597
      // this may happen with DerivedUnitFaced, also with others?
563 598
      $sources = [];
modules/cdm_dataportal/includes/occurrences_new.inc
76 76
    // Annotations and Sources
77 77
    RenderHints::setAnnotationsAndSourceConfig([
78 78
      'sources_as_content' => TRUE,
79
      'annotations_as_content' => TRUE,
79 80
      'link_to_name_used_in_source' => TRUE,
80 81
      'link_to_reference' => FALSE,
81 82
      'add_footnote_keys' => FALSE,
......
85 86
    if ($annotations_and_sources->hasSourceReferences()) {
86 87
      $render_array['sources'] = compose_cdm_sob_dto_sources($sob_dto, $annotations_and_sources);
87 88
    }
89

  
90
    if(count($annotations_and_sources->getAnnotations()) > 0){
91
      $render_array['annotations'] = compose_cdm_sob_dto_annotations($sob_dto, $annotations_and_sources);
92
    }
88 93
      // Markers
89 94
    $markers = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, [$sob_dto->uuid, 'markers']);
90 95
    if(isset_not_empty($markers->records)){
......
468 473
  return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
469 474
}
470 475

  
476
/**
477
 * @param $sob_dto
478
 * @param \AnnotationsAndSources $annotations_and_sources
479
 *
480
 * @return array|null
481
 */
482
function compose_cdm_sob_dto_annotations($sob_dto, $annotations_and_sources) {
483

  
484
  $table_row_data = [];
485

  
486
  foreach ($annotations_and_sources->getAnnotations() as $annotation_text) {
487
    $table_row_data[] = cdm_sob_dto_table_row(NULL, $annotation_text);
488
  }
489

  
490
  $label = count($table_row_data) > 1 ? t("Annotations") : t("Annotation");
491
  return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
492
}
493

  
471 494
function compose_cdm_sob_dto_markers($sob_dto, $markers) {
472 495

  
473 496
  $table_row_data = [];

Also available in: Unified diff