Skip to content

Commit 91b3f7f

Browse files
authored
Merge pull request #964 from APY/test-improvement-vector
Test improvement vector
2 parents 5a0bfad + 4f0ee67 commit 91b3f7f

File tree

3 files changed

+290
-24
lines changed

3 files changed

+290
-24
lines changed

Grid/Source/Source.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ protected function getItemsFromData($columns)
217217
|| is_callable([$itemEntity, $fullFunctionName = 'is' . $functionName])) {
218218
$fieldValue = call_user_func([$itemEntity, $fullFunctionName]);
219219
} else {
220-
throw new PropertyAccessDeniedException(sprintf('Property "%s" is not public or has no accessor.', $fieldName));
220+
throw new PropertyAccessDeniedExceptio(sprintf('Property "%s" is not public or has no accessor.', $fieldName));
221221
}
222222
} elseif (isset($item[$fieldName])) {
223223
$fieldValue = $item[$fieldName];
@@ -236,8 +236,9 @@ protected function getItemsFromData($columns)
236236
* @param \APY\DataGridBundle\Grid\Column\Column[] $columns
237237
* @param int $page
238238
* @param int $limit
239+
* @param int $maxResults
239240
*
240-
* @return \APY\DataGridBundle\DataGrid\Rows
241+
* @return Rows
241242
*/
242243
public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = null)
243244
{
@@ -246,7 +247,6 @@ public function executeFromData($columns, $page = 0, $limit = 0, $maxResults = n
246247
$serializeColumns = [];
247248

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

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

445445
if ($this instanceof Vector) {
446-
$row->setPrimaryField($this->id);
446+
$row->setPrimaryField($this->getId());
447447
}
448448

449449
foreach ($item as $fieldName => $fieldValue) {

Grid/Source/Vector.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212

1313
namespace APY\DataGridBundle\Grid\Source;
1414

15-
use APY\DataGridBundle\Grid\Column;
15+
use APY\DataGridBundle\Grid\Column\ArrayColumn;
16+
use APY\DataGridBundle\Grid\Column\BooleanColumn;
17+
use APY\DataGridBundle\Grid\Column\Column;
18+
use APY\DataGridBundle\Grid\Column\DateColumn;
19+
use APY\DataGridBundle\Grid\Column\DateTimeColumn;
20+
use APY\DataGridBundle\Grid\Column\NumberColumn;
21+
use APY\DataGridBundle\Grid\Column\TextColumn;
22+
use APY\DataGridBundle\Grid\Column\UntypedColumn;
23+
use APY\DataGridBundle\Grid\Rows;
1624

1725
/**
1826
* Vector is really an Array.
@@ -45,6 +53,7 @@ class Vector extends Source
4553
* Creates the Vector and sets its data.
4654
*
4755
* @param array $data
56+
* @param array $columns
4857
*/
4958
public function __construct(array $data, array $columns = [])
5059
{
@@ -78,7 +87,7 @@ protected function guessColumns()
7887
'visible' => true,
7988
'field' => $id,
8089
];
81-
$guessedColumns[] = new Column\UntypedColumn($params);
90+
$guessedColumns[] = new UntypedColumn($params);
8291
}
8392
}
8493

@@ -88,7 +97,7 @@ protected function guessColumns()
8897
$iteration = min(10, count($this->data));
8998

9099
foreach ($this->columns as $c) {
91-
if (!$c instanceof Column\UntypedColumn) {
100+
if (!$c instanceof UntypedColumn) {
92101
continue;
93102
}
94103

@@ -152,26 +161,26 @@ public function getColumns($columns)
152161
$token = empty($this->id); //makes the first column primary by default
153162

154163
foreach ($this->columns as $c) {
155-
if ($c instanceof Column\UntypedColumn) {
164+
if ($c instanceof UntypedColumn) {
156165
switch ($c->getType()) {
157166
case 'date':
158-
$column = new Column\DateColumn($c->getParams());
167+
$column = new DateColumn($c->getParams());
159168
break;
160169
case 'datetime':
161-
$column = new Column\DateTimeColumn($c->getParams());
170+
$column = new DateTimeColumn($c->getParams());
162171
break;
163172
case 'boolean':
164-
$column = new Column\BooleanColumn($c->getParams());
173+
$column = new BooleanColumn($c->getParams());
165174
break;
166175
case 'number':
167-
$column = new Column\NumberColumn($c->getParams());
176+
$column = new NumberColumn($c->getParams());
168177
break;
169178
case 'array':
170-
$column = new Column\ArrayColumn($c->getParams());
179+
$column = new ArrayColumn($c->getParams());
171180
break;
172181
case 'text':
173182
default:
174-
$column = new Column\TextColumn($c->getParams());
183+
$column = new TextColumn($c->getParams());
175184
break;
176185
}
177186
} else {
@@ -192,9 +201,10 @@ public function getColumns($columns)
192201
* @param \APY\DataGridBundle\Grid\Column\Column[] $columns
193202
* @param int $page Page Number
194203
* @param int $limit Rows Per Page
204+
* @param int $maxResults Max rows
195205
* @param int $gridDataJunction Grid data junction
196206
*
197-
* @return \APY\DataGridBundle\Grid\Rows
207+
* @return Rows
198208
*/
199209
public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION)
200210
{
@@ -226,6 +236,14 @@ public function setId($id)
226236
$this->id = $id;
227237
}
228238

239+
/**
240+
* @return mixed
241+
*/
242+
public function getId()
243+
{
244+
return $this->id;
245+
}
246+
229247
/**
230248
* Set a two-dimentional array.
231249
*
@@ -241,12 +259,14 @@ public function setData($data)
241259
throw new \InvalidArgumentException('Data should be an array with content');
242260
}
243261

262+
// This seems to exclude ...
244263
if (is_object(reset($this->data))) {
245264
foreach ($this->data as $key => $object) {
246265
$this->data[$key] = (array) $object;
247266
}
248267
}
249268

269+
// ... this other (or vice versa)
250270
$firstRaw = reset($this->data);
251271
if (!is_array($firstRaw) || empty($firstRaw)) {
252272
throw new \InvalidArgumentException('Data should be a two-dimentional array');
@@ -272,13 +292,4 @@ protected function hasColumn($id)
272292

273293
return false;
274294
}
275-
276-
protected function getColumn($id)
277-
{
278-
foreach ($this->columns as $c) {
279-
if ($id === $c->getId()) {
280-
return $c;
281-
}
282-
}
283-
}
284295
}

0 commit comments

Comments
 (0)