Skip to content

Commit 62542f7

Browse files
authored
Merge branch 'master' into npotier-patch-1
2 parents d861847 + 352c6dd commit 62542f7

37 files changed

Lines changed: 359 additions & 212 deletions

.travis.yml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
4+
- 7.2
5+
- 7.3
66

77
matrix:
88
include:
9-
- php: 5.6
9+
- php: 7.2
1010
env: |
11-
SYMFONY_VERSION=2.7.*
12-
- php: 5.6
13-
env: |
14-
SYMFONY_VERSION=2.8.*
15-
- php: 7.1
11+
SYMFONY_VERSION=^3.0
12+
- php: 7.2
1613
env: |
1714
SYMFONY_VERSION=^4.0
1815
1916
before_install:
17+
- echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
2018
- |
2119
if [ "${SYMFONY_VERSION}" != "" ]; then
22-
packages="form dependency-injection config http-foundation http-kernel options-resolver security serializer"
20+
packages="form dependency-injection config http-foundation http-kernel options-resolver security-guard serializer"
2321
devpackages="framework-bundle browser-kit templating expression-language"
2422
for package in $packages
2523
do
@@ -31,13 +29,9 @@ before_install:
3129
done
3230
fi;
3331
34-
35-
before_script:
36-
- echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
37-
3832
install:
3933
- travis_retry composer self-update
40-
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
34+
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
4135
- curl -s http://getcomposer.org/installer | php
4236
- php composer.phar install --dev --no-interaction
4337

@@ -46,4 +40,4 @@ script:
4640
- php vendor/bin/phpunit -c phpunit.xml.dist
4741

4842
after_success:
49-
- php vendor/bin/coveralls
43+
- php vendor/bin/php-coveralls

