diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-03-02 21:23:19 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-03-02 21:23:19 +0100 |
commit | ba7b9d48d407f87690a3fdc199b37714d2a52897 (patch) | |
tree | a15611f10d09749e82011e0d51532af3de8cfabd /src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php | |
parent | fca3c757233940cbe4c431e3e05fe74893225fe0 (diff) | |
parent | 3e30422cdae3cc45f44c3039c2d38b99121dd9e9 (diff) | |
download | wallabag-ba7b9d48d407f87690a3fdc199b37714d2a52897.tar.gz wallabag-ba7b9d48d407f87690a3fdc199b37714d2a52897.tar.zst wallabag-ba7b9d48d407f87690a3fdc199b37714d2a52897.zip |
Merge pull request #1132 from wallabag/v2-theme
V2 theme
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php new file mode 100644 index 00000000..446629db --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php | |||
@@ -0,0 +1,59 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Liip\ThemeBundle\Helper\DeviceDetectionInterface; | ||
6 | use Symfony\Component\Security\Core\SecurityContextInterface; | ||
7 | use Wallabag\CoreBundle\Entity\User; | ||
8 | |||
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 | */ | ||
15 | class DetectActiveTheme implements DeviceDetectionInterface | ||
16 | { | ||
17 | protected $securityContext; | ||
18 | protected $defaultTheme; | ||
19 | |||
20 | /** | ||
21 | * @param SecurityContextInterface $securityContext Needed to retrieve the current user | ||
22 | * @param string $defaultTheme Default theme when user isn't logged in | ||
23 | */ | ||
24 | public function __construct(SecurityContextInterface $securityContext, $defaultTheme) | ||
25 | { | ||
26 | $this->securityContext = $securityContext; | ||
27 | $this->defaultTheme = $defaultTheme; | ||
28 | } | ||
29 | |||
30 | public function setUserAgent($userAgent) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * This should return the active theme for the logged in user. | ||
36 | * | ||
37 | * Default theme for: | ||
38 | * - anonymous user | ||
39 | * - user without a config (shouldn't happen ..) | ||
40 | * | ||
41 | * @return string | ||
42 | */ | ||
43 | public function getType() | ||
44 | { | ||
45 | $user = $this->securityContext->getToken()->getUser(); | ||
46 | |||
47 | if (!$user instanceof User) { | ||
48 | return $this->defaultTheme; | ||
49 | } | ||
50 | |||
51 | $config = $user->getConfig(); | ||
52 | |||
53 | if (!$config) { | ||
54 | return $this->defaultTheme; | ||
55 | } | ||
56 | |||
57 | return $config->getTheme(); | ||
58 | } | ||
59 | } | ||