You are here

public function FeedsQueryPathParser::parse in Feeds QueryPath Parser 6

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

Implementation of FeedsParser::parse().

Overrides FeedsParser::parse

File

./FeedsQueryPathParser.inc, line 18
Provides the class for FeedsQueryPathParser.

Class

FeedsQueryPathParser
@file

Code

public function parse(FeedsImportBatch $batch, FeedsSource $source) {
  $this->source_config = $source
    ->getConfigFor($this);
  if (isset($this->source_config['rawXML']) && is_array($this->source_config['rawXML'])) {
    $this->rawXML = array_keys(array_filter($this->source_config['rawXML']));
  }
  if (isset($this->source_config['options']['debug']) && is_array($this->source_config['options']['debug'])) {
    $this->debug_options = array_keys(array_filter($this->source_config['options']['debug']));
  }
  if (!empty($this->debug_options)) {
    $this->debug_switch = TRUE;
  }
  $mappings = feeds_importer($this->id)->processor->config['mappings'];
  $this->mappings = array();
  foreach ($mappings as $mapping) {
    if (strpos($mapping['source'], 'querypathparser:') === 0) {
      $this->mappings[$mapping['source']] = $mapping['target'];
    }
  }
  $batch
    ->setTitle(trim(qp($batch
    ->getRaw(), 'title')
    ->text()));
  $context = qp($batch
    ->getRaw(), $this->source_config['context']);
  foreach ($context as $child) {
    $parsed_item = $variables = array();
    foreach ($this->source_config['sources'] as $source => $query) {
      $query = strtr($query, $variables);
      $result = $this
        ->parseSourceElement($child, $query, $source);
      if (!is_array($result)) {
        $variables['$' . $this->mappings[$source]] = $result;
      }
      $parsed_item[$source] = $result;
    }
    $batch
      ->addItem($parsed_item);
  }
}