You are here

public function FeedsExcelParser::parseItems in Feeds Excel 7

Parse items from the given reader source respecting processing limits.

Parameters

$state: state object that comes from source and holds the parsed points.

integer $limit: maximum number of items to process in one step

Return value

array

1 call to FeedsExcelParser::parseItems()
FeedsExcelParser::parse in ./ExcelParser.inc
Implementation of FeedsParser::parse().

File

./ExcelParser.inc, line 95

Class

FeedsExcelParser
Parses a given file as a Excel file.

Code

public function parseItems(&$state, $limit) {
  $count = 0;
  $return = array();

  // Run through each sheet until we got enough items.
  foreach ($state->sheet_ids as $sheet_id) {

    // Process only not yet completed sheets.
    if (empty($state->sheet_states[$sheet_id]['complete'])) {
      $offset = !empty($state->sheet_states[$sheet_id]['offset']) ? $state->sheet_states[$sheet_id]['offset'] : 0;
      $sheet = $this
        ->getSheet($sheet_id);

      // For the moment we parse the whole sheet at once.
      // @TODO: parse single rows to avoid unnecessary processing.
      $items = $this
        ->getItems($sheet);
      $state->sheet_states[$sheet_id]['max'] = count($items);
      $add = array_slice($items, $offset, $limit - $count, FALSE);
      $return = array_merge($return, $add);
      $count += count($add);

      // Set new offset.
      $state->sheet_states[$sheet_id]['offset'] = $offset + count($add);
      if ($state->sheet_states[$sheet_id]['offset'] >= $state->sheet_states[$sheet_id]['max']) {
        $state->sheet_states[$sheet_id]['complete'] = TRUE;
      }

      // If we got enough items, return them.
      if ($limit <= $count) {
        return $return;
      }
    }
  }
  return $return;
}