getConfig('requiredCsvFields')->toArray(); return $this->_getFormInstance('import', $options); } public static function getFullImportFilePath($fileName) { return static::getFullImportFolderPath() . '/' . $fileName; } public static function getFullImportFolderPath() { return BASE_PATH . '/tmp/' . self::DESTINATION_FOLDER; } public function clearFolder($folderPath) { foreach (glob($folderPath . '/*') as $file) { if (is_dir($file)) $this->clearFolder($file); else unlink($file); } return $this; } public function clearImportFolder() { $folderPath = static::getFullImportFolderPath(); $this->clearFolder($folderPath); return $this; } protected function _checkTmpImportFolder() { $dirPath = \App\User\Import\View::getFullImportFolderPath(); if (is_dir($dirPath) ) { return true; } return mkdir($dirPath, 0777); } protected function _doImportForm() { if (!$this->_checkTmpImportFolder()) { $msg = 'Can not create folder: ' . \App\User\Import\View::DESTINATION_FOLDER; $this->_doc->addItem(array('tpl' => 'User/Import/error.tpl', 'message' => $msg)); return $this; } $form = $this->_getImportForm(); $form->setDefaults(); $this->_addFormItem($form); $this->_postNew(); return $this; } protected function _doImportAjax() { $form = $this->_getImportForm(); $data = $form->validateAjax(); $this->_displayJson($data); } protected function _getImportDoneMessage() { $importStatistic = $this->_getDataObj()->getImportStatistic(); $msg = static::MSG_IMPORTED . "
Processed rows count: " . $importStatistic['importedRowsCount']; $msg .= "
New members count: " ; if ($importStatistic['insertedRowsCount']) { $msg .= $importStatistic['insertedRowsCount']; if ($importStatistic['insertedUsersNames']) { $importStatistic['insertedUsersNames'] = array_map('htmlspecialchars', $importStatistic['insertedUsersNames']); $msg .= ' (' . implode(', ', $importStatistic['insertedUsersNames']) . ')'; } } else { $msg .= ' -'; } $msg .= "
Updated members count: "; if ($importStatistic['updatedRowsCount']) { $msg .= $importStatistic['updatedRowsCount']; } else { $msg .= ' -'; } if ($importStatistic['importedErrorRowsCount']) { $msg .= "

Not imported rows: " . $importStatistic['importedErrorRowsCount']; } return $msg; } protected function _doImport() { $form = $this->_getImportForm(); if ($form->validate()) { $this->_initFromForm($form); if (false === $this->_getDataObj()->import()) { $this->_setBackErrors($this->_getDataObj()->getErrors()); } else { $errors = $this->_getDataObj()->getImportErrors(); if (!empty($errors)) { $importErrorMsg = implode("
", $errors); $this->_setBackError($importErrorMsg); } $this->_setBackMessage($this->_getImportDoneMessage()); } $this->clearTemporaryImportData(); $this->_doBack(); } else { $this->_addFormItem($form); } return $this; } protected function clearTemporaryImportData() { //delete file after import $this->clearImportFolder(); //drop temporary table $this->_getDataObj()->dropTemporaryImportTable(); return $this; } }