function it_normalizes_a_datagrid_view(DatagridView $view, UserInterface $user)
 {
     $user->getId()->willReturn(666);
     $view->getId()->willReturn(42);
     $view->getOwner()->willReturn($user);
     $view->getLabel()->willReturn('Cameras');
     $view->getType()->willReturn('public');
     $view->getDatagridAlias()->willReturn('product-grid');
     $view->getColumns()->willReturn(['sku', 'name', 'brand']);
     $view->getFilters()->willReturn('i=1&p=10&s%5Bupdated%5D=1&f%5Bfamily%5D%5Bvalue%5D%5B%5D=mugs');
     $view->getOrder()->willReturn('sku,name,brand');
     $this->normalize($view, 'json')->shouldReturn(['id' => 42, 'owner_id' => 666, 'label' => 'Cameras', 'type' => 'public', 'datagrid_alias' => 'product-grid', 'columns' => ['sku', 'name', 'brand'], 'filters' => 'i=1&p=10&s%5Bupdated%5D=1&f%5Bfamily%5D%5Bvalue%5D%5B%5D=mugs']);
 }
 /**
  * Create a datagrid view
  *
  * @param array $data
  *
  * @return DatagridView
  */
 protected function createDatagridView(array $data)
 {
     $columns = array_map(function ($column) {
         return trim($column);
     }, explode(',', $data['columns']));
     $view = new DatagridView();
     $view->setLabel($data['label']);
     $view->setDatagridAlias($data['alias']);
     $view->setFilters(urlencode($data['filters']));
     $view->setColumns($columns);
     $view->setOwner($this->getUser('Peter'));
     $this->validate($view);
     $this->persist($view);
     return $view;
 }
 /**
  * Remove a datagrid view
  *
  * @param Request      $request
  * @param DatagridView $view
  *
  * @throws DeleteException If the current user doesn't own the view
  *
  * @return Response
  */
 public function removeAction(Request $request, DatagridView $view)
 {
     if ($view->getOwner() !== $this->getUser()) {
         throw new DeleteException($this->getTranslator()->trans('flash.datagrid view.not removable'));
     }
     $this->datagridViewManager->remove($view);
     $this->addFlash('success', 'flash.datagrid view.removed');
     return new Response('', 204);
 }
 /**
  * {@inheritDoc}
  */
 public function getFilters()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getFilters', array());
     return parent::getFilters();
 }
 /**
  * Remove a datagrid view
  *
  * @param DatagridView $view
  *
  * @throws DeleteException If the current user doesn't own the view
  *
  * @return Response
  */
 public function removeAction(DatagridView $view)
 {
     if ($view->getOwner() !== $this->tokenStorage->getToken()->getUser()) {
         throw new DeleteException($this->translator->trans('flash.datagrid view.not removable'));
     }
     $this->datagridViewManager->remove($view);
     $this->request->getSession()->getFlashBag()->add('success', new Message('flash.datagrid view.removed'));
     return new Response('', 204);
 }
 /**
  * Save the Datagrid View received through the $request for the grid with the given $alias.
  *
  * If any errors occur during the writing process, a Json response is sent with {'errors' => 'Error message'}.
  * If success, return a Json response with the id of the saved View.
  *
  * @param Request $request
  * @param string  $alias
  *
  * @return JsonResponse
  */
 public function saveAction(Request $request, $alias)
 {
     $view = $request->request->get('view', null);
     if (null === $view) {
         return new BadRequestHttpException('Parameter "view" needed in the request.');
     }
     if (isset($view['id'])) {
         $creation = false;
         $datagridView = $this->datagridViewRepo->find($view['id']);
     } else {
         $creation = true;
         $user = $this->tokenStorage->getToken()->getUser();
         $datagridView = new DatagridView();
         $datagridView->setOwner($user);
         $datagridView->setDatagridAlias($alias);
         $datagridView->setLabel($view['label']);
     }
     if (null === $datagridView) {
         return new NotFoundHttpException();
     }
     $datagridView->setColumns(explode(',', $view['columns']));
     $datagridView->setFilters($view['filters']);
     $violations = $this->validator->validate($datagridView);
     if ($violations->count()) {
         $messages = [];
         foreach ($violations as $violation) {
             $messages[] = $this->translator->trans($violation->getMessage());
         }
         return new JsonResponse($messages, 400);
     }
     $this->saver->save($datagridView);
     if ($creation) {
         $request->getSession()->getFlashBag()->add('success', new Message('grid.view_selector.flash.created'));
     }
     return new JsonResponse(['id' => $datagridView->getId()]);
 }