function getSummarizationStatesFromFile($file) { if (file_exists($file)) { $fileHandle = fopen($file, 'r'); if (!$fileHandle) { return false; } } else { return array(); } //--- include used methods ---// include_once $this->csvManagerPath; if (!class_exists('csvManager')) { throw new Exception('Unable to include "csvManager".'); return false; } $csvReader = new csvManager(); $csvReader->delimiter = $this->logDelimiter; $states = array(); $rowCount = 0; $missingDateColumnCount = 0; $missingStateColumnCount = 0; $firstRow = fgetcsv($fileHandle, $csvReader->rowLength, $csvReader->delimiter); while ($row = $csvReader->fgetcsv_assoc($fileHandle, $firstRow)) { $rowCount++; if (!isset($row[$this->dateColumnLabel])) { $missingDateColumnCount++; continue; } else { if (!isset($row[$this->stateColumnLabel])) { $missingStateColumnCount++; continue; } } $states[$this->dateColumnLabel] = $row[$this->stateColumnLabel]; } fclose($fileHandle); if ($missingDateColumnCount) { $message = $missingDateColumnCount . ' of ' . $rowCount . ' column' . ($rowCount > 1 ? 's' : '') . ' without date column found in "' . $file . '"'; if ($rowCount && $missingDateColumnCount / $rowCount > 0.5) { throw new Exception($message); } else { trigger_error($message, E_USER_WARNING); } } if ($missingStateColumnCount) { $message = $missingStateColumnCount . ' of ' . $rowCount . ' column' . ($rowCount > 1 ? 's' : '') . ' without date state found in "' . $file . '"'; if ($rowCount && $missingStateColumnCount / $rowCount > 0.5) { throw new Exception($message); } else { trigger_error($message, E_USER_WARNING); } } return $states; }
private function writeDataLevel($identifier, $dataLevel, $timeStamp = false) { if ($timeStamp == false) { $timeStamp = time(); } if (!(include_once $this->libPath . 'class.csvManager.inc.php')) { trigger_error('Unable to include "csvManager". Not warning level data written.', E_USER_WARNING); return false; } $csv = new csvManager(); $rowToWrite = array('id' => $identifier, 'level' => $dataLevel, 'time' => $timeStamp); return $csv->write($this->warningLevelFile, $rowToWrite, 'id'); }