public function testDispatch()
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener('test_populated', function (Event $event) {
         $event->setResponseContent('content');
     });
     $claroDispatcher = new StrictDispatcher($dispatcher);
     $event = $claroDispatcher->dispatch('test_populated', 'CreateFormResource', array());
     $this->assertEquals('content', $event->getResponseContent());
 }
Example #2
0
 /**
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceRights $rights
  */
 public function logChangeSet(ResourceRights $rights)
 {
     $uow = $this->om->getUnitOfWork();
     $class = $this->om->getClassMetadata('Claroline\\CoreBundle\\Entity\\Resource\\ResourceRights');
     $uow->computeChangeSet($class, $rights);
     $changeSet = $uow->getEntityChangeSet($rights);
     if (count($changeSet) > 0) {
         $this->dispatcher->dispatch('log', 'Log\\LogWorkspaceRoleChangeRight', array($rights->getRole(), $rights->getResourceNode(), $changeSet));
     }
 }
 /**
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  * @param \Claroline\CoreBundle\Entity\User                $user
  *
  * @return \Claroline\CoreBundle\Entity\User
  */
 public function addUserAction(Workspace $workspace, User $user)
 {
     $role = $this->roleManager->getCollaboratorRole($workspace);
     $userRoles = $this->roleManager->getWorkspaceRolesForUser($user, $workspace);
     if (count($userRoles) === 0) {
         $this->roleManager->associateRole($user, $role);
         $this->dispatcher->dispatch('claroline_workspace_register_user', 'WorkspaceAddUser', [$role, $user]);
     }
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->container->get('security.context')->setToken($token);
     return $user;
 }
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     $user = $this->tokenStorage->getToken()->getUser();
     if ($uri = $request->getSession()->get('_security.main.target_path')) {
         return new RedirectResponse($uri);
     }
     if ($this->configurationHandler->isRedirectOption(PlatformConfiguration::$REDIRECT_OPTIONS['DESKTOP'])) {
         return new RedirectResponse($this->router->generate('claro_desktop_open'));
     } elseif ($this->configurationHandler->isRedirectOption(PlatformConfiguration::$REDIRECT_OPTIONS['LAST']) && ($uri = $request->getSession()->get('redirect_route'))) {
         return new RedirectResponse($uri);
     } elseif ($this->configurationHandler->isRedirectOption(PlatformConfiguration::$REDIRECT_OPTIONS['URL']) && null !== ($url = $this->configurationHandler->getParameter('redirect_after_login_url'))) {
         return new RedirectResponse($url);
     } elseif ($this->configurationHandler->isRedirectOption(PlatformConfiguration::$REDIRECT_OPTIONS['WORKSPACE_TAG']) && null !== ($defaultWorkspaceTag = $this->configurationHandler->getParameter('default_workspace_tag'))) {
         $event = $this->eventDispatcher->dispatch('claroline_retrieve_user_workspaces_by_tag', 'GenericDatas', [['tag' => $defaultWorkspaceTag, 'user' => $user, 'ordered_by' => 'id', 'order' => 'ASC']]);
         $workspaces = $event->getResponse();
         if (is_array($workspaces) && count($workspaces) > 0) {
             $workspace = $workspaces[0];
             $route = $this->router->generate('claro_workspace_open', ['workspaceId' => $workspace->getId()]);
             return new RedirectResponse($route);
         }
     }
     return new RedirectResponse($this->router->generate('claro_desktop_open'));
 }