Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| QtiCreatorClientConfigRegistry | |
0.00% |
0 / 50 |
|
0.00% |
0 / 3 |
342 | |
0.00% |
0 / 1 |
| registerPlugin | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
132 | |||
| removePlugin | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
20 | |||
| getPlugins | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2016 (original work) Open Assessment Technologies SA ; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model; |
| 23 | |
| 24 | use oat\tao\model\ClientLibConfigRegistry; |
| 25 | |
| 26 | /** |
| 27 | * Class QtiCreatorClientConfigRegistry |
| 28 | * @package oat\taoQtiItem\models |
| 29 | * @author Ivan Klimchuk <klimchuk@1pt.com> |
| 30 | */ |
| 31 | class QtiCreatorClientConfigRegistry extends ClientLibConfigRegistry |
| 32 | { |
| 33 | public const CREATOR = "taoQtiItem/controller/creator/index"; |
| 34 | |
| 35 | /** |
| 36 | * @param $name |
| 37 | * @param $module |
| 38 | * @param $category |
| 39 | * @param null $position |
| 40 | * @throws \common_exception_InvalidArgumentType |
| 41 | */ |
| 42 | public function registerPlugin($name, $module, $category, $position = null) |
| 43 | { |
| 44 | if (!is_string($name)) { |
| 45 | throw new \common_exception_InvalidArgumentType('The plugin name must be a string!'); |
| 46 | } |
| 47 | if (!is_string($module)) { |
| 48 | throw new \common_exception_InvalidArgumentType('The module path must be a string!'); |
| 49 | } |
| 50 | if (!is_string($category)) { |
| 51 | throw new \common_exception_InvalidArgumentType('The category name must be a string!'); |
| 52 | } |
| 53 | if (!is_null($position) && !is_string($position) && !is_numeric($position)) { |
| 54 | throw new \common_exception_InvalidArgumentType('The position must be a string or a number!'); |
| 55 | } |
| 56 | |
| 57 | $config = []; |
| 58 | $registry = self::getRegistry(); |
| 59 | if ($registry->isRegistered(self::CREATOR)) { |
| 60 | $config = $registry->get(self::CREATOR); |
| 61 | } |
| 62 | |
| 63 | $plugins = []; |
| 64 | if (isset($config['plugins'])) { |
| 65 | foreach ($config['plugins'] as $plugin) { |
| 66 | if ($plugin['module'] != $module) { |
| 67 | $plugins[] = $plugin; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | $plugins[] = [ |
| 73 | 'name' => $name, |
| 74 | 'module' => $module, |
| 75 | 'category' => $category, |
| 76 | 'position' => $position, |
| 77 | ]; |
| 78 | |
| 79 | $config['plugins'] = array_values($plugins); |
| 80 | $registry->set(self::CREATOR, $config); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @param $name |
| 85 | * @param $module |
| 86 | * @param $category |
| 87 | * @param null $position |
| 88 | */ |
| 89 | public function removePlugin($name, $module, $category, $position = null) |
| 90 | { |
| 91 | $config = []; |
| 92 | $registry = self::getRegistry(); |
| 93 | |
| 94 | if ($registry->isRegistered(self::CREATOR)) { |
| 95 | $config = $registry->get(self::CREATOR); |
| 96 | } |
| 97 | |
| 98 | if (!isset($config['plugins'])) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | $plugins = $config['plugins']; |
| 103 | |
| 104 | $plugin = [ |
| 105 | 'name' => $name, |
| 106 | 'module' => $module, |
| 107 | 'category' => $category, |
| 108 | 'position' => $position, |
| 109 | ]; |
| 110 | |
| 111 | $key = array_search($plugin, $plugins); |
| 112 | if (is_numeric($key)) { |
| 113 | unset($plugins[$key]); |
| 114 | } |
| 115 | |
| 116 | $config['plugins'] = array_values($plugins); |
| 117 | $registry->set(self::CREATOR, $config); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Quick access to the plugins |
| 122 | * @return array the registered plugins |
| 123 | */ |
| 124 | public function getPlugins() |
| 125 | { |
| 126 | $config = []; |
| 127 | $registry = self::getRegistry(); |
| 128 | |
| 129 | if ($registry->isRegistered(self::CREATOR)) { |
| 130 | $config = $registry->get(self::CREATOR); |
| 131 | } |
| 132 | |
| 133 | if (!isset($config['plugins'])) { |
| 134 | return []; |
| 135 | } |
| 136 | |
| 137 | return $config['plugins']; |
| 138 | } |
| 139 | } |