Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| CustomInteractionRegistry | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| getConfigId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getInteractionClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| getCustomInteractions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getCustomInteractionByName | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 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 (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model; |
| 23 | |
| 24 | use common_exception_Error; |
| 25 | use common_ext_ExtensionsManager; |
| 26 | |
| 27 | /** |
| 28 | * Registry for custom interactions |
| 29 | * |
| 30 | * @author Joel Bout <joel@taotestinf.com> |
| 31 | */ |
| 32 | class CustomInteractionRegistry extends AbstractInteractionRegistry |
| 33 | { |
| 34 | /** |
| 35 | * Key used to store the custom interactions in the config |
| 36 | * |
| 37 | * @var string |
| 38 | */ |
| 39 | public const CONFIG_ID = 'custom_interaction'; |
| 40 | |
| 41 | /** |
| 42 | * |
| 43 | * @author Lionel Lecaque, lionel@taotesting.com |
| 44 | * @return string |
| 45 | */ |
| 46 | protected function getConfigId() |
| 47 | { |
| 48 | return self::CONFIG_ID; |
| 49 | } |
| 50 | /** |
| 51 | * |
| 52 | * @author Lionel Lecaque, lionel@taotesting.com |
| 53 | * @return string |
| 54 | */ |
| 55 | protected function getInteractionClass() |
| 56 | { |
| 57 | return 'oat\taoQtiItem\model\qti\interaction\CustomInteraction'; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Register a new custom interaction |
| 63 | * |
| 64 | * @param string $qtiClass |
| 65 | * @param string $phpClass |
| 66 | * @deprecated |
| 67 | * @throws common_exception_Error |
| 68 | */ |
| 69 | public static function register($qtiClass, $phpClass) |
| 70 | { |
| 71 | if (!class_exists($phpClass)) { |
| 72 | throw new common_exception_Error('Custom interaction class ' . $phpClass . ' not found'); |
| 73 | } |
| 74 | if (!is_subclass_of($phpClass, 'oat\taoQtiItem\model\qti\interaction\CustomInteraction')) { |
| 75 | throw new common_exception_Error('Class ' . $phpClass . ' not a subclass of CustomInteraction'); |
| 76 | } |
| 77 | $taoQtiItem = common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem'); |
| 78 | $map = self::getCustomInteractions(); |
| 79 | $map[$qtiClass] = $phpClass; |
| 80 | $taoQtiItem->setConfig(self::CONFIG_ID, $map); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns a list of registered custom interactions. |
| 85 | * |
| 86 | * With the qti classes as keys and the php classnames that |
| 87 | * implementat these interactions as values |
| 88 | * |
| 89 | * @deprecated |
| 90 | * @return array |
| 91 | */ |
| 92 | public static function getCustomInteractions() |
| 93 | { |
| 94 | $taoQtiItem = common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem'); |
| 95 | $map = $taoQtiItem->getConfig(self::CONFIG_ID); |
| 96 | return is_array($map) ? $map : []; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Get the php class that represents a custom interaction from its class attribute |
| 101 | * |
| 102 | * @param string $name |
| 103 | * @deprecated |
| 104 | * @return string |
| 105 | * |
| 106 | */ |
| 107 | public static function getCustomInteractionByName($name) |
| 108 | { |
| 109 | $all = self::getCustomInteractions(); |
| 110 | if (isset($all[$name])) { |
| 111 | return $all[$name]; |
| 112 | } |
| 113 | return ''; |
| 114 | } |
| 115 | } |