コード例 #1
1
ファイル: BaseController.php プロジェクト: peterAK/pgs-sts
 /**
  * @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!');
 }
コード例 #2
1
 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;
 }
コード例 #3
1
 /**
  * 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);
 }
コード例 #4
0
ファイル: SessionTest.php プロジェクト: laubosslink/lab
 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'));
 }
コード例 #5
0
ファイル: SessionTest.php プロジェクト: rodionrakib/twig
 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();
 }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
 /**
  * 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');
     }
 }
コード例 #8
0
 /**
  * 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()];
 }
コード例 #9
0
 protected function attachFlashBag(SessionInterface $session)
 {
     if (!$this->flashLogger->isFlashBagAttached() && $session instanceof Session) {
         $this->flashLogger->attachFlashBag($session->getFlashBag());
     }
 }
コード例 #10
0
ファイル: AdminExtension.php プロジェクト: pguso/WellCommerce
 /**
  * {@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()];
 }
コード例 #11
0
 /**
  * Resets the flash bag.
  */
 public function reset()
 {
     $this->session->getFlashBag()->clear();
 }
コード例 #12
0
 /**
  * @param string $key
  * @param string $value
  *
  * @return void
  */
 protected function addToSession($key, $value)
 {
     $this->session->getFlashBag()->add($key, $value);
 }
コード例 #13
0
 protected function __construct(\Symfony\Component\HttpFoundation\Session\SessionInterface $session)
 {
     $session->start();
     $this->flashBag = $session->getFlashBag();
     return $this;
 }
コード例 #14
0
 /**
  * @param string $type
  * @param string $message
  */
 protected function addFlash($type, $message)
 {
     $this->session->getFlashBag()->add($type, $message);
 }
コード例 #15
0
 /**
  * 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);
 }
コード例 #16
0
ファイル: SessionHelper.php プロジェクト: dragoonis/framework
 /**
  * @todo Add inline documentation.
  *
  * @return type
  */
 public function hasFlashes()
 {
     return count($this->session->getFlashBag()->peekAll()) > 0;
 }
コード例 #17
0
 public function testGetFlashBag()
 {
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface', $this->session->getFlashBag());
 }
コード例 #18
0
ファイル: Controller.php プロジェクト: deefour/aide
 /**
  * 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;
 }