Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
CreatorConfig | |
0.00% |
0 / 42 |
|
0.00% |
0 / 8 |
342 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
addInteraction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addInfoControl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addPlugin | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
removePlugin | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
toArray | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
init | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
prepare | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 |
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) 2014 (original work) Open Assessment Technologies SA; |
19 | * |
20 | */ |
21 | |
22 | namespace oat\taoQtiItem\model; |
23 | |
24 | /** |
25 | * Interface defining required method for a plugin |
26 | * |
27 | * @package taoQtiItem |
28 | */ |
29 | class CreatorConfig extends Config |
30 | { |
31 | protected $interactions = []; |
32 | protected $infoControls = []; |
33 | protected $plugins = []; |
34 | |
35 | public function __construct(array $properties = [], array $extendedControlEndpoints = []) |
36 | { |
37 | $this->properties = $properties; |
38 | $this->controlEndpoints = array_merge($this->controlEndpoints, $extendedControlEndpoints); |
39 | } |
40 | |
41 | // hard coded urls for using by item creator |
42 | protected $controlEndpoints = [ |
43 | 'itemDataUrl' => ['taoQtiItem', 'QtiCreator', 'getItemData'], |
44 | 'loadCssUrl' => ['taoQtiItem', 'QtiCssAuthoring', 'load'], |
45 | 'downloadCssUrl' => ['taoQtiItem', 'QtiCssAuthoring', 'download'], |
46 | |
47 | 'saveItemUrl' => ['taoQtiItem', 'QtiCreator', 'saveItem'], |
48 | 'saveCssUrl' => ['taoQtiItem', 'QtiCssAuthoring', 'save'], |
49 | |
50 | 'portableElementAddResourcesUrl' => ['taoQtiItem', 'PortableElement', 'addRequiredResources'], |
51 | |
52 | 'mediaSourcesUrl' => ['taoQtiItem', 'QtiCreator', 'getMediaSources'], |
53 | 'getFilesUrl' => ['taoItems', 'ItemContent', 'files'], |
54 | 'fileAccessUrl' => ['taoQtiItem', 'QtiCreator', 'getFile'], |
55 | |
56 | 'fileExistsUrl' => ['taoItems', 'ItemContent', 'fileExists'], |
57 | 'fileUploadUrl' => ['taoItems', 'ItemContent', 'upload'], |
58 | 'fileDownloadUrl' => ['taoItems', 'ItemContent', 'download'], |
59 | 'fileDeleteUrl' => ['taoItems', 'ItemContent', 'delete'], |
60 | |
61 | 'previewUrl' => ['taoQtiItem', 'QtiPreview', 'index'], |
62 | 'previewRenderUrl' => ['taoQtiItem', 'QtiPreview', 'render'], |
63 | 'previewSubmitUrl' => ['taoQtiItem', 'QtiPreview', 'submitResponses'], |
64 | |
65 | 'resourceMetadataUrl' => ['taoQtiItem', 'Metadata', 'resourceMetadata'], |
66 | ]; |
67 | |
68 | public function addInteraction($interactionFile) |
69 | { |
70 | $this->interactions[] = $interactionFile; |
71 | } |
72 | |
73 | public function addInfoControl($infoControl) |
74 | { |
75 | $this->infoControls[] = $infoControl; |
76 | } |
77 | |
78 | /** |
79 | * Add a plugin to the configuration |
80 | * @param string $name - the plugin name |
81 | * @param string $module - the plugin AMD module |
82 | * @param string $category - the plugin category |
83 | */ |
84 | public function addPlugin($name, $module, $category) |
85 | { |
86 | $this->plugins[] = [ |
87 | 'name' => $name, |
88 | 'module' => $module, |
89 | 'category' => $category |
90 | ]; |
91 | } |
92 | |
93 | /** |
94 | * Remove a plugin from the configuration |
95 | * @param string $name - the plugin name |
96 | */ |
97 | public function removePlugin($name) |
98 | { |
99 | foreach ($this->plugins as $key => $plugin) { |
100 | if ($plugin['name'] == $name) { |
101 | $this->plugins[$key]['exclude'] = true; |
102 | } |
103 | } |
104 | } |
105 | |
106 | public function toArray() |
107 | { |
108 | |
109 | $interactions = []; |
110 | foreach ($this->interactions as $interaction) { |
111 | unset($interaction['directory']); |
112 | $interactions[] = $interaction; |
113 | } |
114 | |
115 | $infoControls = []; |
116 | foreach ($this->infoControls as $infoControl) { |
117 | unset($infoControl['directory']); |
118 | $infoControls[] = $infoControl; |
119 | } |
120 | |
121 | return [ |
122 | 'properties' => $this->properties, |
123 | 'contextPlugins' => $this->plugins, |
124 | 'interactions' => $interactions, |
125 | 'infoControls' => $infoControls, |
126 | ]; |
127 | } |
128 | |
129 | public function init() |
130 | { |
131 | foreach ($this->interactions as $interaction) { |
132 | $this->prepare($interaction); |
133 | } |
134 | foreach ($this->infoControls as $infoControl) { |
135 | $this->prepare($infoControl); |
136 | } |
137 | foreach ($this->controlEndpoints as $key => $endpoint) { |
138 | $this->setProperty($key, \tao_helpers_Uri::url($endpoint[2], $endpoint[1], $endpoint[0])); |
139 | } |
140 | |
141 | //as the config overrides the plugins, we get the list from the registry |
142 | $registry = QtiCreatorClientConfigRegistry::getRegistry(); |
143 | $this->plugins = array_merge($this->plugins, $registry->getPlugins()); |
144 | } |
145 | |
146 | protected function prepare($hook) |
147 | { |
148 | |
149 | if (isset($this->properties['uri'])) { |
150 | $item = new \core_kernel_classes_Resource($this->properties['uri']); |
151 | |
152 | //check for implementation in debugging state: |
153 | if (isset($hook['debug']) && $hook['debug']) { |
154 | //add required resources: |
155 | $registry = new $hook['registry'](); |
156 | $registry->addRequiredResources($hook['typeIdentifier'], $item); |
157 | \common_Logger::d('added ' . $hook['registry'] . ' ' . $hook['typeIdentifier']); |
158 | } |
159 | } else { |
160 | throw new \common_Exception('cannot prepare hook because of missing property in config : "uri" '); |
161 | } |
162 | } |
163 | } |