You are here

private function BiblioStyleBibtex::formatContributor in Bibliography Module 7.3

Helper function to get contributors name.

Parameters

EntityMetadataWrapper $wrapper: The wrapper object.

$key: The property name which holds the value of the field.

$role:

Return value

string The contributors name.

2 calls to BiblioStyleBibtex::formatContributor()
BiblioStyleBibtex::formatContributorAuthor in plugins/biblio_style/bibtex/BiblioStyleBibtex.class.php
Author contributor format entry.
BiblioStyleBibtex::formatContributorEditor in plugins/biblio_style/bibtex/BiblioStyleBibtex.class.php
Editor contributor format entry.

File

plugins/biblio_style/bibtex/BiblioStyleBibtex.class.php, line 518
BibTeX style.

Class

BiblioStyleBibtex
@file BibTeX style.

Code

private function formatContributor(EntityMetadataWrapper $wrapper, $key, $role) {
  if (!$wrapper->{$key}
    ->value()) {
    return;
  }
  $names = array();
  foreach ($wrapper->{$key} as $sub_wrapper) {
    if (strtolower($sub_wrapper->biblio_contributor_role
      ->label()) != strtolower($role)) {
      continue;
    }
    $contributor = $sub_wrapper->biblio_contributor
      ->value();

    // Add a dot to each letter in initials.
    if (!empty($contributor->initials)) {
      $letters = explode(' ', $contributor->initials);
      foreach ($letters as &$letter) {
        $letter .= '.';
      }
      $contributor->initials = implode(' ', $letters);
    }

    // Get the contributor's full name, which is all non-empty name parts.
    $fields = array(
      'firstname',
      'initials',
      'suffix',
      'prefix',
      'lastname',
    );
    $full_name = array();
    foreach ($fields as $field) {
      if (empty($contributor->{$field})) {

        // No value in field.
        continue;
      }

      // Add the field's value to the full name.
      $full_name[] = $contributor->{$field};
    }

    // Add the full name to the list of contributors.
    $names[] = implode(' ', $full_name);
  }
  return implode(' and ', $names);
}