Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
TestContentCopier | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
copy | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
copyModel | |
100.00% |
3 / 3 |
|
100.00% |
1 / 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) 2023 (original work) Open Assessment Technologies SA. |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\taoTests\models\Copier; |
24 | |
25 | use core_kernel_classes_Resource; |
26 | use oat\oatbox\event\EventManager; |
27 | use oat\tao\model\resources\Contract\InstanceContentCopierInterface; |
28 | use oat\taoTests\models\event\TestDuplicatedEvent; |
29 | use taoTests_models_classes_TestsService; |
30 | |
31 | class TestContentCopier implements InstanceContentCopierInterface |
32 | { |
33 | private taoTests_models_classes_TestsService $testsService; |
34 | private EventManager $eventManager; |
35 | |
36 | public function __construct(taoTests_models_classes_TestsService $testsService, EventManager $eventManager) |
37 | { |
38 | $this->testsService = $testsService; |
39 | $this->eventManager = $eventManager; |
40 | } |
41 | |
42 | public function copy( |
43 | core_kernel_classes_Resource $instance, |
44 | core_kernel_classes_Resource $destinationInstance |
45 | ): void { |
46 | $this->copyModel($instance, $destinationInstance); |
47 | $this->testsService->cloneContent($instance, $destinationInstance); |
48 | |
49 | $this->eventManager->trigger(new TestDuplicatedEvent($instance->getUri(), $destinationInstance->getUri())); |
50 | } |
51 | |
52 | private function copyModel(core_kernel_classes_Resource $from, core_kernel_classes_Resource $to): void |
53 | { |
54 | $modelProperty = $from->getProperty(taoTests_models_classes_TestsService::PROPERTY_TEST_TESTMODEL); |
55 | $model = $from->getOnePropertyValue($modelProperty); |
56 | |
57 | $to->editPropertyValues($modelProperty, $model instanceof core_kernel_classes_Resource ? $model : null); |
58 | } |
59 | } |