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); } }
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); } } }
/** * @inheritdoc */ protected function isPkFull() { foreach ($this->getPk() as $attribute) { if (!$attribute->value && !DI::getCellParser()->isLoadedPk($attribute->getInitialCell())) { return false; } } return true; }