public function loadCSVColumns() { $app = JFactory::getApplication(); $path = $app->getUserState('file_path', ''); $delimiter = $app->getUserState('delimiter', ','); $enclosure = $app->getUserState('enclosure', '"'); if (!JFile::exists($path)) { $this->setError(JText::sprintf("COM_JUDIRECTORY_IMPORT_IMAGE_FILE_S_NOT_FOUND", $path)); return false; } $rows = JUDirectoryHelper::getCSVData($path, $delimiter, $enclosure, 'r+', 0, null, true); $csvColumnRows = array_shift($rows); $totalCsvRow = count($rows); $app->setUserState('csv_total_row', $totalCsvRow); return $csvColumnRows; }
public function combineCSVColumnNameWithColumnValue() { $app = JFactory::getApplication(); $dataCSV = $app->getUserState('csv.dataCSV'); $config = $dataCSV['csv_config']; $csvPath = $dataCSV['csv_file_path']; $delimiter = $dataCSV['csv_delimiter']; $enclosure = $dataCSV['csv_enclosure']; $start = $app->input->getInt('start', 0); $limit = $config['limit']; $csvData = JUDirectoryHelper::getCSVData($csvPath, $delimiter, $enclosure, 'r+', $start, $limit, false); $columns = $dataCSV['csv_assigned_fields']; foreach ($csvData as $index => $data) { if (count($columns) == count($data)) { $csvData[$index] = array_combine($columns, $data); } else { unset($csvData[$index]); } } return $csvData; }