Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use Session to select portal theme #416

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions models/classes/theme/PortalThemeService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoLti\models\classes\theme;

use common_session_SessionManager;
use oat\tao\model\session\Context\TenantDataSessionContext;
use oat\tao\model\theme\PortalTheme;
use oat\tao\model\theme\ThemeService;
use oat\taoLti\models\classes\TaoLtiSession;

class PortalThemeService extends ThemeService
{
public function getCurrentThemeId()
{
if ($this->isSessionFromPortal()) {
return PortalTheme::THEME_ID;
}

return $this->getOption(static::OPTION_CURRENT);
}

private function isSessionFromPortal(): bool
{
$session = common_session_SessionManager::getSession();
return $session instanceof TaoLtiSession
&& !empty($session->getContexts(TenantDataSessionContext::class));
}
}
45 changes: 45 additions & 0 deletions scripts/install/RegisterPortalTheme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoLti\scripts\install;

use oat\oatbox\config\ConfigurationService;
use oat\oatbox\extension\InstallAction;
use oat\tao\model\theme\PortalTheme;
use oat\tao\model\theme\ThemeServiceInterface;
use oat\taoLti\models\classes\theme\PortalThemeService;

class RegisterPortalTheme extends InstallAction
{
public function __invoke($params = [])
{
/** @var ConfigurationService $previousThemeService */
$previousThemeService = $this->getServiceLocator()->get(ThemeServiceInterface::SERVICE_ID);

/** @var ThemeServiceInterface $service */
$service = new PortalThemeService();
$service->setOptions($previousThemeService->getOptions());
$service->addTheme(new PortalTheme(), false);

$this->getServiceLocator()->register(ThemeServiceInterface::SERVICE_ID, $service);
}
}