Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ThemeService | |
0.00% |
0 / 32 |
|
0.00% |
0 / 5 |
240 | |
0.00% |
0 / 1 |
| getCurrentThemeId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addTheme | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| setCurrentTheme | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getAllThemes | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
| removeThemeById | |
0.00% |
0 / 8 |
|
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) 2015-2022 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\theme; |
| 23 | |
| 24 | use oat\oatbox\Configurable; |
| 25 | |
| 26 | /** |
| 27 | * |
| 28 | * @author Joel Bout |
| 29 | */ |
| 30 | class ThemeService extends ThemeServiceAbstract |
| 31 | { |
| 32 | /** |
| 33 | * @inheritdoc |
| 34 | */ |
| 35 | public function getCurrentThemeId() |
| 36 | { |
| 37 | return $this->getOption(static::OPTION_CURRENT); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @inheritdoc |
| 42 | */ |
| 43 | public function addTheme(Theme $theme, $protectAlreadyExistingThemes = true) |
| 44 | { |
| 45 | $themes = $this->getAllThemes(); |
| 46 | $themeId = $theme->getId(); |
| 47 | |
| 48 | if ($protectAlreadyExistingThemes) { |
| 49 | $themeId = $this->getUniqueId($theme); |
| 50 | } |
| 51 | |
| 52 | $themes[$themeId] = [ |
| 53 | static::THEME_CLASS_OFFSET => get_class($theme), |
| 54 | static::THEME_OPTIONS_OFFSET => ($theme instanceof Configurable) ? $theme->getOptions() : [] |
| 55 | ]; |
| 56 | |
| 57 | $this->setOption(static::OPTION_AVAILABLE, $themes); |
| 58 | |
| 59 | return $themeId; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @inheritdoc |
| 64 | */ |
| 65 | public function setCurrentTheme($themeId) |
| 66 | { |
| 67 | if (!$this->hasTheme($themeId)) { |
| 68 | throw new \common_exception_Error('Theme ' . $themeId . ' not found'); |
| 69 | } |
| 70 | |
| 71 | $this->setOption(static::OPTION_CURRENT, $themeId); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @inheritdoc |
| 76 | */ |
| 77 | public function getAllThemes() |
| 78 | { |
| 79 | $themes = (array)$this->getOption(static::OPTION_AVAILABLE); |
| 80 | foreach ($themes as $key => $theme) { |
| 81 | if (is_array($theme) && isset($theme[static::THEME_CLASS_OFFSET])) { |
| 82 | $options = isset($theme[static::THEME_OPTIONS_OFFSET]) |
| 83 | ? $theme[static::THEME_OPTIONS_OFFSET] |
| 84 | : [] |
| 85 | ; |
| 86 | |
| 87 | $theme = $this->getServiceManager()->build($theme[static::THEME_CLASS_OFFSET], $options); |
| 88 | } |
| 89 | |
| 90 | $themes[$key] = $theme; |
| 91 | } |
| 92 | |
| 93 | return $themes; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @inheritdoc |
| 98 | */ |
| 99 | public function removeThemeById($themeId) |
| 100 | { |
| 101 | if (!$this->hasTheme($themeId)) { |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | $availableThemes = $this->getOption(static::OPTION_AVAILABLE); |
| 106 | foreach ($this->getAllThemes() as $key => $theme) { |
| 107 | if ($theme->getId() === $themeId) { |
| 108 | unset($availableThemes[$key]); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | $this->setOption(static::OPTION_AVAILABLE, $availableThemes); |
| 113 | |
| 114 | return true; |
| 115 | } |
| 116 | } |