Beispiel #1
0
 /**
  * Normaliza as colunas passadas por parametro e transforma em objetos
  * do tipo {@link Column}.
  *
  * @param string[]|array|Column[] $columns
  * @return Column[]
  */
 public static function normalizeColumns(array $columns)
 {
     $normalizedCols = array();
     foreach ($columns as $col) {
         if (is_string($col)) {
             // simples
             $normalizedCols[] = new Column($col);
         } else {
             // referencia completa
             if ($col instanceof Column) {
                 $normalizedCols[] = $col;
                 continue;
             }
             $column = new Column($col['name'], isset($col['data']) ? $col['data'] : null);
             if (isset($col['orderable'])) {
                 $column->setOrderable((bool) $col['orderable']);
             }
             if (isset($col['searchable'])) {
                 $column->setSearchable((bool) $col['searchable']);
             }
             if (isset($col['subcolumns'])) {
                 $column->setSubColumns(self::normalizeColumns((array) $col['subcolumns']));
             }
             $normalizedCols[] = $column;
         }
     }
     return $normalizedCols;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function getFilter()
 {
     if ($this->isTotalizable) {
         $filter = new GenericTotalizableFilter();
     } else {
         $filter = new GenericFilter();
     }
     if (isset($this->outputCallback)) {
         $filter->setOutputCallback($this->outputCallback);
     }
     if (isset($this->firstResult)) {
         $filter->setFirstResult($this->firstResult);
     }
     if (isset($this->maxResults)) {
         $filter->setMaxResults($this->maxResults);
     }
     if (isset($this->globalSearch)) {
         $filter->setGlobalSearch(new Searching($this->globalSearch));
     }
     $columns = array_map(function ($colData) {
         $col = new Column($colData['name'], $colData['data']);
         $col->setOrderable($colData['orderable']);
         $col->setSearchable($colData['searchable']);
         $col->setSubColumns(array_map(function ($subcolData) {
             $subcol = new Column($subcolData['name'], $subcolData['data']);
             $subcol->setOrderable($subcolData['orderable']);
             $subcol->setSearchable($subcolData['searchable']);
             return $subcol;
         }, $colData['subcolumns']));
         return $col;
     }, $this->columns);
     $orderings = array_map(function ($colData) use($columns) {
         return new Ordering($columns[$colData['name']], $colData['dir']);
     }, $this->orders);
     $columnSearchs = array_map(function ($colData) {
         return new Searching($colData['searchValue'], $colData['name']);
     }, $this->columnSearchs);
     $filter->setColumns($columns);
     $filter->setOrderings($orderings);
     $filter->setColumnSearchs($columnSearchs);
     return $filter;
 }
 public function defaultColumnsProvider()
 {
     $col1 = array('name' => 'foo', 'data' => 'bar', 'orderable' => true, 'searchable' => false);
     $expCol1 = new Column('foo', 'bar');
     $expCol1->setOrderable(true)->setSearchable(false);
     $col2 = array('name' => 'baz', 'subcolumns' => array('bar', 'foo'));
     $expCol2 = new Column('baz');
     $expCol2->setSubColumns(array(new Column('bar'), new Column('foo')));
     return array(array(array('foo'), array(new Column('foo'))), array(array('foo', 'bar'), array(new Column('foo'), new Column('bar'))), array(array($col1), array($expCol1)), array(array($col2), array($expCol2)), array(array($col3 = new Column('foobar')), array($col3)), array(array('foo', array('name' => 'bar'), $col4 = new Column('baz')), array(new Column('foo'), new Column('bar'), $col4)));
 }
Beispiel #4
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetSubcolumnsMustBeAnArrayOfColumns()
 {
     $col = new Column('foo');
     $scols = array('a', 'b');
     $col->setSubColumns($scols);
 }