file = $file;
$this->file->processing(true);
}
/**
* Generate a return a table based on the CSV data being previewed.
*
* @return string
*/
public function output()
{
$records_to_fetch = 5;
$total_records = $this->file->getRecordCount();
if ($total_records < $records_to_fetch) {
$records_to_fetch = $total_records;
}
$output = '
';
for ($i = 0; $i < $records_to_fetch; $i++) {
$csv = $this->file->getRecord($i);
$wrapper = $i == 0 ? 'th' : 'td';
$output .= '';
$output .= sprintf('<%s>', $wrapper);
$output .= implode(sprintf('%s><%s>', $wrapper, $wrapper), str_getcsv($csv));
$output .= sprintf('%s>', $wrapper);
$output .= '
';
}
$output .= '
';
return $output;
}
public function data($record_index = 0, $show_headings = true)
{
$result = [];
$headings = str_getcsv($this->file->getRecord(0), $this->file->getDelimiter(), $this->file->getEnclosure());
if (true === $show_headings) {
$result['headings'] = $headings;
$record_index++;
} else {
$result['headings'] = [];
for ($i = 0; $i < count($headings); $i++) {
$result['headings'][] = $i;
}
}
$result['row'] = str_getcsv($this->file->getRecord($record_index), $this->file->getDelimiter(), $this->file->getEnclosure());
return $result;
}
}