示例#1
0
 /**
  * Creates datagrid and triggers event after initialization
  *
  * @param DataGridInterface $datagrid
  *
  * @return DataGridInterface
  */
 public function create(DataGridInterface $datagrid)
 {
     $datagrid->init();
     $eventName = $this->getInitEventName($datagrid->getIdentifier());
     $event = new DataGridEvent($datagrid);
     $this->getDispatcher()->dispatch($eventName, $event);
     return $event->getDataGrid();
 }
 /**
  * {@inheritdoc}
  */
 public function configure(DataGridInterface $datagrid)
 {
     $datagrid->setIdentifier($this->identifier);
     $eventHandlers = $this->manager->getOptions()->getEventHandlers();
     $eventHandlers->add(new LoadEventHandler(['function' => $this->getFunction('load'), 'route' => $this->manager->getRouteForAction('grid')]));
     $eventHandlers->add(new EditRowEventHandler(['function' => $this->getFunction('edit'), 'row_action' => OptionInterface::ACTION_EDIT, 'route' => $this->manager->getRouteForAction('edit')]));
     $eventHandlers->add(new ClickRowEventHandler(['function' => $this->getFunction('click'), 'route' => $this->manager->getRouteForAction('edit')]));
     $eventHandlers->add(new DeleteRowEventHandler(['function' => $this->getFunction('delete'), 'row_action' => OptionInterface::ACTION_DELETE, 'route' => $this->manager->getRouteForAction('delete')]));
     $datagrid->setRepository($this->repository);
     $datagrid->setManager($this->manager);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function loadResults(Request $request)
 {
     $this->columns = $this->dataGrid->getColumns();
     $queryBuilder = $this->dataGrid->getDataGridQueryBuilder();
     // quickest way to automatically bind current locale QB without injecting
     // whole container in repository or fighting with request-scope issues
     if ($this->hasLocalePlaceholder($queryBuilder->getDQL())) {
         $queryBuilder->setParameter('locale', $request->getLocale());
     }
     $orderBy = $this->columns->get($this->orderBy)->getSource();
     $paginatorQuery = clone $queryBuilder;
     $paginator = new Paginator($paginatorQuery->getQuery(), $fetchJoinCollection = true);
     $total = $paginator->count();
     $queryBuilder->addOrderBy($orderBy, $this->orderDir);
     $queryBuilder->select($this->getSelectClause());
     $queryBuilder->setFirstResult($this->offset);
     $queryBuilder->setMaxResults($this->limit);
     $query = $queryBuilder->getQuery();
     $query->useResultCache(true, 3600, $this->dataGrid->getIdentifier());
     $result = $query->getArrayResult();
     return ['data_id' => $this->requestId, 'rows_num' => $total, 'starting_from' => $this->offset, 'total' => $total, 'filtered' => $total, 'rows' => $this->processResults($result)];
 }