From 32da2a70ef278bd42f66eb82c3fbf1905a417b87 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 23 Feb 2015 22:55:06 +0100 Subject: Add LiipThemeBundle 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 :)) --- .../CoreBundle/Helper/DetectActiveTheme.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php (limited to 'src/Wallabag/CoreBundle/Helper') diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php new file mode 100644 index 00000000..2a943bb7 --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -0,0 +1,47 @@ +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(); + } +} -- cgit v1.2.3 From 495aecfe7417918c45d8ea32b1ee8903018449cd Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 1 Mar 2015 08:22:29 +0100 Subject: Cleanup & simplify theme --- .../CoreBundle/Helper/DetectActiveTheme.php | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper') diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php index 2a943bb7..2c742e6a 100644 --- a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -6,13 +6,26 @@ use Liip\ThemeBundle\Helper\DeviceDetectionInterface; use Symfony\Component\Security\Core\SecurityContextInterface; use Wallabag\CoreBundle\Entity\User; +/** + * 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 + */ + class DetectActiveTheme implements DeviceDetectionInterface { protected $securityContext; + protected $defaultTheme; - public function __construct(SecurityContextInterface $securityContext) + /** + * @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) { $this->securityContext = $securityContext; + $this->defaultTheme = $defaultTheme; } public function setUserAgent($userAgent) @@ -21,9 +34,10 @@ class DetectActiveTheme implements DeviceDetectionInterface /** * This should return the active theme for the logged in user. - * No active theme for: + * + * Default theme for: * - anonymous user - * - user without a config (shouldn't happen..) + * - user without a config (shouldn't happen ..) * * @return string */ @@ -31,15 +45,14 @@ class DetectActiveTheme implements DeviceDetectionInterface { $user = $this->securityContext->getToken()->getUser(); - // anon user don't deserve a theme if (!$user instanceof User) { - return false; + return $this->defaultTheme; } $config = $user->getConfig(); if (!$config) { - return false; + return $this->defaultTheme; } return $config->getTheme(); -- cgit v1.2.3 From 3e30422cdae3cc45f44c3039c2d38b99121dd9e9 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 1 Mar 2015 20:25:43 +0100 Subject: Only one pattern for LiipTheme Others patterns aren't required (but I think it's still important to have them around) --- src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Helper') diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php index 2c742e6a..446629db 100644 --- a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -12,7 +12,6 @@ use Wallabag\CoreBundle\Entity\User; * * If no user where logged in, it will returne the default theme */ - class DetectActiveTheme implements DeviceDetectionInterface { protected $securityContext; -- cgit v1.2.3