Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pfilsx committed Mar 22, 2019
2 parents a11e28d + a8a3fd0 commit 5757bc7
Show file tree
Hide file tree
Showing 27 changed files with 965 additions and 14 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ install:

script:
- mkdir -p build/logs
- php vendor/bin/phpunit -c phpunit.xml.dist
- php vendor/bin/phpunit -c phpunit.xml.dist

after_success:
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar --output-document="${HOME}/bin/coveralls"
- chmod u+x "${HOME}/bin/coveralls"
- coveralls -v
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DataGridBundle
==============
General:
[![Build Status](https://travis-ci.com/pfilsx/DataGridBundle.svg?branch=master)](https://travis-ci.com/pfilsx/DataGridBundle)

Quality:
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/pfilsx/DataGridBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/pfilsx/DataGridBundle/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/pfilsx/DataGridBundle/badges/build.png?b=master)](https://scrutinizer-ci.com/g/pfilsx/DataGridBundle/build-status/master)
[![Code Intelligence Status](https://scrutinizer-ci.com/g/pfilsx/DataGridBundle/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence)
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"description": "Symfony 4 Data Grid rendering bundle.",
"keywords": [
"datagrid", "Symfony", "bundle"
"datagrid", "symfony4", "bundle", "data-table", "pagination", "sort", "filters", "table"
],
"authors": [
{
Expand All @@ -14,6 +14,7 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.1",
"symfony/framework-bundle": "^4.0",
"symfony/orm-pack": "*",
"symfony/flex": "^1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Columns/DataColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getFormat(): string
*/
protected function setFormat(string $format): void
{
$this->format = $format;
$this->format = strtolower($format);
}

protected function checkConfiguration()
Expand Down
17 changes: 10 additions & 7 deletions src/Grid/Columns/ImageColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ class ImageColumn extends DataColumn

protected $format = 'html';

protected $alt = '';
protected $alt;

protected $noImageMessage = '-';

function getCellContent($entity, ?DataGrid $grid)
{
$value = (string)$this->getCellValue($entity);
if (!empty($value)){
if ($this->format !== 'raw'){
if ($this->format === 'html'){
return $grid->getTemplate()->renderBlock('grid_img', [
'src' => $value,
'width' => $this->width,
'height' => $this->height,
'alt' => $this->alt
'alt' => $this->getAlt($entity)
]);
}
return htmlspecialchars($value);
Expand Down Expand Up @@ -70,17 +70,20 @@ protected function setHeight(int $height): void
}

/**
* @param $entity
* @return string
*/
public function getAlt(): string
public function getAlt($entity): string
{
return $this->alt;
return $alt = is_callable($this->alt)
? htmlspecialchars(call_user_func_array($this->alt, [$entity]))
: '';
}

/**
* @param string $alt
* @param callable $alt
*/
protected function setAlt(string $alt): void
protected function setAlt(callable $alt): void
{
$this->alt = $alt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/DataGridFiltersBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function addCustomFilter(string $attribute, callable $callback): DataGrid
public function addDateFilter(string $attribute, string $comparison = 'equal'): DataGridFiltersBuilderInterface
{
if (array_key_exists($attribute, $this->params)) {
$comparisonFunc = strtolower($comparison) . 'Date';
$comparisonFunc = lcfirst($comparison) . 'Date';
if (method_exists($this, $comparisonFunc)) {
$this->$comparisonFunc($attribute);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/DataGridFiltersBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function addRelationFilter(string $attribute, string $relationClass): sel

public function addCustomFilter(string $attribute, callable $callback): self;

public function addDateFilter(string $attribute): self;
public function addDateFilter(string $attribute, string $comparison = 'equal'): self;

/**
* @internal
Expand Down
68 changes: 68 additions & 0 deletions src/Resources/doc/columns/ActionColumn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
ActionColumn Class Reference
============================

Usage
-----

.. code-block:: php
$builder->addColumn(self::ACTION_COLUMN, [
'pathPrefix' => 'path_prefix'
]);
Configuration
-------------

attributes - array(default: [])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
html attributes to be applied to the tag <td>.

buttonsTemplate - string(default: '{show} {edit} {delete}')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
buttons rendering template.

buttons - array(default: [])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can be used to override default button rendering.

.. code-block:: php
$builder->addColumn(self::ACTION_COLUMN, [
'buttons' => [
'show' => function(Object $entity, string $url){
return '<a href="'.$url.'?id='.$entity->id.'">Show</a>';
}
]
]);
buttonsVisibility - array(default: ['show' => true, 'edit' => true, 'delete' => true])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can be used to set visibility of each button.

format - string(default: 'raw')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Format of the output data(raw|html).

pathPrefix - string(default: null)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Path prefix would be used in default url generation.

visible - boolean(default: true)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
whether to display a column.

urlGenerator - callable(default: null)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can be used to override default url generation function.

.. code-block:: php
$builder->addColumn(self::ACTION_COLUMN, [
'buttons' => [
'urlGenerator' => function($entity, string $action, RouterInterface $router){
return $router->generate('entity-'.$action, ['guid' => $entity->getId()]);
}
]
]);
66 changes: 66 additions & 0 deletions src/Resources/doc/columns/BooleanColumn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ActionColumn Class Reference
============================

Usage
-----

.. code-block:: php
$builder->addColumn(self::BOOLEAN_COLUMN, [
'attribute' => 'entity_attribute',
'trueValue' => 'yes',
'falseValue' => 'no'
]);
Configuration
-------------

attribute - string(default: null)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entity attribute.

attributes - array(default: [])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
html attributes to be applied to the tag <td>.

filter - array(default: [])
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Filter configuration. See filters docs.

.. code-block:: php
$builder->addColumn(self::BOOLEAN_COLUMN, [
...
'filter' => [
'class' => self::FILTER_BOOLEAN
]
]);
format - string(default: 'raw')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Format of the output data(raw|html).

label - string(default: attribute name|'')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Label of column.

trueValue - string(default: 'yes')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Text output for true value.

falseValue - string(default: 'no')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Text output for false value.

value - callable(default: null)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can be used to override default output generation.

.. code-block:: php
$builder->addColumn(self::BOOLEAN_COLUMN, [
...
'value' => function($entity) {
return $entity->isEnabled ? 'enabled' : 'disabled';
}
]);
55 changes: 55 additions & 0 deletions src/Resources/doc/columns/DataColumn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
DataColumn Class Reference
============================

Usage
-----

.. code-block:: php
$builder->addColumn(self::DATA_COLUMN, [
'attribute' => 'entity_attribute'
]);
Configuration
-------------

attribute - string(default: null)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entity attribute.

attributes - array(default: [])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
html attributes to be applied to the tag <td>.

filter - array(default: [])
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Filter configuration. See filters docs.

.. code-block:: php
$builder->addColumn(self::DATA_COLUMN, [
...
'filter' => [
'class' => self::FILTER_TEXT
]
]);
format - string(default: 'raw')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Format of the output data(raw|html).

label - string(default: attribute name|'')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Label of column.

value - callable(default: null)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can be used to override default output generation.

.. code-block:: php
$builder->addColumn(self::DATA_COLUMN, [
'value' => function($entity) {
return $entity->isEnabled ? 'enabled' : 'disabled';
}
]);
61 changes: 61 additions & 0 deletions src/Resources/doc/columns/DateColumn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
DateColumn Class Reference
============================

Usage
-----

.. code-block:: php
$builder->addColumn(self::DATE_COLUMN, [
'attribute' => 'entity_attribute'
]);
Configuration
-------------

attribute - string(default: null)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entity attribute.

attributes - array(default: [])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
html attributes to be applied to the tag <td>.

dateFormat - string(default: 'd.m.Y')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date format for output. See `PHP_Date`_

filter - array(default: [])
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Filter configuration. See filters docs.

.. code-block:: php
$builder->addColumn(self::DATE_COLUMN, [
...
'filter' => [
'class' => self::FILTER_TEXT
]
]);
format - string(default: 'raw')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Format of the output data(raw|html).

label - string(default: attribute name|'')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Label of column.

value - callable(default: null)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can be used to override default output generation.

.. code-block:: php
$builder->addColumn(self::DATE_COLUMN, [
'value' => function($entity) {
return $entity->getCreationDate()->format('d.m.Y');
}
]);
.. _`PHP_Date`: http://php.net/manual/ru/function.date.php
Loading

0 comments on commit 5757bc7

Please sign in to comment.