protected function initSavedPk() { $sheet = $this->row->getCellIterator()->current()->getWorksheet(); $columns = ArrayHelper::getColumn($this->_standardModel->standardAttributes, 'column'); sort($columns); $lastColumn = end($columns); $cell = $sheet->getCell(++$lastColumn . $this->row->getRowIndex()); if (DI::getCellParser()->isSavedPk($cell)) { $this->_savedPk = DI::getCellParser()->getSavedPk($cell); } }
/** * @inheritdoc */ public function init() { if (!$this->filePath) { throw new InvalidParamException('File path not specified or file not uploaded.'); } if (!file_exists($this->filePath)) { throw new InvalidParamException("File not exist in path \"{$this->filePath}\"."); } foreach ($this->standardModelsConfig as $config) { $this->initStandardModel($config); } $this->configureEventHandlers(); DI::setImporter($this); }
public function linkRelatedModel() { if (!DI::getCellParser()->isLoadedPk($this->cell)) { return; } $loadedPk = DI::getCellParser()->getLoadedPk($this->cell); foreach (array_reverse(DI::getImporter()->models) as $model) { $isRelatedByPk = $loadedPk && $model->savedPk == $loadedPk; $attributeModelClass = $this->_standardAttribute->standardModel->className; $modelClass = $model->standardModel->className; $isRelatedByLastPk = $loadedPk === '' && $attributeModelClass != $modelClass; if ($isRelatedByPk || $isRelatedByLastPk) { $this->_relatedModel = $model; break; } } if (!$this->_relatedModel) { throw new CellException($this->cell, 'Related model not found.'); } }
protected function mergeDefaultAttributes() { foreach ($this->_standardModel->defaultAttributes as $defaultAttribute) { $isFound = false; foreach ($this->_attributes as $index => $attribute) { $namesMatch = $defaultAttribute->standardAttribute->name == $attribute->standardAttribute->name; if (!$namesMatch) { continue; } else { $isFound = true; } $isLoadedPk = DI::getCellParser()->isLoadedPk($attribute->getInitialCell()); if ($namesMatch && $attribute->value === null && !$isLoadedPk) { $this->mergeDefaultAttribute($defaultAttribute, $index); break; } } if (!$isFound) { $this->mergeDefaultAttribute($defaultAttribute); } } }
public function validate() { if (!$this->_instance->validate()) { DI::getImporter()->wrongModel = $this->_instance; throw new RowException($this->row, 'Model data is not valid.'); } }
/** * @inheritdoc */ protected function isPkFull() { foreach ($this->getPk() as $attribute) { if (!$attribute->value && !DI::getCellParser()->isLoadedPk($attribute->getInitialCell())) { return false; } } return true; }
/** * @return \PHPExcel_Cell */ public function getInitialCell() { return DI::getPHPExcel()->getSheetByCodeName($this->_sheetCodeName)->getCell($this->_cellCoordinate); }