mirror of
https://github.com/wallabag/wallabag.git
synced 2024-06-01 19:33:09 +00:00
32da2a70ef
Re-defined the config / user relation to be OneToOne bidirectionnal. ConfigType is now a service so I can inject the list of available themes that are also used by LiipThemeBundle Force sqlite for test In case of people use a different driver in parameter.yml (yes I do :))
48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Wallabag\CoreBundle\Helper;
|
|
|
|
use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
|
|
use Symfony\Component\Security\Core\SecurityContextInterface;
|
|
use Wallabag\CoreBundle\Entity\User;
|
|
|
|
class DetectActiveTheme implements DeviceDetectionInterface
|
|
{
|
|
protected $securityContext;
|
|
|
|
public function __construct(SecurityContextInterface $securityContext)
|
|
{
|
|
$this->securityContext = $securityContext;
|
|
}
|
|
|
|
public function setUserAgent($userAgent)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* This should return the active theme for the logged in user.
|
|
* No active theme for:
|
|
* - anonymous user
|
|
* - user without a config (shouldn't happen..)
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getType()
|
|
{
|
|
$user = $this->securityContext->getToken()->getUser();
|
|
|
|
// anon user don't deserve a theme
|
|
if (!$user instanceof User) {
|
|
return false;
|
|
}
|
|
|
|
$config = $user->getConfig();
|
|
|
|
if (!$config) {
|
|
return false;
|
|
}
|
|
|
|
return $config->getTheme();
|
|
}
|
|
}
|