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 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
ItemModel
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 9
182
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 render
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 getPreviewUrl
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 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getExportHandlers
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getImportHandlers
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getCompilerClass
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getPackerClass
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getItemContentTokenizer
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 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 *
21 */
22
23namespace oat\taoQtiItem\model;
24
25use oat\oatbox\service\ConfigurableService;
26use oat\tao\model\search\tokenizer\ResourceTokenizer;
27use oat\taoItems\model\search\IndexableItemModel;
28use oat\taoQtiItem\model\qti\Service;
29use oat\taoQtiItem\model\search\QtiItemContentTokenizer;
30use tao_models_classes_export_ExportProvider;
31use tao_models_classes_import_ImportProvider;
32use common_ext_ExtensionsManager;
33use core_kernel_classes_Resource;
34use common_Logger;
35use taoItems_models_classes_itemModel;
36
37/**
38 * Short description of class oat\taoQtiItem\model\ItemModel
39 *
40 * @access public
41 * @author Joel Bout, <joel@taotesting.com>
42 * @package taoQTI
43 */
44class ItemModel extends ConfigurableService implements
45    taoItems_models_classes_itemModel,
46    tao_models_classes_export_ExportProvider,
47    tao_models_classes_import_ImportProvider,
48    IndexableItemModel
49{
50    public const SERVICE_ID = 'taoQtiItem/ItemModel';
51    public const MODEL_URI = "http://www.tao.lu/Ontologies/TAOItem.rdf#QTI";
52
53    public const COMPILER = 'compilerClass';
54    public const IMPORT_HANDLER = 'importHandlers';
55    public const EXPORT_HANDLER = 'exportHandlers';
56
57    /**
58     * constructor called by itemService
59     *
60     * @access public
61     * @author Joel Bout, <joel@taotesting.com>
62     * @return mixed
63     */
64    public function __construct($options = [])
65    {
66        parent::__construct($options);
67        // ensure qti extension is loaded
68        common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem');
69    }
70
71    /**
72     * render used for deploy and preview
73     *
74     * @access public
75     * @param core_kernel_classes_Resource $item
76     * @param $langCode
77     * @return string
78     * @throws \common_Exception
79     * @author Joel Bout, <joel@taotesting.com>
80     */
81    public function render(core_kernel_classes_Resource $item, $langCode)
82    {
83        $returnValue = (string)'';
84
85        $qitService = Service::singleton();
86
87        $qtiItem = $qitService->getDataItemByRdfItem($item, $langCode);
88
89        if (!is_null($qtiItem)) {
90            $returnValue = $qitService->renderQTIItem($qtiItem, $langCode);
91        } else {
92            common_Logger::w('No qti data for item ' . $item->getUri() . ' in ' . __FUNCTION__, 'taoQtiItem');
93        }
94
95        return (string)$returnValue;
96    }
97
98    /**
99     * (non-PHPdoc)
100     * @see taoItems_models_classes_itemModel::getPreviewUrl()
101     */
102    public function getPreviewUrl(core_kernel_classes_Resource $item, $languageCode)
103    {
104        return _url('index', 'QtiPreview', 'taoQtiItem', ['uri' => $item->getUri(), 'lang' => $languageCode]);
105    }
106
107    /**
108     * @see taoItems_models_classes_itemModel::getPreviewUrl()
109     */
110    public function getAuthoringUrl(core_kernel_classes_Resource $item)
111    {
112        return _url('index', 'QtiCreator', 'taoQtiItem', [
113            'instance' => $item->getUri(),
114            'STANDALONE_MODE' => intval(\tao_helpers_Context::check('STANDALONE_MODE'))
115        ]);
116    }
117
118
119    public function getExportHandlers()
120    {
121        if ($this->hasOption(self::EXPORT_HANDLER)) {
122            return $this->getOption(self::EXPORT_HANDLER);
123        } else {
124            return [];
125        }
126    }
127
128    public function getImportHandlers()
129    {
130        if ($this->hasOption(self::IMPORT_HANDLER)) {
131            return $this->getOption(self::IMPORT_HANDLER);
132        } else {
133            return [];
134        }
135    }
136
137    public function getCompilerClass()
138    {
139        if ($this->hasOption(self::COMPILER)) {
140            return $this->getOption(self::COMPILER);
141        } else {
142            return [];
143        }
144    }
145
146    public function getPackerClass()
147    {
148        return 'oat\\taoQtiItem\\model\\pack\\QtiItemPacker';
149    }
150
151    public function getItemContentTokenizer(): ResourceTokenizer
152    {
153        return $this->getServiceLocator()->get(QtiItemContentTokenizer::SERVICE_ID);
154    }
155}