Skip to content

Commit

Permalink
Merge 6ea7f1b into e9340fe
Browse files Browse the repository at this point in the history
  • Loading branch information
DonCallisto committed Jul 25, 2017
2 parents e9340fe + 6ea7f1b commit ca5586e
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Grid/Source/Source.php
Expand Up @@ -217,7 +217,7 @@ protected function getItemsFromData($columns)
|| is_callable([$itemEntity, $fullFunctionName = 'is' . $functionName])) {
$fieldValue = call_user_func([$itemEntity, $fullFunctionName]);
} else {
throw new PropertyAccessDeniedException(sprintf('Property "%s" is not public or has no accessor.', $fieldName));
throw new PropertyAccessDeniedExceptio(sprintf('Property "%s" is not public or has no accessor.', $fieldName));
}
} elseif (isset($item[$fieldName])) {
$fieldValue = $item[$fieldName];
Expand All @@ -236,8 +236,9 @@ protected function getItemsFromData($columns)
* @param \APY\DataGridBundle\Grid\Column\Column[] $columns
* @param int $page
* @param int $limit
* @param int $maxResults
*
* @return \APY\DataGridBundle\DataGrid\Rows
* @return Rows
*/
public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = null)
{
Expand All @@ -246,7 +247,6 @@ public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = n
$serializeColumns = [];

foreach ($this->data as $key => $item) {
$keep = true;

foreach ($columns as $column) {
$fieldName = $column->getField();
Expand Down Expand Up @@ -443,7 +443,7 @@ public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = n
$row = new Row();

if ($this instanceof Vector) {
$row->setPrimaryField($this->id);
$row->setPrimaryField($this->getId());
}

foreach ($item as $fieldName => $fieldValue) {
Expand Down
41 changes: 30 additions & 11 deletions Grid/Source/Vector.php
Expand Up @@ -12,7 +12,15 @@

namespace APY\DataGridBundle\Grid\Source;

use APY\DataGridBundle\Grid\Column;
use APY\DataGridBundle\Grid\Column\ArrayColumn;
use APY\DataGridBundle\Grid\Column\BooleanColumn;
use APY\DataGridBundle\Grid\Column\Column;
use APY\DataGridBundle\Grid\Column\DateColumn;
use APY\DataGridBundle\Grid\Column\DateTimeColumn;
use APY\DataGridBundle\Grid\Column\NumberColumn;
use APY\DataGridBundle\Grid\Column\TextColumn;
use APY\DataGridBundle\Grid\Column\UntypedColumn;
use APY\DataGridBundle\Grid\Rows;

/**
* Vector is really an Array.
Expand Down Expand Up @@ -78,7 +86,7 @@ protected function guessColumns()
'visible' => true,
'field' => $id,
];
$guessedColumns[] = new Column\UntypedColumn($params);
$guessedColumns[] = new UntypedColumn($params);
}
}

Expand All @@ -88,7 +96,7 @@ protected function guessColumns()
$iteration = min(10, count($this->data));

foreach ($this->columns as $c) {
if (!$c instanceof Column\UntypedColumn) {
if (!$c instanceof UntypedColumn) {
continue;
}

Expand Down Expand Up @@ -152,26 +160,26 @@ 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) {
if ($c instanceof UntypedColumn) {
switch ($c->getType()) {
case 'date':
$column = new Column\DateColumn($c->getParams());
$column = new DateColumn($c->getParams());
break;
case 'datetime':
$column = new Column\DateTimeColumn($c->getParams());
$column = new DateTimeColumn($c->getParams());
break;
case 'boolean':
$column = new Column\BooleanColumn($c->getParams());
$column = new BooleanColumn($c->getParams());
break;
case 'number':
$column = new Column\NumberColumn($c->getParams());
$column = new NumberColumn($c->getParams());
break;
case 'array':
$column = new Column\ArrayColumn($c->getParams());
$column = new ArrayColumn($c->getParams());
break;
case 'text':
default:
$column = new Column\TextColumn($c->getParams());
$column = new TextColumn($c->getParams());
break;
}
} else {
Expand All @@ -192,9 +200,10 @@ public function getColumns($columns)
* @param \APY\DataGridBundle\Grid\Column\Column[] $columns
* @param int $page Page Number
* @param int $limit Rows Per Page
* @param int $maxResults Max rows
* @param int $gridDataJunction Grid data junction
*
* @return \APY\DataGridBundle\Grid\Rows
* @return Rows
*/
public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION)
{
Expand Down Expand Up @@ -226,6 +235,14 @@ public function setId($id)
$this->id = $id;
}

/**
* @return mixed
*/
public function getId()
{
return $this->id;
}

/**
* Set a two-dimentional array.
*
Expand All @@ -241,12 +258,14 @@ public function setData($data)
throw new \InvalidArgumentException('Data should be an array with content');
}

// This seems to exclude ...
if (is_object(reset($this->data))) {
foreach ($this->data as $key => $object) {
$this->data[$key] = (array) $object;
}
}

// ... this other (or vice versa)
$firstRaw = reset($this->data);
if (!is_array($firstRaw) || empty($firstRaw)) {
throw new \InvalidArgumentException('Data should be a two-dimentional array');
Expand Down

0 comments on commit ca5586e

Please sign in to comment.