/**
  * {@inheritDoc}
  */
 public function setLabel($label)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setLabel', array($label));
     return parent::setLabel($label);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
 /**
  * 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()]);
 }