Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LtiThemeSwitcher | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
| getTheme | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| isHeadless | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
| 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 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoLti\models\classes\theme; |
| 23 | |
| 24 | use oat\tao\model\theme\ThemeService; |
| 25 | use oat\taoLti\models\classes\TaoLtiSession; |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * @author Joel Bout |
| 30 | * |
| 31 | * @deprecated Set the LtiThemeIdProvider (ThemeIdProviderInterface) to the ThemeService as option and use getTheme |
| 32 | * method! |
| 33 | */ |
| 34 | class LtiThemeSwitcher extends ThemeService implements LtiHeadless |
| 35 | { |
| 36 | public const OPTION_HEADLESS_PAGE = 'headless_page'; |
| 37 | |
| 38 | public const LTI_VARIABLE = 'custom_theme'; |
| 39 | public const LTI_PRESENTATION_TARGET = 'launch_presentation_document_target'; |
| 40 | |
| 41 | /** |
| 42 | * @return \oat\tao\model\theme\Theme |
| 43 | * @throws \common_exception_Error |
| 44 | * @throws \common_exception_InconsistentData |
| 45 | * @throws \oat\taoLti\models\classes\LtiVariableMissingException |
| 46 | */ |
| 47 | public function getTheme() |
| 48 | { |
| 49 | $currentSession = \common_session_SessionManager::getSession(); |
| 50 | if ($currentSession instanceof TaoLtiSession) { |
| 51 | $launchData = $currentSession->getLaunchData(); |
| 52 | if ( |
| 53 | $launchData->hasVariable(self::LTI_VARIABLE) |
| 54 | && $this->hasTheme($launchData->getVariable(self::LTI_VARIABLE)) |
| 55 | ) { |
| 56 | return $this->getThemeById($launchData->getVariable(self::LTI_VARIABLE)); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return parent::getTheme(); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * Tells if the page has to be headless: without header and footer. |
| 66 | * @return bool|mixed |
| 67 | * @throws \common_exception_Error |
| 68 | * @throws \oat\taoLti\models\classes\LtiVariableMissingException |
| 69 | */ |
| 70 | public function isHeadless() |
| 71 | { |
| 72 | if ($this->hasOption(self::OPTION_HEADLESS_PAGE)) { |
| 73 | return $this->getOption(self::OPTION_HEADLESS_PAGE); |
| 74 | } |
| 75 | |
| 76 | $currentSession = \common_session_SessionManager::getSession(); |
| 77 | if ($currentSession instanceof TaoLtiSession) { |
| 78 | $launchData = $currentSession->getLaunchData(); |
| 79 | $presentationTarget = $launchData->hasVariable(self::LTI_PRESENTATION_TARGET) |
| 80 | ? $launchData->getVariable(self::LTI_PRESENTATION_TARGET) |
| 81 | : ''; |
| 82 | |
| 83 | return $presentationTarget == 'frame' || $presentationTarget == 'iframe'; |
| 84 | } |
| 85 | |
| 86 | return true; |
| 87 | } |
| 88 | } |