Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
CsvMulty Class Reference
Inheritance diagram for CsvMulty:
Csv

Public Member Functions

 getDataPairs ($file, $keyIndex=0, $valueIndex=1)
 
- Public Member Functions inherited from Csv
 __construct (File $file)
 
 setLineLength ($length)
 
 setDelimiter ($delimiter)
 
 setEnclosure ($enclosure)
 
 getData ($file)
 
 getDataPairs ($file, $keyIndex=0, $valueIndex=1)
 
 saveData ($file, $data)
 
 appendData ($file, $data, $mode='w')
 

Additional Inherited Members

- Protected Attributes inherited from Csv
 $_lineLength = 0
 
 $_delimiter = ','
 
 $_enclosure = '"'
 
 $file
 

Detailed Description

Definition at line 14 of file CsvMulty.php.

Member Function Documentation

◆ getDataPairs()

getDataPairs (   $file,
  $keyIndex = 0,
  $valueIndex = 1 
)

Retrieve CSV file data as pairs with duplicates

Parameters
string$file
int$keyIndex
int$valueIndex
Returns
array

Definition at line 24 of file CsvMulty.php.

25  {
26  $data = [];
27  $csvData = $this->getData($file);
28  $lineNumber = 0;
29  foreach ($csvData as $rowData) {
30  $lineNumber++;
31  if (isset($rowData[$keyIndex])) {
32  if (isset($data[$rowData[$keyIndex]])) {
33  if (isset($data[$rowData[$keyIndex]]['duplicate'])) {
34  $data[$rowData[$keyIndex]]['duplicate']['line'] .= ', ' . $lineNumber;
35  } else {
36  $tmpValue = $data[$rowData[$keyIndex]]['value'];
37  $tmpLine = $data[$rowData[$keyIndex]]['line'];
38  $data[$rowData[$keyIndex]]['duplicate'] = [];
39  $data[$rowData[$keyIndex]]['duplicate']['line'] = $tmpLine . ' ,' . $lineNumber;
40  $data[$rowData[$keyIndex]]['duplicate']['value'] = $tmpValue;
41  }
42  } else {
43  $data[$rowData[$keyIndex]] = [];
44  $data[$rowData[$keyIndex]]['line'] = $lineNumber;
45  $data[$rowData[$keyIndex]]['value'] = isset($rowData[$valueIndex]) ? $rowData[$valueIndex] : null;
46  }
47  }
48  }
49  return $data;
50  }

The documentation for this class was generated from the following file: