You are here

public function FeedsOAIParser::parse in Feeds OAI-PMH Fetcher and Parser 6

Same name and namespace in other branches
  1. 7 FeedsOAIParser.inc \FeedsOAIParser::parse()

Implementation of FeedsParser::parse().

Overrides FeedsParser::parse

File

./FeedsOAIParser.inc, line 17
Implementation of FeedsParser::parse().

Class

FeedsOAIParser
Class definition for OAI-PMH Dublin Core metadata parser.

Code

public function parse(FeedsImportBatch $batch, FeedsSource $source) {
  require_once drupal_get_path('module', 'feeds_oai_pmh') . '/feeds_oai_pmh.inc';
  $feed = feeds_oai_pmh_parse($batch
    ->getRaw());
  if (!$feed) {

    // No items, return
    return;
  }

  // Check for items.
  if (is_array($feed['items'])) {

    // Add set name element to each of the items.
    $oai_endpoint_url = $source->config['FeedsOAIHTTPFetcher']['source'];
    $identify_response = feeds_oai_pmh_identify($oai_endpoint_url);
    if ($identify_response['repository']['sets']) {
      foreach ($feed['items'] as $index => $item) {
        foreach ($item['setspec_raw'] as $setspec) {
          $set_name = $identify_response['repository']['sets'][$setspec]['name'];
          $feed['items'][$index]['setspec_name'][] = $set_name;
        }
      }
    }

    // Return the items found in feed.
    $batch
      ->setItems($feed['items']);
  }
}