Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
TestModelService
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 11
240
0.00% covered (danger)
0.00%
0 / 1
 prepareContent
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 deleteContent
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getItems
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 onChangeTestLabel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAuthoringUrl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 cloneContent
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
 getImportHandlers
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getExportHandlers
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getCompiler
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getCompilerClass
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPackerClass
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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) 2013-2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 *
21 */
22
23namespace oat\taoQtiTest\models;
24
25use oat\oatbox\service\ConfigurableService;
26use oat\oatbox\filesystem\Directory;
27use oat\taoTests\models\TestModel;
28use oat\tao\model\service\ServiceFileStorage;
29
30/**
31 * the qti TestModel
32 *
33 * @access public
34 * @author Joel Bout, <joel.bout@tudor.lu>
35 * @package taoQtiTest
36 */
37class TestModelService extends ConfigurableService implements
38    TestModel,
39    \tao_models_classes_import_ImportProvider,
40    \tao_models_classes_export_ExportProvider
41{
42    public const SERVICE_ID = 'taoQtiTest/TestModel';
43
44    public const SUBSERVICE_COMPILATION = 'CompilationService';
45
46    /**
47     * {@inheritDoc}
48     * @see \taoTests_models_classes_TestModel::prepareContent()
49     */
50    public function prepareContent(\core_kernel_classes_Resource $test, $items = [])
51    {
52        $service = $this->getServiceLocator()->get(\taoQtiTest_models_classes_QtiTestService::class);
53        $service->save($test, $items);
54    }
55
56    /**
57     * {@inheritDoc}
58     * @see \taoTests_models_classes_TestModel::deleteContent()
59     */
60    public function deleteContent(\core_kernel_classes_Resource $test)
61    {
62        $service = $this->getServiceLocator()->get(\taoQtiTest_models_classes_QtiTestService::class);
63        $service->deleteContent($test);
64    }
65
66    /**
67     * {@inheritDoc}
68     * @see \taoTests_models_classes_TestModel::getItems()
69     */
70    public function getItems(\core_kernel_classes_Resource $test)
71    {
72        $service = $this->getServiceLocator()->get(\taoQtiTest_models_classes_QtiTestService::class);
73        return $service->getItems($test);
74    }
75
76    /**
77     * {@inheritDoc}
78     * @see \taoTests_models_classes_TestModel::onChangeTestLabel()
79     */
80    public function onChangeTestLabel(\core_kernel_classes_Resource $test)
81    {
82        // do nothing
83    }
84
85    /**
86     * {@inheritDoc}
87     * @see \taoTests_models_classes_TestModel::getAuthoringUrl()
88     */
89    public function getAuthoringUrl(\core_kernel_classes_Resource $test)
90    {
91        return _url('index', 'Creator', 'taoQtiTest', ['uri' => $test->getUri()]);
92    }
93
94    /**
95     * Clone a QTI Test Resource.
96     *
97     * @param \core_kernel_classes_Resource $source The resource to be cloned.
98     * @param \core_kernel_classes_Resource $destination An existing resource to be filled as the clone of $source.
99     */
100    public function cloneContent(\core_kernel_classes_Resource $source, \core_kernel_classes_Resource $destination)
101    {
102        $service = \taoQtiTest_models_classes_QtiTestService::singleton();
103        $existingDir = $service->getQtiTestDir($source);
104        $destinationDir = $service->getQtiTestDir($destination, false);
105
106        if ($existingDir->exists()) {
107            $iterator = $existingDir->getFlyIterator(Directory::ITERATOR_FILE | Directory::ITERATOR_RECURSIVE);
108            /** @var File $file */
109            foreach ($iterator as $file) {
110                $destinationDir->getFile($existingDir->getRelPath($file))->write($file->readStream());
111            }
112        } else {
113            \common_Logger::w('Test "' . $source->getUri() . '" had no content, nothing to clone');
114        }
115    }
116
117    public function getImportHandlers()
118    {
119        if ($this->hasOption('importHandlers')) {
120            return $this->getOption('importHandlers');
121        } else {
122            return [];
123        }
124    }
125
126    public function getExportHandlers()
127    {
128        if ($this->hasOption('exportHandlers')) {
129            return $this->getOption('exportHandlers');
130        } else {
131            return [];
132        }
133    }
134
135    /**
136     * {@inheritDoc}
137     * @see \oat\taoTests\models\TestModel::getCompiler()
138     */
139    public function getCompiler(\core_kernel_classes_Resource $test, ServiceFileStorage $storage)
140    {
141        $service = $this->getSubService('CompilationService');
142        return $service->getCompiler($test, $storage);
143    }
144
145    public function getCompilerClass()
146    {
147        return $this->getSubService(self::SUBSERVICE_COMPILATION)->getCompilerClass();
148    }
149
150
151    public function getPackerClass()
152    {
153        return 'oat\\taoQtiTest\\models\\pack\\QtiTestPacker';
154    }
155}