/**
  * {@inheritdoc}
  */
 public function getItems()
 {
     /* @var TokenStorageInterface $tokenStorage */
     $tokenStorage = $this->container->get('security.token_storage');
     /* @var RequestStack */
     $requestStack = $this->container->get('request_stack');
     /* @var Request $request */
     $request = $requestStack->getCurrentRequest();
     if (null === $request) {
         return array();
     }
     /* @var Router $router */
     $router = $this->container->get('router');
     $locale = $request->getLocale();
     $runtimeConfig = $this->container->getParameter(ModeraMjrIntegrationExtension::CONFIG_KEY);
     $token = $tokenStorage->getToken();
     if ($token->isAuthenticated() && $token->getUser() instanceof User) {
         /* @var EntityManager $em */
         $em = $this->container->get('doctrine.orm.entity_manager');
         /* @var UserSettings $settings */
         $settings = $em->getRepository(UserSettings::clazz())->findOneBy(array('user' => $token->getUser()->getId()));
         if ($settings && $settings->getLanguage() && $settings->getLanguage()->getEnabled()) {
             $locale = $settings->getLanguage()->getLocale();
             $session = $request->getSession();
             $session->set('_backend_locale', $locale);
         }
     }
     return array('extjs_localization_runtime_plugin' => array('className' => 'Modera.backend.languages.runtime.ExtJsLocalizationPlugin', 'tags' => ['runtime_plugin'], 'args' => array(array('urls' => array($runtimeConfig['extjs_path'] . '/locale/ext-lang-' . $locale . '.js', $router->generate('modera_backend_languages_extjs_l10n', array('locale' => $locale)))))), 'modera_backend_languages.user_settings_window_contributor' => array('className' => 'Modera.backend.languages.runtime.UserSettingsWindowContributor', 'args' => ['@application'], 'tags' => ['shared_activities_provider']));
 }
 /**
  * @param User $user
  *
  * @return string
  */
 private function getLocale(User $user)
 {
     $settings = $this->em->getRepository(UserSettings::clazz())->findOneBy(array('user' => $user->getId()));
     if ($settings && $settings->getLanguage() && $settings->getLanguage()->getEnabled()) {
         return $settings->getLanguage()->getLocale();
     }
     return $this->defaultLocale;
 }
 /**
  * @param OnFlushEventArgs $event
  */
 public function onFlush(OnFlushEventArgs $event)
 {
     $em = $event->getEntityManager();
     $uow = $em->getUnitOfWork();
     foreach ($uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof User) {
             $userSettings = new UserSettings();
             $userSettings->setUser($entity);
             $em->persist($userSettings);
             $uow->computeChangeSet($em->getClassMetadata(UserSettings::clazz()), $userSettings);
         }
     }
     foreach ($uow->getScheduledEntityDeletions() as $entity) {
         if ($entity instanceof User) {
             $query = $em->createQuery(sprintf('DELETE FROM %s us WHERE us.user = ?0', UserSettings::clazz()));
             $query->execute(array($entity));
         }
     }
 }
Exemplo n.º 4
0
 protected function setUp()
 {
     $this->em = \Phake::mock('Doctrine\\ORM\\EntityManagerInterface');
     \Phake::when($this->em)->getRepository(UserSettings::clazz())->thenReturn(new DummyRepository());
     $this->mailer = new DummySwiftMailer(\Phake::mock('Swift_Transport'));
 }
Exemplo n.º 5
0
 /**
  * @return array
  */
 public function getConfig()
 {
     return array('entity' => UserSettings::clazz(), 'hydration' => array('groups' => array('main-form' => function (UserSettings $settings) {
         return array('id' => $settings->getId(), 'username' => $settings->getUser()->getUsername(), 'language' => $settings->getLanguage() ? $settings->getLanguage()->getId() : null);
     }), 'profiles' => array('main-form')));
 }