Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| StyleRegistry | |
0.00% |
0 / 12 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| getConfigId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getExtension | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAllStyles | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| isValidStyleData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| register | |
0.00% |
0 / 5 |
|
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\style; |
| 23 | |
| 24 | use oat\oatbox\AbstractRegistry; |
| 25 | use common_ext_ExtensionsManager; |
| 26 | use common_Logger; |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * Registry to store available style classes |
| 31 | * |
| 32 | * @author Sam, sam@taotesting.com |
| 33 | */ |
| 34 | class StyleRegistry extends AbstractRegistry |
| 35 | { |
| 36 | /** |
| 37 | * @see \oat\oatbox\AbstractRegistry::getConfigId() |
| 38 | */ |
| 39 | protected function getConfigId() |
| 40 | { |
| 41 | return 'style_class_registry'; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @see \oat\oatbox\AbstractRegistry::getExtension() |
| 46 | */ |
| 47 | protected function getExtension() |
| 48 | { |
| 49 | return common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem'); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get all styles available from the registry |
| 54 | * |
| 55 | * @return array |
| 56 | */ |
| 57 | public function getAllStyles() |
| 58 | { |
| 59 | $styles = []; |
| 60 | foreach (self::getRegistry()->getMap() as $id => $styleData) { |
| 61 | $styles[$id] = $styleData; |
| 62 | } |
| 63 | return $styles; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Check if the array contains sufficient style data |
| 68 | * |
| 69 | * @param array $data |
| 70 | * @return boolean |
| 71 | */ |
| 72 | public function isValidStyleData($data) |
| 73 | { |
| 74 | return isset($data['label']) && !empty($data['label']); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Register a style |
| 79 | * |
| 80 | * @param string $id |
| 81 | * @param array $styleData |
| 82 | */ |
| 83 | public function register($id, $styleData) |
| 84 | { |
| 85 | if (self::getRegistry()->isRegistered($id)) { |
| 86 | common_Logger::w('Style already registered'); |
| 87 | } |
| 88 | if ($this->isValidStyleData($styleData)) { |
| 89 | self::getRegistry()->set($id, $styleData); |
| 90 | } else { |
| 91 | common_Logger::w('Invalid style data format'); |
| 92 | } |
| 93 | } |
| 94 | } |