Revision dd0767b6
Added by Andreas Kohlbecker over 3 years ago
modules/cdm_dataportal/includes/descriptions.inc | ||
---|---|---|
333 | 333 |
return $item; |
334 | 334 |
} |
335 | 335 |
|
336 |
/** |
|
337 |
* Creates the footnotes for the given CDM instance. |
|
338 |
* |
|
339 |
* Footnotes are created for annotations and original sources whereas the resulting footnote keys depend on the |
|
340 |
* parameters $footnote_list_key_suggestion and $is_bibliography_aware, see parameter $footnote_list_key_suggestion |
|
341 |
* for more details. |
|
342 |
* |
|
343 |
* possible keys for |
|
344 |
* - annotation footnotes: |
|
345 |
* - $footnote_list_key_suggestion |
|
346 |
* - RenderHints::getFootnoteListKey().'-annotations' |
|
347 |
* - original source footnotes |
|
348 |
* - "BIBLIOGRAPHY" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 1 ) |
|
349 |
* - "BIBLIOGRAPHY-$footnote_list_key_suggestion" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 ) |
|
350 |
* - $footnote_list_key_suggestion (when $is_bibliography_aware) |
|
351 |
* |
|
352 |
* @param $description_element |
|
353 |
* A CDM DescriptionElement instance |
|
354 |
* @param string $separator |
|
355 |
* Optional parameter. The separator string to concatenate the footnote ids, default is ',' |
|
356 |
* @param $footnote_list_key_suggestion string |
|
357 |
* Optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined by the nested |
|
358 |
* method calls by calling RenderHints::getFootnoteListKey(). NOTE: the footnote key for annotations will be set to |
|
359 |
* RenderHints::getFootnoteListKey().'-annotations'. |
|
360 |
* @param bool $do_link_to_reference |
|
361 |
* Create a link to the reference pages for sources when TRUE. |
|
362 |
* @param bool $do_link_to_name_used_in_source |
|
363 |
* Create a link to the name pages for name in source when TRUE. |
|
364 |
* @param bool $is_bibliography_aware |
|
365 |
* Put source references into the bibliography when this param is TRUE. |
|
366 |
* |
|
367 |
* @return String |
|
368 |
* The foot note keys |
|
369 |
* |
|
370 |
* @throws \Exception re-throw exception from theme() |
|
371 |
* @see cdm_entities_annotations_footnotekeys() |
|
372 |
* For original sources the $footnote_list_key_suggestion will be overwritten by bibliography_footnote_list_key() when |
|
373 |
* $is_bibliography_aware is set TRUE. |
|
374 |
* @$original_source_footnote_tag |
|
375 |
* null will cause bibliography_footnote_list_key to use the default |
|
376 |
*/ |
|
377 |
function cdm_create_footnotes( |
|
378 |
$description_element, |
|
379 |
$separator = ',', |
|
380 |
$footnote_list_key_suggestion = null, |
|
381 |
$do_link_to_reference = FALSE, |
|
382 |
$do_link_to_name_used_in_source = FALSE, |
|
383 |
$is_bibliography_aware = FALSE |
|
384 |
){ |
|
385 |
|
|
386 |
$sources = cdm_entity_sources_sorted($description_element); |
|
387 |
|
|
388 |
// Annotations as footnotes. |
|
389 |
$footnote_keys = cdm_entity_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion); |
|
390 |
|
|
391 |
// Source references as footnotes. |
|
392 |
if($is_bibliography_aware){ |
|
393 |
$bibliography_settings = get_bibliography_settings(); |
|
394 |
$sources_footnote_list_key = bibliography_footnote_list_key($footnote_list_key_suggestion); |
|
395 |
$original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // null will cause bibliography_footnote_list_key to use the default |
|
396 |
} else { |
|
397 |
$sources_footnote_list_key = $footnote_list_key_suggestion; |
|
398 |
if(!$sources_footnote_list_key) { |
|
399 |
RenderHints::getFootnoteListKey(); |
|
400 |
} |
|
401 |
$original_source_footnote_tag = NULL; |
|
402 |
} |
|
403 |
|
|
404 |
foreach ($sources as $source) { |
|
405 |
if (_is_original_source_type($source)) { |
|
406 |
$fn_key = FootnoteManager::addNewFootnote( |
|
407 |
$sources_footnote_list_key, |
|
408 |
render_original_source( |
|
409 |
$source, |
|
410 |
$do_link_to_reference, |
|
411 |
$do_link_to_name_used_in_source |
|
412 |
), |
|
413 |
$original_source_footnote_tag |
|
414 |
); |
|
415 |
// Ensure uniqueness of the footnote keys. |
|
416 |
cdm_add_footnote_to_array($footnote_keys, $fn_key); |
|
417 |
} |
|
418 |
} |
|
419 |
// Sort and render footnote keys. |
|
420 |
asort($footnote_keys); |
|
421 |
return footnote_keys_to_markup($footnote_keys, $separator); |
|
422 |
} |
|
423 |
|
|
424 |
/** |
|
425 |
* Creates markup for an array of foot note keys |
|
426 |
* |
|
427 |
* @param array $footnote_keys |
|
428 |
* @param string $separator |
|
429 |
* |
|
430 |
* @return string |
|
431 |
*/ |
|
432 |
function footnote_keys_to_markup(array $footnote_keys, $separator) { |
|
433 |
|
|
434 |
$footnotes_markup = ''; |
|
435 |
foreach ($footnote_keys as $foot_note_key) { |
|
436 |
try { |
|
437 |
$footnotes_markup .= cdm_footnote_key($foot_note_key, ($footnotes_markup ? $separator : '')); |
|
438 |
} catch (Exception $e) { |
|
439 |
drupal_set_message("Exception: " . $e->getMessage(), 'error'); |
|
440 |
} |
|
441 |
} |
|
442 |
return $footnotes_markup; |
|
443 |
} |
|
444 |
|
|
445 |
|
|
446 | 336 |
/** |
447 | 337 |
* Compare callback to be used in usort() to sort render arrays produced by |
448 | 338 |
* compose_description_element(). |
Also available in: Unified diff
ref #8543 moving footnote functions to separate inc file