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
 /**
  * Get the number of lines available.
  *
  * @return int The number of lines available.
  */
 public function getNumLines()
 {
     return $this->__csvReader->getNumLines();
 }