2015-02-23 21:55:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\CoreBundle\Helper;
|
|
|
|
|
|
|
|
use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
|
|
|
|
use Symfony\Component\Security\Core\SecurityContextInterface;
|
|
|
|
use Wallabag\CoreBundle\Entity\User;
|
|
|
|
|
2015-03-01 07:22:29 +00:00
|
|
|
/**
|
|
|
|
* This class intend to detect the active theme for the logged in user.
|
|
|
|
* It will retrieve the configured theme of the user.
|
|
|
|
*
|
|
|
|
* If no user where logged in, it will returne the default theme
|
|
|
|
*/
|
2015-02-23 21:55:06 +00:00
|
|
|
class DetectActiveTheme implements DeviceDetectionInterface
|
|
|
|
{
|
|
|
|
protected $securityContext;
|
2015-03-01 07:22:29 +00:00
|
|
|
protected $defaultTheme;
|
2015-02-23 21:55:06 +00:00
|
|
|
|
2015-03-01 07:22:29 +00:00
|
|
|
/**
|
|
|
|
* @param SecurityContextInterface $securityContext Needed to retrieve the current user
|
|
|
|
* @param string $defaultTheme Default theme when user isn't logged in
|
|
|
|
*/
|
|
|
|
public function __construct(SecurityContextInterface $securityContext, $defaultTheme)
|
2015-02-23 21:55:06 +00:00
|
|
|
{
|
|
|
|
$this->securityContext = $securityContext;
|
2015-03-01 07:22:29 +00:00
|
|
|
$this->defaultTheme = $defaultTheme;
|
2015-02-23 21:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setUserAgent($userAgent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This should return the active theme for the logged in user.
|
2015-03-01 07:22:29 +00:00
|
|
|
*
|
|
|
|
* Default theme for:
|
2015-02-23 21:55:06 +00:00
|
|
|
* - anonymous user
|
2015-03-01 07:22:29 +00:00
|
|
|
* - user without a config (shouldn't happen ..)
|
2015-02-23 21:55:06 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getType()
|
|
|
|
{
|
|
|
|
$user = $this->securityContext->getToken()->getUser();
|
|
|
|
|
|
|
|
if (!$user instanceof User) {
|
2015-03-01 07:22:29 +00:00
|
|
|
return $this->defaultTheme;
|
2015-02-23 21:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$config = $user->getConfig();
|
|
|
|
|
|
|
|
if (!$config) {
|
2015-03-01 07:22:29 +00:00
|
|
|
return $this->defaultTheme;
|
2015-02-23 21:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $config->getTheme();
|
|
|
|
}
|
|
|
|
}
|