You are here

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

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

Implementation of 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(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  $result = new FeedsParserResult();
  require_once drupal_get_path('module', 'feeds_oai_pmh') . '/feeds_oai_pmh.inc';
  $feed = feeds_oai_pmh_parse($fetcher_result
    ->getRaw());
  if (!$feed) {

    // No items, return
    return $result;
  }

  // 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.
        $result->items[] = $item;
      }
    }
  }
  return $result;
}