Example #1
0
 /**
  * Parse a CSV file, adding the data to the stockData array.
  * 
  * @param $filepath string Path to the .csv file to try and parse.
  */
 private function __parseCsv($filepath)
 {
     $csvReader = new CsvReader();
     if ($csvReader->readFile(makeAbsolutePath($filepath))) {
         $numLines = $csvReader->getNumLines();
         // If the .csv is sane, the first line is the headers
         $headers = $csvReader->getLine(0);
         if ($headers != null) {
             for ($i = 1; $i < $numLines; $i++) {
                 // For every line, convert the indexed array to an associated array
                 // using the headers as keys
                 $line = $csvReader->getLine($i);
                 if ($line != null && count($line) == count($headers)) {
                     $assocLine = array();
                     $numLineParts = count($line);
                     for ($j = 0; $j < $numLineParts; $j++) {
                         $assocLine[$headers[$j]] = $line[$j];
                     }
                     array_push($this->__stockData, $assocLine);
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * Attempt to read a .csv file
  *
  * @param string $filePath The path to look for the file.
  * @return bool True if file was opened successfully, false otherwise.
  */
 public function readFile($filePath)
 {
     return $this->__csvReader->readFile($filePath);
 }