You are here

protected function views_oai_pmh_plugin_style::apply_attributes in Views OAI-PMH 7.3

Applies the available attributes to any of the given nodes.

Applies the available attributes to any of the given nodes, whenever a node's path matches an attribute's path. Unused attributes may remain. Matching is starts with the leaf node, to avoid overwriting attributes that might have already been applied to parent nodes.

Parameters

int $row_index: The row index.

string $field: The field name.

int $delta: The delta.

array $nodes: A list of nodes belonging to a single path, sorted parents first, and keyed by their paths.

array $available_attributes: A list of available attributes.

array $used_attributes: A list of used attributes.

1 call to views_oai_pmh_plugin_style::apply_attributes()
views_oai_pmh_plugin_style::append_record_metadata in plugins/views_oai_pmh_plugin_style.inc
Builds the core of a record's XML.

File

plugins/views_oai_pmh_plugin_style.inc, line 595
Contains the base OAI-PMH style plugin.

Class

views_oai_pmh_plugin_style
Views OAI-PMH_plugin style.

Code

protected function apply_attributes($row_index, $field, $delta, array $nodes, array $available_attributes, array &$used_attributes) {
  foreach (array_reverse($nodes) as $element_path => $element_node) {

    // Check if the metadata format supports any attributes on the current
    // path.
    if (isset($this->request->metadata_format->attributes[$element_path]) && !empty($this->request->metadata_format->attributes[$element_path])) {

      // Check if any of our available attributes are among those supported by
      // the metadata format.
      foreach ($available_attributes as $attribute_name => $attribute_field_name) {
        if (in_array($attribute_name, $this->request->metadata_format->attributes[$element_path])) {

          // Attribute applies. Let's add it!
          $attribute_field = $this->view->field[$attribute_field_name];
          $attribute_value = $this
            ->get_field($row_index, $attribute_field_name);
          if (isset($attribute_field->multiple) && $attribute_field->multiple && isset($field->multiple) && $field->multiple) {

            // Find attribute delta matching the current field delta.
            $attribute_values = explode($attribute_field->options['separator'], $attribute_value);
            if (isset($attribute_values[$delta])) {
              $attribute_value = $attribute_values[$delta];
            }
          }
          $attribute_value = trim($attribute_value);
          if (!$attribute_field->options['hide_empty'] || !empty($attribute_value)) {
            $element_node
              ->setAttribute($attribute_name, check_plain($attribute_value));
          }
          $used_attributes[$attribute_name] = TRUE;

          // Remove this attribute from the available ones before proceeding
          // with the remainder of the path.
          unset($available_attributes[$attribute_name]);
        }
      }
    }
  }
}