コード例 #1
0
ファイル: Grid.php プロジェクト: deeky666/APYDataGridBundle
 /**
  * Adds Column Extension - internal helper
  *
  * @param Column\Column $extension
  *
  * @return self
  */
 public function addColumnExtension($extension)
 {
     $this->columns->addExtension($extension);
     return $this;
 }
コード例 #2
0
 /**
  * @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->getQueryBuilder();
     foreach ($columns as $column) {
         //checks if exists '.' notation on referenced columns and build query if it's filtered
         $subColumn = explode('.', $column->getId());
         if (count($subColumn) > 1 && isset($this->referencedMappings[$subColumn[0]])) {
             $this->addReferencedColumnn($subColumn, $column);
             //must remove this referenced subColumn from processing
             $columns->offsetUnset($columns->key());
             continue;
         }
         $this->query->select($column->getField());
         if ($column->isSorted()) {
             $this->query->sort($column->getField(), $column->getOrder());
         }
         if ($column->isPrimary()) {
             $column->setFilterable(false);
         } elseif ($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[strtolower($column->getId())])) {
                 $row->setField($column->getId(), $properties[strtolower($column->getId())]);
             }
         }
         $this->addReferencedFields($row, $resource);
         //call overridden prepareRow or associated closure
         if (($modifiedRow = $this->prepareRow($row)) != null) {
             $result->addRow($modifiedRow);
         }
     }
     return $result;
 }