Revision fe064e2d
Added by Andreas Kohlbecker over 3 years ago
modules/cdm_dataportal/includes/footnotes.inc | ||
---|---|---|
15 | 15 |
* @author |
16 | 16 |
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org> |
17 | 17 |
*/ |
18 |
const FOOTNOTE_KEY_SUFFIX_ANNOTATIONS = '-annotations'; |
|
18 | 19 |
|
19 | 20 |
/** |
20 | 21 |
* Creates the footnotes for the given CDM instance. |
... | ... | |
26 | 27 |
* possible keys for |
27 | 28 |
* - annotation footnotes: |
28 | 29 |
* - $footnote_list_key_suggestion |
29 |
* - RenderHints::getFootnoteListKey().'-annotations'
|
|
30 |
* - RenderHints::getFootnoteListKey().FOOTNOTE_KEY_SUFFIX_ANNOTATIONS
|
|
30 | 31 |
* - original source footnotes |
31 | 32 |
* - "BIBLIOGRAPHY" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 1 ) |
32 | 33 |
* - "BIBLIOGRAPHY-$footnote_list_key_suggestion" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 ) |
33 | 34 |
* - $footnote_list_key_suggestion (when $is_bibliography_aware) |
34 | 35 |
* |
35 |
* @param $description_element
|
|
36 |
* A CDM DescriptionElement instance
|
|
36 |
* @param $cdm_entity
|
|
37 |
* A CDM entity
|
|
37 | 38 |
* @param string $separator |
38 | 39 |
* Optional parameter. The separator string to concatenate the footnote ids, default is ',' |
39 | 40 |
* @param $footnote_list_key_suggestion string |
... | ... | |
51 | 52 |
* The foot note keys |
52 | 53 |
* |
53 | 54 |
* @throws \Exception re-throw exception from theme() |
54 |
* @see cdm_entities_annotations_footnotekeys() |
|
55 |
* @see cdm_entities_annotations_footnote_keys()
|
|
55 | 56 |
* For original sources the $footnote_list_key_suggestion will be overwritten by bibliography_footnote_list_key() when |
56 | 57 |
* $is_bibliography_aware is set TRUE. |
57 | 58 |
* @$original_source_footnote_tag |
58 | 59 |
* null will cause bibliography_footnote_list_key to use the default |
59 | 60 |
*/ |
60 |
function cdm_create_footnotes(
|
|
61 |
$description_element,
|
|
61 |
function cdm_entity_footnotes(
|
|
62 |
$cdm_entity,
|
|
62 | 63 |
$separator = ',', |
63 | 64 |
$footnote_list_key_suggestion = null, |
64 | 65 |
$do_link_to_reference = FALSE, |
... | ... | |
66 | 67 |
$is_bibliography_aware = FALSE |
67 | 68 |
){ |
68 | 69 |
|
69 |
$sources = cdm_entity_sources_sorted($description_element);
|
|
70 |
$sources = cdm_entity_sources_sorted($cdm_entity);
|
|
70 | 71 |
|
71 | 72 |
// Annotations as footnotes. |
72 |
$footnote_keys = cdm_entity_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
|
|
73 |
$footnote_keys = cdm_entity_annotations_as_footnote_keys($cdm_entity, $footnote_list_key_suggestion);
|
|
73 | 74 |
|
74 | 75 |
// Source references as footnotes. |
75 | 76 |
if($is_bibliography_aware){ |
... | ... | |
96 | 97 |
$original_source_footnote_tag |
97 | 98 |
); |
98 | 99 |
// Ensure uniqueness of the footnote keys. |
99 |
cdm_add_footnote_to_array($footnote_keys, $fn_key); |
|
100 |
if(array_search($fn_key, $footnote_keys)=== false) { |
|
101 |
$footnote_keys[] = $fn_key; |
|
102 |
} |
|
100 | 103 |
} |
101 | 104 |
} |
102 | 105 |
// Sort and render footnote keys. |
... | ... | |
115 | 118 |
* An array of CdmBase instances. |
116 | 119 |
* @param $footnote_list_key_suggestion string |
117 | 120 |
* optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to |
118 |
* RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied key will be used.
|
|
121 |
* RenderHints::getFootnoteListKey().FOOTNOTE_KEY_SUFFIX_ANNOTATIONS otherwise the supplied key will be used.
|
|
119 | 122 |
* |
120 | 123 |
* @return array of footnote keys |
121 | 124 |
*/ |
122 |
function cdm_entities_annotations_footnotekeys(array $cdm_entities, $footnote_list_key_suggestion = NULL) { |
|
125 |
function cdm_entities_annotations_footnote_keys(array $cdm_entities, $footnote_list_key_suggestion = NULL) {
|
|
123 | 126 |
|
124 | 127 |
$foot_note_keys = []; |
125 | 128 |
foreach ($cdm_entities as $cdm_entity) { |
126 |
$foot_note_keys = array_merge($foot_note_keys, cdm_entity_annotations_as_footnotekeys($cdm_entity,$footnote_list_key_suggestion)); |
|
129 |
$foot_note_keys = array_merge($foot_note_keys, cdm_entity_annotations_as_footnote_keys($cdm_entity,$footnote_list_key_suggestion));
|
|
127 | 130 |
} |
128 | 131 |
|
129 | 132 |
return $foot_note_keys; |
... | ... | |
145 | 148 |
* |
146 | 149 |
* @see cdm_fetch_visible_annotations() |
147 | 150 |
*/ |
148 |
function cdm_entity_annotations_as_footnotekeys(stdClass $cdm_entity, $footnote_list_key_suggestion = NULL) { |
|
151 |
function cdm_entity_annotations_as_footnote_keys(stdClass $cdm_entity, $footnote_list_key_suggestion = NULL) {
|
|
149 | 152 |
|
150 | 153 |
$foot_note_keys = []; |
151 | 154 |
|
... | ... | |
153 | 156 |
if (isset($footnote_list_key_suggestion)) { |
154 | 157 |
$footnote_list_key = $footnote_list_key_suggestion; |
155 | 158 |
} else { |
156 |
$footnote_list_key = RenderHints::getFootnoteListKey() . '-annotations';
|
|
159 |
$footnote_list_key = RenderHints::getFootnoteListKey() . FOOTNOTE_KEY_SUFFIX_ANNOTATIONS;
|
|
157 | 160 |
} |
158 | 161 |
|
159 | 162 |
// Adding the footnotes keys. |
... | ... | |
188 | 191 |
return $footnotes_markup; |
189 | 192 |
} |
190 | 193 |
|
191 |
/** |
|
192 |
* @todo Please document this function. |
|
193 |
* @see http://drupal.org/node/1354 |
|
194 |
*/ |
|
195 |
function cdm_add_footnote_to_array(&$footnote_list, $footnote) { |
|
196 |
if (!cdm_exist_footnote($footnote_list, $footnote)) { |
|
197 |
$footnote_list[] = $footnote; |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
|
|
202 | 194 |
/** |
203 | 195 |
* Create markup for the footnotes mapped to the $footnoteListKey. |
204 | 196 |
* |
... | ... | |
214 | 206 |
if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) { |
215 | 207 |
return ''; |
216 | 208 |
} |
217 |
return cdm_footnotes($footnote_list_key . '-annotations', $element_tag);
|
|
209 |
return cdm_footnotes($footnote_list_key . FOOTNOTE_KEY_SUFFIX_ANNOTATIONS, $element_tag);
|
|
218 | 210 |
} |
219 | 211 |
|
220 | 212 |
/** |
... | ... | |
311 | 303 |
} |
312 | 304 |
|
313 | 305 |
$out = '<' . $enclosingTag . ' class="footnotes footnotes-' . $footnote_list_key . ' ">' |
314 |
. FootnoteManager::renderFootnoteList($footnote_list_key . '-annotations') . ' ' . FootnoteManager::renderFootnoteList($footnote_list_key)
|
|
306 |
. FootnoteManager::renderFootnoteList($footnote_list_key . FOOTNOTE_KEY_SUFFIX_ANNOTATIONS) . ' ' . FootnoteManager::renderFootnoteList($footnote_list_key)
|
|
315 | 307 |
. '</' . $enclosingTag . '>'; |
316 |
FootnoteManager::removeFootnoteList($footnote_list_key . '-annotations');
|
|
308 |
FootnoteManager::removeFootnoteList($footnote_list_key . FOOTNOTE_KEY_SUFFIX_ANNOTATIONS);
|
|
317 | 309 |
FootnoteManager::removeFootnoteList($footnote_list_key); |
318 | 310 |
return $out; |
319 | 311 |
} |
320 |
|
|
321 |
/** |
|
322 |
* @todo Please document this function. |
|
323 |
* @see http://drupal.org/node/1354 |
|
324 |
*/ |
|
325 |
function cdm_exist_footnote($footnote_list, $footnote) { |
|
326 |
$result = FALSE; |
|
327 |
if (is_array($footnote_list)) { |
|
328 |
foreach ($footnote_list as $element) { |
|
329 |
if ($element == $footnote) { |
|
330 |
$result = TRUE; |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
return $result; |
|
335 |
} |
Also available in: Unified diff
ref #8543 removing useless code and cleaner footnote functions