_getCountiesData($primaryKey); return $data; } protected function _getCountiesData($primaryKey) { $select = $this->_db->select(); $select->from($this->_getPair($this->_dependencyTable), array('countyId')) ->where('benchmarkId = ?', $primaryKey); return $this->_db->fetchCol($select); } protected function _insertDependency() { $this->_saveCounties(); return parent::_insertDependency(); } protected function _updateDependency() { $this->_saveCounties(); return parent::_updateDependency(); } protected function _saveCounties() { $counties = $this->getData('counties'); $this->_parseCSV(); $this->_updateIds($this->_getTableName($this->_dependencyTable), 'benchmarkId', 'countyId', $counties); return $this; } protected function _parseCSV() { if (false === ($file = fopen($this->getBasePath() . $this->getData('file'), 'r'))) { throw new \Exception('Can not open raw csv file "' . $file . '"'); } $content = array(); $columns = array(); $min = 0; $max = 0; for ($counter = 0; $data = fgetcsv($file); ++$counter) { if ($counter === 0) { $columns = array('age', 'rate', 'benchmarkId'); } if ($counter == 1) { $min = (int)substr($data[0], -2); $content[] = array($columns[0] => $min, $columns[1] => $data[1], $columns[2] => $this->getPrimaryKey()); } if ((int)($data[0]) !== 0) { $max = (int)$data[0]; $content[] = array($columns[0] => $max, $columns[1] => $data[1], $columns[2] => $this->getPrimaryKey()); } } if(empty($content)){ return false; } $this->_deleteIds($this->_getTableName('BenchmarkPlansData'), 'benchmarkId'); $sqlParts = array(); foreach ($content as $row) { $_row = $row; $_row = Qs_Array::map($_row, $columns); $_row = Qs_Db::quoteRow($_row, $this->_getTable('BenchmarkPlansData')); $sqlParts[] = '(' . implode(', ', $_row) . ')'; } $sql = 'INSERT INTO ' . $this->_db->quoteIdentifier($this->_getTableName('BenchmarkPlansData')) . ' (`' . implode('`, `', $columns) . '`) VALUES ' . PHP_EOL . implode(', ' . PHP_EOL, $sqlParts) . ';'; $sql2 = 'UPDATE' . $this->_db->quoteIdentifier($this->_getTableName('BenchmarkPlans')) . ' SET `min`=' . $min . ', `max`=' . $max . ' WHERE id = ' . $this->_primaryKey . ';'; $this->_db->query($sql2); return $this->_db->query($sql)->rowCount(); } public function getBasePath() { if (null === $this->_basePath) { $this->_basePath = constant('WWW_PATH') . '/userfiles/files/'; } return $this->_basePath; } }