]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php
Removed old, not so maintained and buggy baggy theme
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / DetectActiveTheme.php
CommitLineData
32da2a70
J
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
18f8f32f 6use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1210dae1 7use Wallabag\UserBundle\Entity\User;
32da2a70 8
495aecfe
J
9/**
10 * This class intend to detect the active theme for the logged in user.
11 * It will retrieve the configured theme of the user.
12 *
13 * If no user where logged in, it will returne the default theme
14 */
32da2a70
J
15class DetectActiveTheme implements DeviceDetectionInterface
16{
18f8f32f 17 protected $tokenStorage;
495aecfe 18 protected $defaultTheme;
39676caf 19 protected $themes;
32da2a70 20
495aecfe 21 /**
164d260c
JB
22 * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user
23 * @param string $defaultTheme Default theme when user isn't logged in
39676caf 24 * @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes)
495aecfe 25 */
39676caf 26 public function __construct(TokenStorageInterface $tokenStorage, $defaultTheme, $themes)
32da2a70 27 {
18f8f32f 28 $this->tokenStorage = $tokenStorage;
495aecfe 29 $this->defaultTheme = $defaultTheme;
39676caf 30 $this->themes = $themes;
32da2a70
J
31 }
32
33 public function setUserAgent($userAgent)
34 {
35 }
36
37 /**
38 * This should return the active theme for the logged in user.
495aecfe
J
39 *
40 * Default theme for:
32da2a70 41 * - anonymous user
495aecfe 42 * - user without a config (shouldn't happen ..)
32da2a70
J
43 *
44 * @return string
45 */
46 public function getType()
47 {
18f8f32f 48 $token = $this->tokenStorage->getToken();
ce782c84 49
f808b016 50 if (null === $token) {
ce782c84
NL
51 return $this->defaultTheme;
52 }
53
54 $user = $token->getUser();
32da2a70 55
32da2a70 56 if (!$user instanceof User) {
495aecfe 57 return $this->defaultTheme;
32da2a70
J
58 }
59
60 $config = $user->getConfig();
61
62 if (!$config) {
495aecfe 63 return $this->defaultTheme;
32da2a70
J
64 }
65
39676caf
NL
66 if (!in_array($config->getTheme(), $this->themes)) {
67 return $this->defaultTheme;
68 }
69
32da2a70
J
70 return $config->getTheme();
71 }
72}