Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ImportHandlerHelperTrait | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| fetchUploadedFile | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |||
| getUploadService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTaskParameters | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017-2021 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\import; |
| 23 | |
| 24 | use common_exception_Error; |
| 25 | use oat\oatbox\filesystem\File; |
| 26 | use oat\tao\model\upload\UploadService; |
| 27 | use tao_helpers_form_Form; |
| 28 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 29 | |
| 30 | trait ImportHandlerHelperTrait |
| 31 | { |
| 32 | use ServiceLocatorAwareTrait; |
| 33 | |
| 34 | /** |
| 35 | * @param array|tao_helpers_form_Form $form |
| 36 | * @return File|string |
| 37 | * @throws common_exception_Error |
| 38 | * |
| 39 | * @deprecated Use \oat\tao\model\upload\UploadService::fetchUploadedFile() |
| 40 | */ |
| 41 | protected function fetchUploadedFile($form) |
| 42 | { |
| 43 | $file = ''; |
| 44 | |
| 45 | // for backward compatibility |
| 46 | if ($form instanceof tao_helpers_form_Form) { |
| 47 | $fileInfo = $form->getValue('source'); |
| 48 | |
| 49 | /** @var string $file */ |
| 50 | $file = $form->getValue('importFile') ?: $fileInfo['uploaded_file']; // key "importFile" used in CSV import |
| 51 | } elseif (isset($form['uploaded_file'])) { |
| 52 | /** @var File $file */ |
| 53 | $file = $this->getUploadService()->getUploadDir()->getFile($form['uploaded_file']); |
| 54 | } |
| 55 | |
| 56 | if (!$file) { |
| 57 | throw new common_exception_Error('No source file for import'); |
| 58 | } |
| 59 | |
| 60 | return $file; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @return UploadService|object |
| 65 | */ |
| 66 | protected function getUploadService() |
| 67 | { |
| 68 | return $this->getServiceLocator()->get(UploadService::SERVICE_ID); |
| 69 | } |
| 70 | |
| 71 | public function getTaskParameters(tao_helpers_form_Form $importForm) |
| 72 | { |
| 73 | // key "importFile" used in CSV import |
| 74 | $file = $this->getUploadService()->getUploadedFlyFile($importForm->getValue('importFile') |
| 75 | ?: $importForm->getValue('source')['uploaded_file']); |
| 76 | |
| 77 | return [ |
| 78 | 'uploaded_file' => $file->getPrefix(), // because of Async, we need the full path of the uploaded file |
| 79 | ]; |
| 80 | } |
| 81 | } |