Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ImportByHandler | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getImporter | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| getContainer | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\task; |
| 23 | |
| 24 | use common_report_Report as Report; |
| 25 | use InvalidArgumentException; |
| 26 | use oat\generis\model\OntologyAwareTrait; |
| 27 | use oat\oatbox\extension\AbstractAction; |
| 28 | use Psr\Container\ContainerInterface; |
| 29 | use tao_models_classes_import_ImportHandler; |
| 30 | |
| 31 | /** |
| 32 | * General import task. |
| 33 | * |
| 34 | * @author Gyula Szucs <gyula@taotesting.com> |
| 35 | */ |
| 36 | class ImportByHandler extends AbstractAction |
| 37 | { |
| 38 | use OntologyAwareTrait; |
| 39 | |
| 40 | public const PARAM_IMPORT_HANDLER = 'import_handler'; |
| 41 | public const PARAM_IMPORT_HANDLER_SERVICE_ID = 'import_handler_service_id'; |
| 42 | public const PARAM_FORM_VALUES = 'form_values'; |
| 43 | public const PARAM_PARENT_CLASS = 'parent_class_uri'; |
| 44 | public const PARAM_OWNER = 'owner'; |
| 45 | |
| 46 | /** |
| 47 | * @param array $params |
| 48 | * @return Report |
| 49 | */ |
| 50 | public function __invoke($params) |
| 51 | { |
| 52 | return $this->getImporter($params)->import( |
| 53 | $this->getClass($params[self::PARAM_PARENT_CLASS]), |
| 54 | $params[self::PARAM_FORM_VALUES], |
| 55 | $params[self::PARAM_OWNER] |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | private function getImporter(array $params): tao_models_classes_import_ImportHandler |
| 60 | { |
| 61 | if (isset($params[self::PARAM_IMPORT_HANDLER_SERVICE_ID])) { |
| 62 | return $this->getContainer()->get($params[self::PARAM_IMPORT_HANDLER_SERVICE_ID]); |
| 63 | } |
| 64 | |
| 65 | if (!isset($params[self::PARAM_IMPORT_HANDLER]) || !class_exists($params[self::PARAM_IMPORT_HANDLER])) { |
| 66 | throw new InvalidArgumentException('Please provide a valid import handler'); |
| 67 | } |
| 68 | |
| 69 | /** @var tao_models_classes_import_ImportHandler $importer */ |
| 70 | $importer = new $params[self::PARAM_IMPORT_HANDLER](); |
| 71 | |
| 72 | $this->propagate($importer); |
| 73 | |
| 74 | return $importer; |
| 75 | } |
| 76 | |
| 77 | private function getContainer(): ContainerInterface |
| 78 | { |
| 79 | return $this->getServiceManager()->getContainer(); |
| 80 | } |
| 81 | } |