Exemple #1
1
 /**
  * @param string $type
  * @param string $message
  */
 protected function addFlash($type, $message)
 {
     if (!$this->session) {
         $this->session = $this->getSession();
     }
     $this->session->getFlashBag()->set('notice', 'Session  saved!');
 }
 public function updateSecondaryResources(ActivityParameters $parameters, \stdClass $stepStructure)
 {
     // Store current resources to clean removed
     $existingResources = $parameters->getSecondaryResources();
     $existingResources = $existingResources->toArray();
     // Publish new resources
     $publishedResources = array();
     if (!empty($stepStructure->resources)) {
         $i = 0;
         foreach ($stepStructure->resources as $resource) {
             $resourceNode = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneById($resource->resourceId);
             if (!empty($resourceNode)) {
                 $parameters->addSecondaryResource($resourceNode);
                 $publishedResources[] = $resourceNode;
             } else {
                 $warning = $this->translator->trans('warning_compl_resource_deleted', array('resourceId' => $resource->resourceId, 'resourceName' => $resource->name), "innova_tools");
                 $this->session->getFlashBag()->add('warning', $warning);
                 unset($stepStructure->resources[$i]);
             }
             $i++;
         }
     }
     // Clean removed resources
     foreach ($existingResources as $existingResource) {
         if (!in_array($existingResource, $publishedResources)) {
             $parameters->removeSecondaryResource($existingResource);
         }
     }
     return $this;
 }
 /**
  * Publish path
  * Create all needed resources for path to be played
  * 
  * @Route(
  *     "/publish/{id}/{redirect}",
  *     name         = "innova_path_publish",
  *     requirements = {"id" = "\d+"},
  *     options      = {"expose" = true}
  * )
  * @Method({"GET", "PUT"})
  */
 public function publishAction(Path $path, $redirect = false, Request $request)
 {
     $this->pathManager->checkAccess('EDIT', $path);
     $response = array();
     try {
         $this->publishingManager->publish($path);
         // Publish success
         $response['status'] = 'OK';
         $response['messages'] = array();
         $response['data'] = json_decode($path->getStructure());
         // Send updated data
     } catch (\Exception $e) {
         // Error
         $response['status'] = 'ERROR';
         $response['messages'] = array($e->getMessage());
         $response['data'] = null;
     }
     if ($redirect) {
         // That's not an AJAX call, so display a flash message and redirect the User
         $message = 'OK' === $response['status'] ? 'publish_success' : 'publish_error';
         $this->session->getFlashBag()->add('OK' === $response['status'] ? 'success' : 'error', $this->translator->trans($message, array(), 'path_wizards'));
         return new RedirectResponse($request->headers->get('referer'));
     }
     return new JsonResponse($response);
 }
Exemple #4
0
 public function testGetSetFlash()
 {
     $this->assertNull($this->session->getFlash('notice'));
     $this->assertEquals('default', $this->session->getFlash('notice', 'default'));
     $this->session->getFlashBag()->add('notice', 'foo');
     $this->session->getFlashBag()->add('notice', 'foo2');
     // test that BC works by only retrieving the first added.
     $this->assertEquals('foo', $this->session->getFlash('notice'));
     $this->assertNull($this->session->getFlash('notice'));
 }
Exemple #5
0
 public function testGetSetFlash()
 {
     set_error_handler(array($this, "deprecationErrorHandler"));
     $this->assertNull($this->session->getFlash('notice'));
     $this->assertEquals('default', $this->session->getFlash('notice', 'default'));
     $this->session->getFlashBag()->add('notice', 'foo');
     $this->session->getFlashBag()->add('notice', 'foo2');
     // test that BC works by only retrieving the first added.
     $this->assertEquals('foo', $this->session->getFlash('notice'));
     $this->assertNull($this->session->getFlash('notice'));
     restore_error_handler();
 }
 public function redirect($url, $message = null)
 {
     if ($this->request->isXmlHttpRequest()) {
         $json = array();
         $json['redirect'] = $url;
         if ($message) {
             $json['message'] = $message;
         }
         return new JsonResponse($json);
     } else {
         if ($message) {
             $this->session->getFlashBag()->add('success', $message);
         }
         return new RedirectResponse($url);
     }
 }
 /**
  * Test the flash manager get() method with a specified domain
  */
 public function testFlashMessageWithCustomDomain()
 {
     // Given
     $translator = $this->flashManager->getTranslator();
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array('my_bundle_success_message' => 'My bundle success message!'), 'en', 'MyCustomDomain');
     // When
     $this->session->getFlashBag()->set('my_bundle_success', 'my_bundle_success_message');
     $messages = $this->flashManager->get('success', 'MyCustomDomain');
     $this->session->getFlashBag()->set('my_bundle_success', 'my_bundle_success_message');
     $messagesWithoutDomain = $this->flashManager->get('success');
     // Then
     $this->assertCount(1, $messages);
     $this->assertCount(1, $messagesWithoutDomain);
     foreach ($messages as $message) {
         $this->assertEquals($message, 'My bundle success message!');
     }
     foreach ($messagesWithoutDomain as $message) {
         $this->assertEquals($message, 'my_bundle_success_message');
     }
 }
 /**
  * Returns all global assignable admin template variables
  *
  * @return array
  */
 public function getGlobals()
 {
     return ['user' => $this->session->get('admin/user'), 'menu' => $this->session->get('admin/menu'), 'flashbag' => $this->session->getFlashBag()];
 }
 protected function attachFlashBag(SessionInterface $session)
 {
     if (!$this->flashLogger->isFlashBagAttached() && $session instanceof Session) {
         $this->flashLogger->attachFlashBag($session->getFlashBag());
     }
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function getGlobals()
 {
     $scope = $this->session->get('admin/shop');
     return ['user' => $this->session->get('admin/user'), 'menu' => $this->adminMenuProvider->getMenu(), 'shops' => $this->session->get('admin/shops'), 'activeContextId' => $scope['id'], 'flashbag' => $this->session->getFlashBag()];
 }
 /**
  * Resets the flash bag.
  */
 public function reset()
 {
     $this->session->getFlashBag()->clear();
 }
 /**
  * @param string $key
  * @param string $value
  *
  * @return void
  */
 protected function addToSession($key, $value)
 {
     $this->session->getFlashBag()->add($key, $value);
 }
 protected function __construct(\Symfony\Component\HttpFoundation\Session\SessionInterface $session)
 {
     $session->start();
     $this->flashBag = $session->getFlashBag();
     return $this;
 }
 /**
  * @param string $type
  * @param string $message
  */
 protected function addFlash($type, $message)
 {
     $this->session->getFlashBag()->add($type, $message);
 }
 /**
  * Adds a flash message to the given session.
  *
  * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
  * @param string $type
  * @param string $message
  */
 protected function addUserFlash(SessionInterface $session, $type, $message)
 {
     $session->getFlashBag()->add($type, $message);
 }
Exemple #16
0
 /**
  * @todo Add inline documentation.
  *
  * @return type
  */
 public function hasFlashes()
 {
     return count($this->session->getFlashBag()->peekAll()) > 0;
 }
 public function testGetFlashBag()
 {
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface', $this->session->getFlashBag());
 }
Exemple #18
0
 /**
  * Sets a flash message for the next request
  *
  * @param  string  $message
  * @param  string  $type  [optional]
  *
  * @return \Deefour\Aide\Silex\Controller
  */
 protected function flash($message, $type = 'info')
 {
     $this->session->getFlashBag()->add('flash', ['type' => $type, 'message' => $message]);
     return $this;
 }