DependencyInjection/Configuration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Configuration implements ConfigurationInterface
1717
*/
1818
public function getConfigTreeBuilder()
1919
{
20-
$treeBuilder = new TreeBuilder();
21-
$rootNode = $treeBuilder->root('apy_data_grid');
20+
$treeBuilder = new TreeBuilder('apy_data_grid');
21+
$rootNode = $treeBuilder->getRootNode();
2222

2323
$rootNode
2424
->children()
@@ -32,7 +32,7 @@ public function getConfigTreeBuilder()
3232
->prototype('scalar')->end()
3333
->end()
3434
->booleanNode('persistence')->defaultFalse()->end()
35-
->scalarNode('theme')->defaultValue('APYDataGridBundle::blocks.html.twig')->end()
35+
->scalarNode('theme')->defaultValue('@APYDataGrid/blocks.html.twig')->end()
3636
->scalarNode('no_data_message')->defaultValue('No data')->end()
3737
->scalarNode('no_result_message')->defaultValue('No result')->end()
3838
->scalarNode('actions_columns_size')->defaultValue(-1)->end()

Grid/Column/Column.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,12 @@ public function getData()
528528
$result = [];
529529

530530
$hasValue = false;
531-
if ($this->data['from'] != $this::DEFAULT_VALUE) {
531+
if (isset($this->data['from']) && $this->data['from'] != $this::DEFAULT_VALUE) {
532532
$result['from'] = $this->data['from'];
533533
$hasValue = true;
534534
}
535535

536-
if ($this->data['to'] != $this::DEFAULT_VALUE) {
536+
if (isset($this->data['to']) && $this->data['to'] != $this::DEFAULT_VALUE) {
537537
$result['to'] = $this->data['to'];
538538
$hasValue = true;
539539
}
@@ -687,7 +687,7 @@ public function getFilters($source)
687687
{
688688
$filters = [];
689689

690-
if ($this->hasOperator($this->data['operator'])) {
690+
if (isset($this->data['operator']) && $this->hasOperator($this->data['operator'])) {
691691
if ($this instanceof ArrayColumn && in_array($this->data['operator'], [self::OPERATOR_EQ, self::OPERATOR_NEQ])) {
692692
$filters[] = new Filter($this->data['operator'], $this->data['from']);
693693
} else {

Grid/Column/DateColumn.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class DateColumn extends DateTimeColumn
2020

2121
protected $fallbackFormat = 'Y-m-d';
2222

23+
protected $fallbackInputFormat = 'Y-m-d';
24+
2325
public function getFilters($source)
2426
{
2527
$parentFilters = parent::getFilters($source);

Grid/Column/DateTimeColumn.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ class DateTimeColumn extends Column
2424

2525
protected $fallbackFormat = 'Y-m-d H:i:s';
2626

27+
protected $inputFormat;
28+
29+
protected $fallbackInputFormat = 'Y-m-d H:i:s';
30+
2731
protected $timezone;
2832

2933
public function __initialize(array $params)
3034
{
3135
parent::__initialize($params);
3236

3337
$this->setFormat($this->getParam('format'));
38+
$this->setInputFormat($this->getParam('inputFormat', $this->fallbackInputFormat));
3439
$this->setOperators($this->getParam('operators', [
3540
self::OPERATOR_EQ,
3641
self::OPERATOR_NEQ,
@@ -56,7 +61,7 @@ public function isQueryValid($query)
5661

5762
protected function isDateTime($query)
5863
{
59-
return strtotime($query) !== false;
64+
return false !== \DateTime::createFromFormat($this->inputFormat, $query);
6065
}
6166

6267
public function getFilters($source)
@@ -65,7 +70,7 @@ public function getFilters($source)
6570

6671
$filters = [];
6772
foreach ($parentFilters as $filter) {
68-
$filters[] = ($filter->getValue() === null) ? $filter : $filter->setValue(new \DateTime($filter->getValue()));
73+
$filters[] = ($filter->getValue() === null) ? $filter : $filter->setValue(\DateTime::createFromFormat($this->inputFormat, $filter->getValue()));
6974
}
7075

7176
return $filters;
@@ -160,6 +165,18 @@ public function getFormat()
160165
return $this->format;
161166
}
162167

168+
public function setInputFormat($inputFormat)
169+
{
170+
$this->inputFormat = $inputFormat;
171+
172+
return $this;
173+
}
174+
175+
public function getInputFormat()
176+
{
177+
return $this->inputFormat;
178+
}
179+
163180
public function getTimezone()
164181
{
165182
return $this->timezone;

Grid/Export/Export.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
abstract class Export implements ExportInterface, ContainerAwareInterface
2121
{
22-
const DEFAULT_TEMPLATE = 'APYDataGridBundle::blocks.html.twig';
22+
const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig';
2323

2424
protected $title;
2525

@@ -459,7 +459,7 @@ protected function getTemplatesFromString($theme)
459459
$templates = [];
460460

461461
$template = $this->twig->loadTemplate($theme);
462-
while ($template instanceof \Twig_Template) {
462+
while ($template instanceof TemplateWrapper) {
463463
$templates[] = $template;
464464
$template = $template->getParent([]);
465465
}

Grid/Grid.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\HttpFoundation\RedirectResponse;
2727
use Symfony\Component\HttpFoundation\Request;
2828
use Symfony\Component\HttpFoundation\Response;
29+
use Twig\TemplateWrapper;
2930

3031
class Grid implements GridInterface
3132
{
@@ -359,8 +360,10 @@ public function initialize()
359360
$this->setPersistence($config->isPersisted());
360361

361362
// Route parameters
362-
$routeParameters = $config->getRouteParameters();
363-
if (!empty($routeParameters)) {
363+
$routeParameters = [];
364+
$parameters = $config->getRouteParameters();
365+
if (!empty($parameters)) {
366+
$routeParameters = $parameters;
364367
foreach ($routeParameters as $parameter => $value) {
365368
$this->setRouteParameter($parameter, $value);
366369
}
@@ -1135,7 +1138,7 @@ protected function set($key, $data)
11351138

11361139
protected function saveSession()
11371140
{
1138-
if (!empty($this->sessionData)) {
1141+
if (!empty($this->sessionData) && !empty($this->hash)) {
11391142
$this->session->set($this->hash, $this->sessionData);
11401143
}
11411144
}
@@ -1395,12 +1398,11 @@ public function getRowActions()
13951398
public function setTemplate($template)
13961399
{
13971400
if ($template !== null) {
1398-
if ($template instanceof \Twig_Template) {
1401+
if ($template instanceof TemplateWrapper) {
13991402
$template = '__SELF__' . $template->getTemplateName();
14001403
} elseif (!is_string($template)) {
14011404
throw new \Exception(self::TWIG_TEMPLATE_LOAD_EX_MSG);
14021405
}
1403-
14041406
$this->set(self::REQUEST_QUERY_TEMPLATE, $template);
14051407
$this->saveSession();
14061408
}
@@ -2147,7 +2149,7 @@ public function getGridResponse($param1 = null, $param2 = null, Response $respon
21472149
if ($view === null) {
21482150
return $parameters;
21492151
} else {
2150-
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
2152+
return new Response($this->container->get('twig')->render($view, $parameters, $response));
21512153
}
21522154
}
21532155
}

Grid/GridManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ public function getGridManagerResponse($param1 = null, $param2 = null, Response
193193
return $parameters;
194194
}
195195

196-
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
196+
$content = $this->container->get('twig')->render($view, $parameters);
197+
198+
if (null === $response) {
199+
$response = new Response();
200+
}
201+
202+
$response->setContent($content);
203+
204+
return $response;
197205
}
198206
}
199207

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class MyEntity
109109
And clear your cache.
110110

111111
## Bundle history
112+
112113
Datagrid for Symfony inspired by Zfdatagrid and Magento Grid.
113114
This bundle was initiated by Stanislav Turza (Sorien).
114115

115116
See [CHANGELOG](https://github.com/APY/APYDataGridBundle/blob/master/CHANGELOG.md) and [UPGRADE 2.0](https://github.com/APY/APYDataGridBundle/blob/master/UPGRADE-2.0.md)
116-

Resources/config/services.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
<argument>%apy_data_grid.actions_columns_title%</argument>
4242
</call>
4343
</service>
44+
45+
<service id="%grid.class%" alias="grid" public="true">
46+
</service>
4447

4548
<service id="grid.manager" class="%grid.manager.class%">
4649
<argument type="service" id="service_container" />

0 commit comments

Comments
 (0)