protected function getBaseColumns()
 {
     $context = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $columns = new Columns($context);
     $columns->addColumn($this->col1);
     $columns->addColumn($this->col2);
     $columns->addColumn($this->col3);
     $this->assertAttributeEquals(array($this->col1, $this->col2, $this->col3), 'columns', $columns);
     return $columns;
 }
Beispiel #2
0
 /**
  * Prepare Grid for Drawing
  *
  * @return self
  *
  * @throws \Exception
  */
 protected function prepare()
 {
     if ($this->prepared) {
         return $this;
     }
     if ($this->source->isDataLoaded()) {
         $this->rows = $this->source->executeFromData($this->columns->getIterator(true), $this->page, $this->limit, $this->maxResults);
     } else {
         $this->rows = $this->source->execute($this->columns->getIterator(true), $this->page, $this->limit, $this->maxResults, $this->dataJunction);
     }
     if (!$this->rows instanceof Rows) {
         throw new \Exception('Source have to return Rows object.');
     }
     if (count($this->rows) == 0 && $this->page > 0) {
         $this->page = 0;
         $this->prepare();
         return $this;
     }
     //add row actions column
     if (count($this->rowActions) > 0) {
         foreach ($this->rowActions as $column => $rowActions) {
             if ($actionColumn = $this->columns->hasColumnById($column, true)) {
                 $actionColumn->setRowActions($rowActions);
             } else {
                 $actionColumn = new ActionsColumn($column, $this->actionsColumnTitle, $rowActions);
                 if ($this->actionsColumnSize > -1) {
                     $actionColumn->setSize($this->actionsColumnSize);
                 }
                 $this->columns->addColumn($actionColumn);
             }
         }
     }
     //add mass actions column
     if (count($this->massActions) > 0) {
         $this->columns->addColumn(new MassActionColumn(), 1);
     }
     $primaryColumnId = $this->columns->getPrimaryColumn()->getId();
     foreach ($this->rows as $row) {
         $row->setPrimaryField($primaryColumnId);
     }
     //@todo refactor autohide titles when no title is set
     if (!$this->showTitles) {
         $this->showTitles = false;
         foreach ($this->columns as $column) {
             if (!$this->showTitles) {
                 break;
             }
             if ($column->getTitle() != '') {
                 $this->showTitles = true;
                 break;
             }
         }
     }
     //get size
     if ($this->source->isDataLoaded()) {
         $this->source->populateSelectFiltersFromData($this->columns);
         $this->totalCount = $this->source->getTotalCountFromData($this->maxResults);
     } else {
         $this->source->populateSelectFilters($this->columns);
         $this->totalCount = $this->source->getTotalCount($this->maxResults);
     }
     if (!is_int($this->totalCount)) {
         throw new \Exception(sprintf('Source function getTotalCount need to return integer result, returned: %s', gettype($this->totalCount)));
     }
     $this->prepared = true;
     return $this;
 }
Beispiel #3
0
 /**
  * @param \APY\DataGridBundle\Grid\Columns $columns
  * @return null
  */
 public function getColumns($columns)
 {
     $token = empty($this->id);
     //makes the first column primary by default
     foreach ($this->columns as $c) {
         if ($c instanceof Column\UntypedColumn) {
             switch ($c->getType()) {
                 case 'date':
                     $column = new Column\DateColumn($c->getParams());
                     break;
                 case 'datetime':
                     $column = new Column\DateTimeColumn($c->getParams());
                     break;
                 case 'boolean':
                     $column = new Column\BooleanColumn($c->getParams());
                     break;
                 case 'number':
                     $column = new Column\NumberColumn($c->getParams());
                     break;
                 case 'array':
                     $column = new Column\ArrayColumn($c->getParams());
                     break;
                 case 'text':
                 default:
                     $column = new Column\TextColumn($c->getParams());
                     break;
             }
         } else {
             $column = $c;
         }
         if (!$column->isPrimary()) {
             $column->setPrimary(is_array($this->id) && in_array($column->getId(), $this->id) || $column->getId() == $this->id || $token);
         }
         $columns->addColumn($column);
         $token = false;
     }
 }