Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
 /**
  * @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);
 }
Esempio n. 3
0
 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.');
     }
 }
Esempio n. 4
0
 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);
         }
     }
 }
Esempio n. 5
0
 public function validate()
 {
     if (!$this->_instance->validate()) {
         DI::getImporter()->wrongModel = $this->_instance;
         throw new RowException($this->row, 'Model data is not valid.');
     }
 }
Esempio n. 6
0
 /**
  * @inheritdoc
  */
 protected function isPkFull()
 {
     foreach ($this->getPk() as $attribute) {
         if (!$attribute->value && !DI::getCellParser()->isLoadedPk($attribute->getInitialCell())) {
             return false;
         }
     }
     return true;
 }
Esempio n. 7
0
 /**
  * @return \PHPExcel_Cell
  */
 public function getInitialCell()
 {
     return DI::getPHPExcel()->getSheetByCodeName($this->_sheetCodeName)->getCell($this->_cellCoordinate);
 }