/** * @param array $subColumn * @param Column \APY\DataGridBundle\Grid\Column\Column */ protected function addReferencedColumnn(array $subColumn, Column $column) { $this->referencedColumns[$subColumn[0]][] = $subColumn[1]; if ($column->isFiltered()) { $helperQuery = $this->manager->createQueryBuilder($this->referencedMappings[$subColumn[0]]); $filters = $column->getFilters('document'); foreach ($filters as $filter) { $operator = $this->normalizeOperator($filter->getOperator()); $value = $this->normalizeValue($filter->getOperator(), $filter->getValue()); $helperQuery->field($subColumn[1])->{$operator}($value); $this->prepareQuery($this->query); $cursor = $helperQuery->getQuery()->execute(); foreach ($cursor as $resource) { if ($cursor->count() > 0) { $this->query->select($subColumn[0]); } if ($cursor->count() == 1) { $this->query->field($subColumn[0])->references($resource); } else { $this->query->addOr($this->query->expr()->field($subColumn[0])->references($resource)); } } } } }
/** * @param \APY\DataGridBundle\Grid\Column\Column[] $columns * @param int $page Page Number * @param int $limit Rows Per Page * @param int $gridDataJunction Grid data junction * @return \APY\DataGridBundle\Grid\Rows */ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION) { $this->query = $this->manager->createQueryBuilder($this->documentName); foreach ($columns as $column) { $this->query->select($column->getField()); if ($column->isSorted()) { $this->query->sort($column->getField(), $column->getOrder()); } if ($column->isPrimary()) { $column->setFilterable(false); } else { if ($column->isFiltered()) { // Some attributes of the column can be changed in this function $filters = $column->getFilters('document'); foreach ($filters as $filter) { //normalize values $operator = $this->normalizeOperator($filter->getOperator()); $value = $this->normalizeValue($filter->getOperator(), $filter->getValue()); if ($column->getDataJunction() === Column::DATA_DISJUNCTION) { $this->query->addOr($this->query->expr()->field($column->getField())->{$operator}($value)); } else { $this->query->field($column->getField())->{$operator}($value); } } } } } if ($page > 0) { $this->query->skip($page * $limit); } if ($limit > 0) { if ($maxResults !== null && $maxResults - $page * $limit < $limit) { $limit = $maxResults - $page * $limit; } $this->query->limit($limit); } elseif ($maxResults !== null) { $this->query->limit($maxResults); } //call overridden prepareQuery or associated closure $this->prepareQuery($this->query); //execute and get results $result = new Rows(); $cursor = $this->query->getQuery()->execute(); $this->count = $cursor->count(); foreach ($cursor as $resource) { $row = new Row(); $properties = $this->getClassProperties($resource); foreach ($columns as $column) { if (isset($properties[$column->getId()])) { $row->setField($column->getId(), $properties[$column->getId()]); } } //call overridden prepareRow or associated closure if (($modifiedRow = $this->prepareRow($row)) != null) { $result->addRow($modifiedRow); } } return $result; }