public function FeedsExcelParser::parse in Feeds Excel 7
Same name and namespace in other branches
- 6 ExcelParser.inc \FeedsExcelParser::parse()
- 7.2 FeedsExcelParser.inc \FeedsExcelParser::parse()
Implementation of FeedsParser::parse().
File
- ./
ExcelParser.inc, line 34
Class
- FeedsExcelParser
- Parses a given file as a Excel file.
Code
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
$source_config = $source
->getConfigFor($this);
// State object holds information on the progress of parsing the given source.
$state = $source
->state(FEEDS_PARSE);
$this->fetcher_result = $fetcher_result;
$this->filepath = $fetcher_result
->getFilePath();
_feeds_excel_include_libraries();
// Read file to object
$this->reader = new Spreadsheet_Excel_Reader();
$this->reader
->read($this->filepath);
$limit = $source->importer
->getLimit();
// Populated state with default values.
if (!isset($state->sheet_states)) {
$state->sheet_states = array();
}
// Popuplate state with the sheet ids, as this will be the only time, so
// we do process and count with the inital state.
if (!isset($state->sheet_ids)) {
$state->sheet_ids = $this
->getSheetIDs();
}
$rows = $this
->parseItems($state, $limit);
// Get progress.
$total = 0;
$progress = 0;
$max = 10;
$no_count = 0;
foreach ($state->sheet_ids as $id) {
if (!empty($state->sheet_states[$id]['max'])) {
$total += $state->sheet_states[$id]['max'];
$progress += $state->sheet_states[$id]['offset'];
$max = max($max, $state->sheet_states[$id]['max']);
}
else {
$no_count++;
}
}
$total += $no_count * $max;
// Report progress.
$state->total = $total;
$state
->progress($state->total, $progress);
// Create a result object and return it.
return new FeedsParserResult($rows, $source->feed_nid);
}