Skip to content

Commit

Permalink
Merge pull request #964 from APY/test-improvement-vector
Browse files Browse the repository at this point in the history
Test improvement vector
  • Loading branch information
DonCallisto authored Nov 19, 2017
2 parents 5a0bfad + 4f0ee67 commit 91b3f7f
Show file tree
Hide file tree
Showing 3 changed files with 290 additions and 24 deletions.
8 changes: 4 additions & 4 deletions Grid/Source/Source.php
Original file line number Diff line number Diff line change
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
51 changes: 31 additions & 20 deletions Grid/Source/Vector.php
Original file line number Diff line number Diff line change
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 @@ -45,6 +53,7 @@ class Vector extends Source
* Creates the Vector and sets its data.
*
* @param array $data
* @param array $columns
*/
public function __construct(array $data, array $columns = [])
{
Expand Down Expand Up @@ -78,7 +87,7 @@ protected function guessColumns()
'visible' => true,
'field' => $id,
];
$guessedColumns[] = new Column\UntypedColumn($params);
$guessedColumns[] = new UntypedColumn($params);
}
}

Expand All @@ -88,7 +97,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 +161,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 +201,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 +236,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 +259,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 All @@ -272,13 +292,4 @@ protected function hasColumn($id)

return false;
}

protected function getColumn($id)
{
foreach ($this->columns as $c) {
if ($id === $c->getId()) {
return $c;
}
}
}
}
Loading

0 comments on commit 91b3f7f

Please sign in to comment.