You are here

function csl_names::render in Bibliography Module 7.2

Same name and namespace in other branches
  1. 6.2 modules/CiteProc/CSL.inc \csl_names::render()
  2. 7 modules/CiteProc/CSL.inc \csl_names::render()

Overrides csl_rendering_element::render

File

modules/CiteProc/CSL.inc, line 795

Class

csl_names

Code

function render($data, $mode = NULL) {
  $matches = 0;
  $variable_parts = array();
  if (!isset($this->delimiter)) {
    $style_delimiter = $this->citeproc->style->{'names-delimiter'};
    $mode_delimiter = $this->citeproc->{$mode}->{'names-delimiter'};
    $this->delimiter = isset($mode_delimiter) ? $mode_delimiter : (isset($style_delimiter) ? $style_delimiter : '');
  }
  $variables = explode(' ', $this->variable);
  foreach ($variables as $var) {
    list($contributor, $category) = explode(':', $var);
    if (!empty($contributor) && $this
      ->_get_category($data->{$contributor}, $category)) {
      $matches++;
      break;
    }
  }
  if (!$matches) {

    // we don't have any primary suspects, so lets check the substitutes...
    if (isset($this->substitutes)) {
      foreach ($this->substitutes->elements as $element) {
        if ($element instanceof csl_names) {

          //test to see if any of the other names variables has content
          $variables = explode(' ', $element->variable);
          foreach ($variables as $var) {
            list($contributor, $category) = explode(':', $var);
            if (!empty($contributor) && $this
              ->_get_category($data->{$contributor}, $category)) {
              $matches++;
              break;
            }
          }
        }
        else {

          // if it's not a "names" element, just render it
          return $element
            ->render($data, $mode);
        }
      }
    }
  }
  foreach ($variables as $var) {
    $text = '';
    list($contributor, $category) = explode(':', $var);
    if (!empty($contributor) && ($authors = $this
      ->_get_category($data->{$contributor}, $category))) {
      foreach ($this->elements as $element) {
        if (is_a($element, 'csl_label')) {
          $data->{$var}['variable'] = $var;
        }
        $text .= $element
          ->render($authors, $mode);
      }
    }
    if (!empty($text)) {
      $variable_parts[] = $text;
    }
  }
  if (!empty($variable_parts)) {
    $text = implode($this->delimiter, $variable_parts);
    return $this
      ->format($text);
  }
  return;
}