diff --git a/.travis.yml b/.travis.yml index ab0d4956..13d5fea2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.5 - 5.6 - 7.0 diff --git a/Grid/Column/Column.php b/Grid/Column/Column.php index 018c65da..d78e27a1 100755 --- a/Grid/Column/Column.php +++ b/Grid/Column/Column.php @@ -14,7 +14,7 @@ use APY\DataGridBundle\Grid\Filter; use Doctrine\Common\Version as DoctrineVersion; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; abstract class Column { @@ -80,7 +80,7 @@ abstract class Column protected $params; protected $isSorted = false; protected $orderUrl; - protected $securityContext; + protected $authorizationChecker; protected $data; protected $operatorsVisible; protected $operators; @@ -293,8 +293,8 @@ public function isVisible($isExported = false) { $visible = $isExported && $this->export !== null ? $this->export : $this->visible; - if ($visible && $this->securityContext !== null && $this->getRole() != null) { - return $this->securityContext->isGranted($this->getRole()); + if ($visible && $this->authorizationChecker !== null && $this->getRole() != null) { + return $this->authorizationChecker->isGranted($this->getRole()); } return $visible; @@ -804,13 +804,13 @@ public function hasDQLFunction(&$matches = null) /** * Internal function. * - * @param $securityContext + * @param $authorizationChecker * * @return $this */ - public function setSecurityContext(SecurityContextInterface $securityContext) + public function setAuthorizationChecker(AuthorizationCheckerInterface $authorizationChecker) { - $this->securityContext = $securityContext; + $this->authorizationChecker = $authorizationChecker; return $this; } diff --git a/Grid/Columns.php b/Grid/Columns.php index bbba628e..8447443c 100644 --- a/Grid/Columns.php +++ b/Grid/Columns.php @@ -14,7 +14,7 @@ use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Helper\ColumnsIterator; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; class Columns implements \IteratorAggregate, \Countable { @@ -22,13 +22,13 @@ class Columns implements \IteratorAggregate, \Countable protected $extensions = []; /** - * @var \Symfony\Component\Security\Core\SecurityContextInterface + * @var AuthorizationCheckerInterface */ - protected $securityContext; + protected $authorizationChecker; - public function __construct(SecurityContextInterface $securityContext) + public function __construct(AuthorizationCheckerInterface $authorizationChecker) { - $this->securityContext = $securityContext; + $this->authorizationChecker = $authorizationChecker; } public function getIterator($showOnlySourceColumns = false) @@ -46,7 +46,7 @@ public function getIterator($showOnlySourceColumns = false) */ public function addColumn(Column $column, $position = 0) { - $column->setSecurityContext($this->securityContext); + $column->setAuthorizationChecker($this->authorizationChecker); if ($position == 0) { $this->columns[] = $column; diff --git a/Grid/Export/Export.php b/Grid/Export/Export.php index 5b239dd0..e732da63 100644 --- a/Grid/Export/Export.php +++ b/Grid/Export/Export.php @@ -384,7 +384,7 @@ protected function getGridCell($column, $row) protected function hasBlock($name) { foreach ($this->getTemplates() as $template) { - if ($template->hasBlock($name)) { + if ($template->hasBlock($name, [])) { return true; } } @@ -403,7 +403,7 @@ protected function hasBlock($name) protected function renderBlock($name, $parameters) { foreach ($this->getTemplates() as $template) { - if ($template->hasBlock($name)) { + if ($template->hasBlock($name, [])) { return $template->renderBlock($name, array_merge($parameters, $this->params)); } } diff --git a/Grid/Grid.php b/Grid/Grid.php index 208e2a51..23530b4c 100644 --- a/Grid/Grid.php +++ b/Grid/Grid.php @@ -60,7 +60,7 @@ class Grid implements GridInterface protected $request; /** - * @var \Symfony\Component\Security\Core\SecurityContext + * @var \Symfony\Component\Security\Core\Authorization\AuthorizationChecker */ protected $securityContext; @@ -307,9 +307,9 @@ public function __construct($container, $id = '', GridConfigInterface $config = $this->config = $config; $this->router = $container->get('router'); - $this->request = $container->get('request'); + $this->request = $container->get('request_stack')->getCurrentRequest(); $this->session = $this->request->getSession(); - $this->securityContext = $container->get('security.context'); + $this->securityContext = $container->get('security.authorization_checker'); $this->id = $id; @@ -343,6 +343,11 @@ public function initialize() $this->setRouteParameter($parameter, $value); } } + + // Route + if (null != $config->getRoute()) { + $this->setRouteUrl($this->router->generate($config->getRoute(), $routeParameters)); + } // Route if (null != $config->getRoute()) { @@ -632,7 +637,7 @@ protected function processMassActions($actionId) $action->getParameters() ); - $subRequest = $this->container->get('request')->duplicate([], null, $path); + $subRequest = $this->request->duplicate([], null, $path); $this->massActionResponse = $this->container->get('http_kernel')->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST); } else { diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 1e797324..f6ae5a07 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -20,7 +20,7 @@ - + %apy_data_grid.limits% @@ -50,7 +50,7 @@ - + @@ -58,4 +58,5 @@ + diff --git a/Resources/doc/columns_configuration/index.md b/Resources/doc/columns_configuration/index.md new file mode 100644 index 00000000..c1b5b39e --- /dev/null +++ b/Resources/doc/columns_configuration/index.md @@ -0,0 +1,35 @@ +# Columns Configuration with Annotations + +## Annotations + +* [Source Annotation](annotations/source_annotation.md) +* [Column Annotation for a property](annotations/column_annotation_property.md) +* [Column Annotation for a class](annotations/column_annotation_class.md) +* [ORM Association Mapping](annotations/association_mapping.md) +* [DQL Functions](annotations/dql_function.md) + +## Column Types References + +* [Text Column](types/text_column.md) +* [Number Column](types/number_column.md) + * [Decimal](types/number_column.md) + * [Currency](types/number_column.md) + * [Percent](types/number_column.md) + * [Duration](types/number_column.md) + * [Scientific](types/number_column.md) + * [Spell Out](types/number_column.md) +* [Boolean Column](types/boolean_column.md) +* [DateTime Column](types/datetime_column.md) +* [Date Column](types/date_column.md) +* [_Time_](types/time_column.md) +* [Array Column](types/array_column.md) +* [Blank Column](types/blank_column.md) +* [Rank Column](types/rank_column.md) +* [Join Column](types/join_column.md) +* [Create your column](types/create_column.md) + +## Filters + +* [Input Filter](filters/input_filter.md) +* [Select Filter](filters/select_filter.md) +* [Create a filter](filters/create_filter.md) diff --git a/Resources/doc/configuration.md b/Resources/doc/configuration.md new file mode 100644 index 00000000..7c830b9b --- /dev/null +++ b/Resources/doc/configuration.md @@ -0,0 +1,19 @@ +# APYDataGrid Configuration Reference + +All available configuration options are listed below with their default values. + +```yaml +apy_data_grid: + limits: [20, 50, 100] + persistence: false + theme: 'APYDataGridBundle::blocks.html.twig' + no_data_message: "No data" + no_result_message: "No result" + actions_columns_size: -1 + actions_columns_title: "Actions" + actions_columns_separator: "
" + pagerfanta: + enable: false + view_class: "Pagerfanta\View\DefaultView" + options: ["prev_message" => "«", "next_message" => "»"] +``` \ No newline at end of file diff --git a/Resources/doc/export/index.md b/Resources/doc/export/index.md new file mode 100644 index 00000000..33409648 --- /dev/null +++ b/Resources/doc/export/index.md @@ -0,0 +1,35 @@ +# Export + +APYDataGrid bundle provides different ways for export your datas. This bundle proposes native exports such as a CSV or a JSON export and library-dependent exports such as Excel and PDF exports but everything is made that it is really easy to create your own export. + +> Note: An export don't export mass action and row actions columns. + +## Native Exports + +* [CSV Export](native_exports/CSV_export.md) +* [DSV Export](native_exports/DSV_export.md) +* [Excel Export](native_exports/Excel_export.md) +* [JSON Export](native_exports/JSON_export.md) +* [SCVS Export](native_exports/SCVS_export.md) +* [TSV Export](native_exports/TSV_export.md) +* [XML Export](native_exports/XML_export.md) + +## External Library Exports + +### With PHPExcel + +Add the following package to your composer.json file: + +```bash +$ composer require phpoffice/phpexcel "dev-master" +``` + +* [PHPExcel Excel 2007 Export](library-dependent_exports/PHPExcel/PHPExcel_excel2007_export.md) +* [PHPExcel Excel 2003 Export](library-dependent_exports/PHPExcel/PHPExcel_excel2003_export.md) +* [PHPExcel Excel 5 (97-2003) Export](library-dependent_exports/PHPExcel/PHPExcel_excel5_export.md) +* [PHPExcel Simple HTML Export](library-dependent_exports/PHPExcel/PHPExcel_HTML_export.md) +* [PHPExcel simple PDF export](library-dependent_exports/PHPExcel/PHPExcel_PDF_export.md) + +## Cook Book + +* [How to create your custom export](create_export.md) \ No newline at end of file diff --git a/Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_installation.md b/Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_installation.md deleted file mode 100644 index 41101b06..00000000 --- a/Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_installation.md +++ /dev/null @@ -1,16 +0,0 @@ -PHPExcel installation -===================== - -Add the foolowing package to your composer.json file: -```js -{ - "require": { - "phpoffice/phpexcel": "dev-master" - } -} -``` - -Execute this command: -```bash -$ php composer.phar update phpoffice/phpexcel -``` diff --git a/Resources/doc/features.md b/Resources/doc/features.md new file mode 100644 index 00000000..e2e8c114 --- /dev/null +++ b/Resources/doc/features.md @@ -0,0 +1,40 @@ +# APYDataGrid Bundle Features + +- Supports Entity (ORM), Document (ODM) and Vector (Array) sources +- Sortable and Filterable with operators (Comparison operators, range, starts/ends with, (not) contains, is (not) defined, regex) +- Auto-typing columns (Text, Number, Boolean, Array, DateTime, Date, ...) +- Locale support for DateTime, Date and Number columns (Decimal, Currency, Percent, Duration, Scientific, Spell out) +- Input, Select, checkbox and radio button filters filled with the data of the grid or an array of values +- Export (CSV, Excel, _PDF_, XML, JSON, HTML, ...) +- Mass actions +- Row actions +- Supports mapped fields with Entity source +- Securing the columns, actions and export with security roles +- Annotations and PHP configuration +- External filters box +- Ajax loading +- Pagination (You can also use Pagerfanta) +- Column width and column align +- Prefix translated titles +- Grid manager for multi-grid on the same page +- Groups configuration for ORM and ODM sources +- Easy templates overriding (twig) +- Custom columns and filters creation + +## Screenshot + +Full example with this [CSS style file](https://github.com/APY/APYDataGridBundle/blob/master/Resources/doc/grid_configuration/working_example.css): + +![test](https://github.com/APY/APYDataGridBundle/blob/master/Resources/doc/images/screenshot_full.png?raw=true) + +Simple example with the external filter box in english: + +![test](https://github.com/APY/APYDataGridBundle/blob/master/Resources/doc/images/screenshot_en.png?raw=true) + +Same example in french: + +![test](https://github.com/APY/APYDataGridBundle/blob/master/Resources/doc/images/screenshot_fr.png?raw=true) + +Data used in these screenshots (this is a phpMyAdmin screenshot): + +![test](https://github.com/APY/APYDataGridBundle/blob/master/Resources/doc/images/screenshot_database.png?raw=true) \ No newline at end of file diff --git a/Resources/doc/grid_configuration/index.md b/Resources/doc/grid_configuration/index.md new file mode 100644 index 00000000..fffcaf59 --- /dev/null +++ b/Resources/doc/grid_configuration/index.md @@ -0,0 +1,102 @@ +# Grid Configuration with PHP + +#### [Set the identifier of the grid](set_grid_identifier.md) +You can set the identifier of a grid to manage easily the grid with css and javascript for instance. + +#### [Set the persistence of the grid](set_grid_persistence.md) +By default, filters, page and order are reset when you quit the page where your grid is. If you set to true the persistence, its parameters are kept until you close your web browser or you kill the session cookie yourself. + +#### [Pagination](set_limits.md) +Define the selector of the number of items per page + +#### [Set max results](set_max_results.md) +Set max results. + +#### [Add column](add_column.md) +You can add a column to the grid. You can fill it with the row manipulator, in your template or tell the grid what field the column will be mapped. + +#### [Add row action](add_row_action.md) +A row action is an action performed on the current row. It's represented by a route to a controller with the identifier of the row. + +#### [Add multiple row actions columns](add_actions_column.md) +You can create other columns of row actions and choose the position of these ones. + +#### [Add mass action](add_mass_action.md) +A mass action is like a row action but over many lines at the same time. + +#### [Add a native delete mass action](add_delete_mass_action.md) +This mass action calls the delete method of the source. + +#### [Add export](add_export.md) + + +#### [Manipulate rows data](manipulate_rows_data.md) +You can set a callback to manipulate the row of the grid. + +#### [Manipulate column render cell](manipulate_column_render_cell.md) +You can set a callback to manipulate the render of a cell. + +#### [Manipulate the source query](manipulate_query.md) +The Entity Source provides two ways of manipulating the query which is used for generating the grid. + +#### [Manipulate the count query (source Entity only)](manipulate_count_query.md) +The grid requires the total number of results (COUNT (...)). The grid clones the source QueryBuilder and wraps it with a COUNT DISTINCT clause. + +#### [Manipulate columns](manipulate_column.md) +You can manipulate the behavior of a column. + +#### [Manipulate row action rendering](manipulate_row_action_rendering.md) +You can set a callback to manipulate the rendering of an action. + +#### [Hide or show columns](hide_show_columns.md) +These functions are helpers to manipulate columns. + +#### [Set columns order](set_columns_order.md) +You can already define the order of the columns with the columns option of the Source annotation. + +#### [Set a default page](set_default_page.md) +You can define a default page. This page will be used on each new session of the grid. + +#### [Set a default order](set_default_order.md) +You can define a default order. This order will be used on each new session of the grid. + +#### [Set a default items per page](set_default_limit.md) +You can define a default limit. This limit will be used on each new session of the grid. + +#### [Set default filters](set_default_filters.md) +You can define default filters. These values will be used on each new session of the grid. + +#### [Set permanent filters](set_permanent_filters.md) +You can define permanent filters. These values will be used every time and the filter part will be disable for columns which have a permanent filter. + +#### [Set the no data message](set_no_data_message.md) +When you render a grid with no data in the source, the grid isn't displayed and a no data message is displayed. + +#### [Set the no result message](set_no_result_message.md) +When you render a grid with no result after a filtering, a no result message is displayed in a unique row. + +#### [Always show the grid](always_show_grid.md) +When you render a grid with no data in the source, the grid isn't displayed and a no data message is displayed. + +#### [Set a title prefix](set_prefix_titles.md) +You can define a prefix title for all columns of the grid. + +#### [Set the size of the actions colum](set_size_actions_column.md) +Set the size of the actions column. + +#### [Set the title of the actions colum](set_title_actions_column.md) +Set the title of the actions column. + +#### [Set data to avoid calling the database](set_data.md) +You can use fetched data to avoid unnecessary queries. + +#### [Grid Response helper](grid_response.md) +The getGridResponse method is an helper which manage the redirection, export and the rendering of the grid. + +#### [Multi Grid manager](multi_grid_manager.md) +Handle multiple grids on the same page. + +#### [Set the route of the grid](set_grid_route.md) +The route of a grid is automatically retrieved from the request. But when you render a controller which contains a grid from twig, the route cannot be retrieved so you have to define it. + +#### [Working Example](working_example.md) diff --git a/Resources/doc/index.md b/Resources/doc/index.md new file mode 100644 index 00000000..72906add --- /dev/null +++ b/Resources/doc/index.md @@ -0,0 +1,132 @@ +# APY DataGrid Bundle + +APYDataGridBundle is a Symfony bundle for create grids for list your Entity (ORM), Document (ODM) and Vector (Array) sources. [APYDataGridBundle](https://github.com/APY/APYDataGridBundle) was initiated by **Stanislav Turza (Sorien)** and inspired by **Zfdatagrid and Magento Grid**. + +> IMPORTANT NOTICE : this is a fork repository of [APYDataGridBundle](https://github.com/APY/APYDataGridBundle). But the current version of [APYDataGridBundle](https://github.com/APY/APYDataGridBundle) is not compatible with Symfony 3+ framework. So, I fork this repository for make a APYDataGrid bundle compatible with Symfony3+. If you want to use it for Symfony2, please use the original repository [APYDataGridBundle](https://github.com/APY/APYDataGridBundle). + +> IMPORTANT NOTICE: This bundle is still under development. Any changes will be done without prior notice to consumers of this package. Of course this code will become stable at a certain point, but for now, use at your own risk. + +> You can see [CHANGELOG](CHANGELOG.md) and [UPGRADE 2.0](UPGRADE-2.0.md). + +## Prerequisites + +This version of the bundle requires Symfony 3.0+. + +### Translations + +If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config. + +```yaml +# app/config/config.yml +framework: + translator: ~ +``` + +For more information about translations, check [Symfony documentation](https://symfony.com/doc/current/book/translation.html). + +## Installation + +### Step 1 : Download APYDataGridBundle using composer + +Require the bundle with composer : + +```bash +$ composer require artscorestudio/datagrid-bundle +``` + +Composer will install the bundle to your project's *vendor/artscorestudio/datagrid-bundle* directory. + +### Step 2 : Enable the bundle + +Enable the bundle in the kernel : + +```php +// app/AppKernel.php + +public function registerBundles() +{ + $bundles = array( + // ... + new APY\DataGridBundle\APYDataGridBundle(), + // ... + ); +} +``` + +### Step 3 : Quick start with APYDataGridBundle + +#### Create simple grid with an ORM source in your controller + +```php +get('grid'); + + // Attach the source to the grid + $grid->setSource($source); + + // Return the response of the grid to the template + return $grid->getGridResponse('MyProjectMyBundle:myGrid.html.twig'); + } +} +``` + +#### Create simple configuration of the grid in the entity + +```php + +{{ grid(grid) }} +``` + +> Don't forget to clean your cache ! + +### Next Steps + +Now you have completed the basic installation and configuration of the APYDataGridBundle, you are ready to learn about more advanced features and usages of the bundle. + +The following documents are available : + +* [Getting Started With APYDataGridBundle](getting_started.md) +* [Setting the Grid Source](source/index.md) +* [Display the Grid (Twig template)](template/index.md) +* [Columns Configuration with Annotations](columns_configuration/index.md) +* [Grid Configuration with PHP](grid_configuration/index.md) +* [Export](export/index.md) +* [APYDataGridBundle Configuration Reference](configuration.md) diff --git a/Resources/doc/installation.md b/Resources/doc/installation.md deleted file mode 100644 index 869027c7..00000000 --- a/Resources/doc/installation.md +++ /dev/null @@ -1,25 +0,0 @@ -Installation -============ - -### Step 1: Download DataGridBundle using Composer - -```bash -$ composer require apy/datagrid-bundle -``` - -### Step 2: Enable the bundle - -Finally, enable the bundle in the kernel: - -``` php -get('grid'); - -$grid->setSource($source); - -return $grid->getGridResponse('MyProjectMyBundle::my_grid.html.twig'); -... +class DefaultController extends Controller +{ + public function myGridAction() + { + // [...] + $grid = $this->get('grid'); + + $grid->setSource($source); + + return $grid->getGridResponse('MyProjectMyBundle::my_grid.html.twig'); + } + // [...] +} ``` -And the template +And the Twig template -```janjo +```djanjo {{ grid(grid, theme, id, params) }} ``` -## grid function parameters +## Grid Function Parameters Reference |parameter|Type|Default value|Description| |:--:|:--|:--|:--|:--| @@ -34,16 +39,7 @@ And the template |id|string|_none_|Set the identifier of the grid.| |params|array|array()|Additional parameters passed to each block.| -## Example - -```janjo - - -{{ grid(grid) }} -... -``` - -## Override the getGridResponse function +## Overriding the getGridResponse function See [Grid Response helper](../grid_configuration/grid_response.md) for a detailed outline of ```getGridResponse```. @@ -66,3 +62,12 @@ if ($grid->isReadyForRedirect()) { ``` **Note:** GridResponse parameters are useless in this case and exports are managed directly in the getGridResponse function. + +## Learn more about advanced features and usages + +* [Display an ajax grid](render_an_ajax_grid.md) +* [Cell rendering](cell_rendering.md) +* [Filter rendering](filter_rendering.md) +* [Overriding internal blocks](overriding_internal_blocks.md) +* [Display an external filters box](render_external_filters.md) +* [Display a pagerfanta pager](render_pagerfanta_pager.md) \ No newline at end of file diff --git a/Tests/AddColumnTest.php b/Tests/AddColumnTest.php index 27d0adb3..72132b4f 100644 --- a/Tests/AddColumnTest.php +++ b/Tests/AddColumnTest.php @@ -2,16 +2,18 @@ namespace APY\DataGridBundle\Tests; +use APY\DataGridBundle\Grid\Column\Column; use APY\DataGridBundle\Grid\Columns; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; class AddColumnTest extends \PHPUnit_Framework_TestCase { public function setUp() { - $this->col1 = $this->getMock('APY\DataGridBundle\Grid\Column\Column'); - $this->col2 = $this->getMock('APY\DataGridBundle\Grid\Column\Column'); - $this->col3 = $this->getMock('APY\DataGridBundle\Grid\Column\Column'); - $this->newCol = $this->getMock('APY\DataGridBundle\Grid\Column\Column'); + $this->col1 = $this->getMock(Column::class); + $this->col2 = $this->getMock(Column::class); + $this->col3 = $this->getMock(Column::class); + $this->newCol = $this->getMock(Column::class); } public function testAddColumnPositiveOffset() @@ -65,8 +67,9 @@ public function testAddColumnNegativeOffset() protected function getBaseColumns() { - $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); - $columns = new Columns($context); + $authChecker = $this->getMock(AuthorizationCheckerInterface::class); + + $columns = new Columns($authChecker); $columns->addColumn($this->col1); $columns->addColumn($this->col2); $columns->addColumn($this->col3); diff --git a/Tests/Grid/GridBuilderTest.php b/Tests/Grid/GridBuilderTest.php index 7856a4fa..dc9bf856 100755 --- a/Tests/Grid/GridBuilderTest.php +++ b/Tests/Grid/GridBuilderTest.php @@ -2,8 +2,17 @@ namespace APY\DataGridBundle\Grid\Tests; +use APY\DataGridBundle\Grid\Column\Column; +use APY\DataGridBundle\Grid\Exception\InvalidArgumentException; +use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; +use APY\DataGridBundle\Grid\Grid; use APY\DataGridBundle\Grid\GridBuilder; +use APY\DataGridBundle\Grid\GridFactoryInterface; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; /** * Class GridBuilderTest. @@ -27,7 +36,7 @@ class GridBuilderTest extends \PHPUnit_Framework_TestCase public function testAddUnexpectedType() { - $this->setExpectedException('APY\DataGridBundle\Grid\Exception\UnexpectedTypeException'); + $this->setExpectedException(UnexpectedTypeException::class); $this->builder->add('foo', 123); $this->builder->add('foo', ['test']); @@ -40,7 +49,7 @@ public function testAddColumnTypeString() $this->factory->expects($this->once()) ->method('createColumn') ->with('foo', 'text', []) - ->willReturn($this->getMock('APY\DataGridBundle\Grid\Column\Column')); + ->willReturn($this->getMock(Column::class)); $this->builder->add('foo', 'text'); @@ -52,7 +61,7 @@ public function testAddColumnType() $this->factory->expects($this->never())->method('createColumn'); $this->assertFalse($this->builder->has('foo')); - $this->builder->add('foo', $this->getMock('APY\DataGridBundle\Grid\Column\Column')); + $this->builder->add('foo', $this->getMock(Column::class)); $this->assertTrue($this->builder->has('foo')); } @@ -65,7 +74,7 @@ public function testAddIsFluent() public function testGetUnknown() { $this->setExpectedException( - 'APY\DataGridBundle\Grid\Exception\InvalidArgumentException', + InvalidArgumentException::class, 'The column with the name "foo" does not exist.' ); @@ -74,7 +83,7 @@ public function testGetUnknown() public function testGetExplicitColumnType() { - $expectedColumn = $this->getMock('APY\DataGridBundle\Grid\Column\Column'); + $expectedColumn = $this->getMock(Column::class); $this->factory->expects($this->once()) ->method('createColumn') @@ -93,7 +102,7 @@ public function testHasColumnType() $this->factory->expects($this->once()) ->method('createColumn') ->with('foo', 'text', []) - ->willReturn($this->getMock('APY\DataGridBundle\Grid\Column\Column')); + ->willReturn($this->getMock(Column::class)); $this->builder->add('foo', 'text'); @@ -110,7 +119,7 @@ public function testRemove() $this->factory->expects($this->once()) ->method('createColumn') ->with('foo', 'text', []) - ->willReturn($this->getMock('APY\DataGridBundle\Grid\Column\Column')); + ->willReturn($this->getMock(Column::class)); $this->builder->add('foo', 'text'); @@ -127,7 +136,7 @@ public function testRemoveIsFluent() public function testGetGrid() { - $this->assertInstanceOf('APY\DataGridBundle\Grid\Grid', $this->builder->getGrid()); + $this->assertInstanceOf(Grid::class, $this->builder->getGrid()); } /** @@ -137,26 +146,28 @@ protected function setUp() { $self = $this; - $this->container = $this->getMock('Symfony\Component\DependencyInjection\Container'); + $this->container = $this->getMock(Container::class); $this->container->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($param) use ($self) { - switch ($param) { - case 'router': - return $self->getMock('Symfony\Component\Routing\RouterInterface'); - break; - case 'request': - $request = new Request([], [], ['key' => 'value']); - - return $request; - break; - case 'security.context': - return $self->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); - break; - } - })); - - $this->factory = $this->getMock('APY\DataGridBundle\Grid\GridFactoryInterface'); + ->method('get') + ->will($this->returnCallback(function ($param) use ($self) { + switch ($param) { + case 'router': + return $self->getMock(RouterInterface::class); + break; + case 'request_stack': + $request = new Request([], [], ['key' => 'value']); + $requestStack = new RequestStack(); + $requestStack->push($request); + + return $requestStack; + break; + case 'security.authorization_checker': + return $self->getMock(AuthorizationCheckerInterface::class); + break; + } + })); + + $this->factory = $this->getMock(GridFactoryInterface::class); $this->builder = new GridBuilder($this->container, $this->factory, 'name'); } diff --git a/Tests/Grid/GridFactoryTest.php b/Tests/Grid/GridFactoryTest.php index 0638c27a..d7bc8be3 100755 --- a/Tests/Grid/GridFactoryTest.php +++ b/Tests/Grid/GridFactoryTest.php @@ -3,11 +3,20 @@ namespace APY\DataGridBundle\Tests\Grid; use APY\DataGridBundle\Grid\Column\TextColumn; +use APY\DataGridBundle\Grid\Exception\UnexpectedTypeException; +use APY\DataGridBundle\Grid\Grid; use APY\DataGridBundle\Grid\GridBuilder; +use APY\DataGridBundle\Grid\GridBuilderInterface; use APY\DataGridBundle\Grid\GridFactory; +use APY\DataGridBundle\Grid\GridRegistryInterface; +use APY\DataGridBundle\Grid\GridTypeInterface; use APY\DataGridBundle\Grid\Type\GridType; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; /** * Class GridFactoryTest. @@ -36,7 +45,7 @@ class GridFactoryTest extends \PHPUnit_Framework_TestCase public function testCreateWithUnexpectedType() { - $this->setExpectedException('APY\DataGridBundle\Grid\Exception\UnexpectedTypeException'); + $this->setExpectedException(UnexpectedTypeException::class); $this->factory->create(1234); $this->factory->create(['foo']); $this->factory->create(new \stdClass()); @@ -47,16 +56,16 @@ public function testCreateWithTypeString() $this->registry->expects($this->once()) ->method('getType') ->with('foo') - ->willReturn($this->getMock('APY\DataGridBundle\Grid\GridTypeInterface')); + ->willReturn($this->getMock(GridTypeInterface::class)); - $this->assertInstanceOf('APY\DataGridBundle\Grid\Grid', $this->factory->create('foo')); + $this->assertInstanceOf(Grid::class, $this->factory->create('foo')); } public function testCreateWithTypeObject() { $this->registry->expects($this->never())->method('getType'); - $this->assertInstanceOf('APY\DataGridBundle\Grid\Grid', $this->factory->create(new GridType())); + $this->assertInstanceOf(Grid::class, $this->factory->create(new GridType())); } public function testCreateBuilderWithDefaultType() @@ -78,7 +87,7 @@ public function testCreateBuilder() $givenOptions = ['a' => 1, 'b' => 2]; $resolvedOptions = ['a' => 1, 'b' => 2, 'c' => 3]; - $type = $this->getMock('APY\DataGridBundle\Grid\GridTypeInterface'); + $type = $this->getMock(GridTypeInterface::class); $type->expects($this->once()) ->method('getName') @@ -104,7 +113,7 @@ public function testCreateBuilder() $builder = $this->factory->createBuilder($type, null, $givenOptions); - $this->assertInstanceOf('APY\DataGridBundle\Grid\GridBuilderInterface', $builder); + $this->assertInstanceOf(GridBuilderInterface::class, $builder); $this->assertSame($type, $builder->getType()); $this->assertSame('TYPE', $builder->getName()); $this->assertEquals($resolvedOptions, $builder->getOptions()); @@ -113,7 +122,7 @@ public function testCreateBuilder() public function testCreateColumnWithUnexpectedType() { - $this->setExpectedException('APY\DataGridBundle\Grid\Exception\UnexpectedTypeException'); + $this->setExpectedException(UnexpectedTypeException::class); $this->factory->createColumn('foo', 1234); } @@ -128,7 +137,7 @@ public function testCreateColumnWithTypeString() $column = $this->factory->createColumn('foo', 'text', ['title' => 'bar']); - $this->assertInstanceOf('APY\DataGridBundle\Grid\Column\TextColumn', $column); + $this->assertInstanceOf(TextColumn::class, $column); $this->assertEquals('text', $column->getType()); $this->assertEquals('foo', $column->getId()); $this->assertEquals('bar', $column->getTitle()); @@ -140,7 +149,7 @@ public function testCreateColumnWithObject() { $column = $this->factory->createColumn('foo', new TextColumn(), ['title' => 'bar']); - $this->assertInstanceOf('APY\DataGridBundle\Grid\Column\TextColumn', $column); + $this->assertInstanceOf(TextColumn::class, $column); $this->assertEquals('text', $column->getType()); $this->assertEquals('foo', $column->getId()); $this->assertEmpty($column->getTitle()); @@ -151,27 +160,30 @@ public function testCreateColumnWithObject() protected function setUp() { $self = $this; - $this->container = $this->getMock('Symfony\Component\DependencyInjection\Container'); + + $this->container = $this->getMock(Container::class); $this->container->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($param) use ($self) { - switch ($param) { - case 'router': - return $self->getMock('Symfony\Component\Routing\RouterInterface'); - break; - case 'request': - $request = new Request([], [], ['key' => 'value']); - - return $request; - break; - case 'security.context': - return $self->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); - break; - } - })); - - $this->registry = $this->getMock('APY\DataGridBundle\Grid\GridRegistryInterface'); - $this->builder = $this->getMock('APY\DataGridBundle\Grid\GridBuilderInterface'); + ->method('get') + ->will($this->returnCallback(function ($param) use ($self) { + switch ($param) { + case 'router': + return $self->getMock(RouterInterface::class); + break; + case 'request_stack': + $request = new Request([], [], ['key' => 'value']); + $requestStack = new RequestStack(); + $requestStack->push($request); + + return $requestStack; + break; + case 'security.authorization_checker': + return $self->getMock(AuthorizationCheckerInterface::class); + break; + } + })); + + $this->registry = $this->getMock(GridRegistryInterface::class); + $this->builder = $this->getMock(GridBuilderInterface::class); $this->factory = new GridFactory($this->container, $this->registry); } } diff --git a/Tests/Grid/GridRegistryTest.php b/Tests/Grid/GridRegistryTest.php index 6e41b822..de3b426d 100755 --- a/Tests/Grid/GridRegistryTest.php +++ b/Tests/Grid/GridRegistryTest.php @@ -2,7 +2,13 @@ namespace APY\DataGridBundle\Tests\Grid; +use APY\DataGridBundle\Grid\Column\Column; +use APY\DataGridBundle\Grid\Exception\ColumnAlreadyExistsException; +use APY\DataGridBundle\Grid\Exception\ColumnNotFoundException; +use APY\DataGridBundle\Grid\Exception\TypeAlreadyExistsException; +use APY\DataGridBundle\Grid\Exception\TypeNotFoundException; use APY\DataGridBundle\Grid\GridRegistry; +use APY\DataGridBundle\Grid\GridTypeInterface; /** * Class GridRegistryTest. @@ -16,7 +22,7 @@ class GridRegistryTest extends \PHPUnit_Framework_TestCase public function testAddTypeAlreadyExists() { - $this->setExpectedException('APY\DataGridBundle\Grid\Exception\TypeAlreadyExistsException'); + $this->setExpectedException(TypeAlreadyExistsException::class); $type = $this->createTypeMock(); @@ -39,7 +45,7 @@ public function testAddIsFluent() public function testGetTypeUnknown() { - $this->setExpectedException('APY\DataGridBundle\Grid\Exception\TypeNotFoundException'); + $this->setExpectedException(TypeNotFoundException::class); $this->registry->getType('foo'); } @@ -53,7 +59,7 @@ public function testGetType() public function testAddColumnAlreadyExists() { - $this->setExpectedException('APY\DataGridBundle\Grid\Exception\ColumnAlreadyExistsException'); + $this->setExpectedException(ColumnAlreadyExistsException::class); $type = $this->createColumnTypeMock(); @@ -76,7 +82,7 @@ public function testAddColumnTypeIsFluent() public function testGetColumnTypeUnknown() { - $this->setExpectedException('APY\DataGridBundle\Grid\Exception\ColumnNotFoundException'); + $this->setExpectedException(ColumnNotFoundException::class); $this->registry->getColumn('type'); } @@ -95,7 +101,7 @@ protected function setUp() protected function createTypeMock() { - $mock = $this->getMock('APY\DataGridBundle\Grid\GridTypeInterface'); + $mock = $this->getMock(GridTypeInterface::class); $mock->expects($this->any()) ->method('getName') ->willReturn('foo'); @@ -105,7 +111,7 @@ protected function createTypeMock() protected function createColumnTypeMock() { - $mock = $this->getMock('APY\DataGridBundle\Grid\Column\Column'); + $mock = $this->getMock(Column::class); $mock->expects($this->any()) ->method('getType') ->willReturn('type'); diff --git a/Tests/Twig/DataGridExtensionTest.php b/Tests/Twig/DataGridExtensionTest.php index f405534d..c5e87df5 100644 --- a/Tests/Twig/DataGridExtensionTest.php +++ b/Tests/Twig/DataGridExtensionTest.php @@ -2,7 +2,10 @@ namespace APY\DataGridBundle\Tests\Twig; +use APY\DataGridBundle\Grid\Column\Column; +use APY\DataGridBundle\Grid\Grid; use APY\DataGridBundle\Twig\DataGridExtension; +use Symfony\Component\Routing\RouterInterface; /** * Class DataGridExtensionTest. @@ -19,7 +22,7 @@ class DataGridExtensionTest extends \PHPUnit_Framework_TestCase public function setUp() { - $router = $this->getMock('Symfony\Component\Routing\RouterInterface'); + $router = $this->getMock(RouterInterface::class); $this->extension = new DataGridExtension($router, ''); } @@ -29,14 +32,14 @@ public function testGetGridUrl() $gridHash = 'my_grid'; // Creates grid - $grid = $this->getMock('APY\DataGridBundle\Grid\Grid', [], [], '', false); + $grid = $this->getMock(Grid::class, [], [], '', false); $grid->expects($this->any())->method('getRouteUrl')->willReturn($baseUrl); $grid->expects($this->any())->method('getHash')->willReturn($gridHash); $prefix = $baseUrl . '?' . $gridHash; // Creates column - $column = $this->getMock('APY\DataGridBundle\Grid\Column\Column'); + $column = $this->getMock(Column::class); // Limit $this->assertEquals($prefix . '[_limit]=', $this->extension->getGridUrl('limit', $grid, $column)); diff --git a/Twig/DataGridExtension.php b/Twig/DataGridExtension.php index a7b24d2d..f6186287 100644 --- a/Twig/DataGridExtension.php +++ b/Twig/DataGridExtension.php @@ -16,13 +16,26 @@ use Pagerfanta\Adapter\NullAdapter; use Pagerfanta\Pagerfanta; use Symfony\Component\Routing\RouterInterface; - -class DataGridExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface +use Twig_Environment; +use Twig_Extension; +use Twig_Extension_GlobalsInterface; +use Twig_SimpleFunction; +use Twig_Template; + +/** + * DataGrid Twig Extension. + * + * (c) Abhoryo + * (c) Stanislav Turza + * + * Updated by Nicolas Claverie + */ +class DataGridExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface { const DEFAULT_TEMPLATE = 'APYDataGridBundle::blocks.html.twig'; /** - * @var \Twig_TemplateInterface[] + * @var Twig_Template[] */ protected $templates = []; @@ -66,6 +79,9 @@ public function __construct($router, $defaultTemplate) $this->defaultTemplate = $defaultTemplate; } + /** + * @param array $def + */ public function setPagerFanta(array $def) { $this->pagerFantaDefs = $def; @@ -96,19 +112,53 @@ public function getGlobals() public function getFunctions() { return [ - new \Twig_SimpleFunction('grid', [$this, 'getGrid'], ['is_safe' => ['html'], 'needs_environment' => true]), - new \Twig_SimpleFunction('grid_html', [$this, 'getGridHtml'], ['is_safe' => ['html'], 'needs_environment' => true]), - new \Twig_SimpleFunction('grid_url', [$this, 'getGridUrl'], ['is_safe' => ['html']]), - new \Twig_SimpleFunction('grid_filter', [$this, 'getGridFilter'], ['is_safe' => ['html'], 'needs_environment' => true]), - new \Twig_SimpleFunction('grid_column_operator', [$this, 'getGridColumnOperator'], ['is_safe' => ['html'], 'needs_environment' => true]), - new \Twig_SimpleFunction('grid_cell', [$this, 'getGridCell'], ['is_safe' => ['html'], 'needs_environment' => true]), - new \Twig_SimpleFunction('grid_search', [$this, 'getGridSearch'], ['is_safe' => ['html'], 'needs_environment' => true]), - new \Twig_SimpleFunction('grid_pager', [$this, 'getGridPager'], ['is_safe' => ['html'], 'needs_environment' => true]), - new \Twig_SimpleFunction('grid_pagerfanta', [$this, 'getPagerfanta'], ['is_safe' => ['html']]), - new \Twig_SimpleFunction('grid_*', [$this, 'getGrid_'], ['is_safe' => ['html'], 'needs_environment' => true]), + new Twig_SimpleFunction('grid', [$this, 'getGrid'], [ + 'needs_environment' => true, + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_html', [$this, 'getGridHtml'], [ + 'needs_environment' => true, + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_url', [$this, 'getGridUrl'], [ + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_filter', [$this, 'getGridFilter'], [ + 'needs_environment' => true, + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_column_operator', [$this, 'getGridColumnOperator'], [ + 'needs_environment' => true, + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_cell', [$this, 'getGridCell'], [ + 'needs_environment' => true, + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_search', [$this, 'getGridSearch'], [ + 'needs_environment' => true, + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_pager', [$this, 'getGridPager'], [ + 'needs_environment' => true, + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_pagerfanta', [$this, 'getPagerfanta'], [ + 'is_safe' => ['html'], + ]), + new Twig_SimpleFunction('grid_*', [$this, 'getGrid_'], [ + 'needs_environment' => true, + 'is_safe' => ['html'], + ]), ]; } + /** + * @param unknown $grid + * @param unknown $theme + * @param string $id + * @param array $params + */ public function initGrid($grid, $theme = null, $id = '', array $params = []) { $this->theme = $theme; @@ -121,14 +171,14 @@ public function initGrid($grid, $theme = null, $id = '', array $params = []) /** * Render grid block. * - * @param \Twig_Environment $environment + * @param Twig_Environment $environment * @param \APY\DataGridBundle\Grid\Grid $grid * @param string $theme * @param string $id * * @return string */ - public function getGrid(\Twig_Environment $environment, $grid, $theme = null, $id = '', array $params = [], $withjs = true) + public function getGrid(Twig_Environment $environment, $grid, $theme = null, $id = '', array $params = [], $withjs = true) { $this->initGrid($grid, $theme, $id, $params); @@ -141,24 +191,37 @@ public function getGrid(\Twig_Environment $environment, $grid, $theme = null, $i /** * Render grid block (html only). * - * @param \Twig_Environment $environment + * @param Twig_Environment $environment * @param \APY\DataGridBundle\Grid\Grid $grid * @param string $theme * @param string $id * * @return string */ - public function getGridHtml(\Twig_Environment $environment, $grid, $theme = null, $id = '', array $params = []) + public function getGridHtml(Twig_Environment $environment, $grid, $theme = null, $id = '', array $params = []) { return $this->getGrid($environment, $grid, $theme, $id, $params, false); } - public function getGrid_(\Twig_Environment $environment, $name, $grid) + /** + * @param Twig_Environment $environment + * @param string $name + * @param unknown $grid + * + * @return string + */ + public function getGrid_(Twig_Environment $environment, $name, $grid) { return $this->renderBlock($environment, 'grid_' . $name, ['grid' => $grid]); } - public function getGridPager(\Twig_Environment $environment, $grid) + /** + * @param Twig_Environment $environment + * @param unknown $grid + * + * @return string + */ + public function getGridPager(Twig_Environment $environment, $grid) { return $this->renderBlock($environment, 'grid_pager', ['grid' => $grid, 'pagerfanta' => $this->pagerFantaDefs['enable']]); } @@ -166,31 +229,31 @@ public function getGridPager(\Twig_Environment $environment, $grid) /** * Cell Drawing override. * - * @param \Twig_Environment $environment + * @param Twig_Environment $environment * @param \APY\DataGridBundle\Grid\Column\Column $column * @param \APY\DataGridBundle\Grid\Row $row * @param \APY\DataGridBundle\Grid\Grid $grid * * @return string */ - public function getGridCell(\Twig_Environment $environment, $column, $row, $grid) + public function getGridCell(Twig_Environment $environment, $column, $row, $grid) { $value = $column->renderCell($row->getField($column->getId()), $row, $this->router); $id = $this->names[$grid->getHash()]; if (($id != '' && ($this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_cell'))) - || $this->hasBlock($environment, $block = 'grid_column_' . $column->getRenderBlockId() . '_cell') - || $this->hasBlock($environment, $block = 'grid_column_' . $column->getType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_column_' . $column->getParentType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_column_id_' . $column->getRenderBlockId() . '_cell') - || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getType() . '_cell') - || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getParentType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_cell'))) + || $this->hasBlock($environment, $block = 'grid_column_' . $column->getRenderBlockId() . '_cell') + || $this->hasBlock($environment, $block = 'grid_column_' . $column->getType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_column_' . $column->getParentType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_column_id_' . $column->getRenderBlockId() . '_cell') + || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getType() . '_cell') + || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getParentType() . '_cell') ) { return $this->renderBlock($environment, $block, ['grid' => $grid, 'column' => $column, 'row' => $row, 'value' => $value]); } @@ -201,27 +264,27 @@ public function getGridCell(\Twig_Environment $environment, $column, $row, $grid /** * Filter Drawing override. * - * @param \Twig_Environment $environment + * @param Twig_Environment $environment * @param \APY\DataGridBundle\Grid\Column\Column $column * @param \APY\DataGridBundle\Grid\Grid $grid * * @return string */ - public function getGridFilter(\Twig_Environment $environment, $column, $grid, $submitOnChange = true) + public function getGridFilter(Twig_Environment $environment, $column, $grid, $submitOnChange = true) { $id = $this->names[$grid->getHash()]; if (($id != '' && ($this->hasBlock($environment, $block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_filter') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_filter') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getType() . '_filter') - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_filter')) - || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_filter_type_' . $column->getFilterType())) - || $this->hasBlock($environment, $block = 'grid_column_' . $column->getRenderBlockId() . '_filter') - || $this->hasBlock($environment, $block = 'grid_column_id_' . $column->getRenderBlockId() . '_filter') - || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getType() . '_filter') - || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getParentType() . '_filter') - || $this->hasBlock($environment, $block = 'grid_column_filter_type_' . $column->getFilterType()) - ) { + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_filter') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getType() . '_filter') + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_filter')) + || $this->hasBlock($environment, $block = 'grid_' . $id . '_column_filter_type_' . $column->getFilterType())) + || $this->hasBlock($environment, $block = 'grid_column_' . $column->getRenderBlockId() . '_filter') + || $this->hasBlock($environment, $block = 'grid_column_id_' . $column->getRenderBlockId() . '_filter') + || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getType() . '_filter') + || $this->hasBlock($environment, $block = 'grid_column_type_' . $column->getParentType() . '_filter') + || $this->hasBlock($environment, $block = 'grid_column_filter_type_' . $column->getFilterType()) + ) { return $this->renderBlock($environment, $block, ['grid' => $grid, 'column' => $column, 'submitOnChange' => $submitOnChange && $column->isFilterSubmitOnChange()]); } @@ -231,13 +294,13 @@ public function getGridFilter(\Twig_Environment $environment, $column, $grid, $s /** * Column Operator Drawing override. * - * @param \Twig_Environment $environment + * @param Twig_Environment $environment * @param \APY\DataGridBundle\Grid\Column\Column $column * @param \APY\DataGridBundle\Grid\Grid $grid * * @return string */ - public function getGridColumnOperator(\Twig_Environment $environment, $column, $grid, $operator, $submitOnChange = true) + public function getGridColumnOperator(Twig_Environment $environment, $column, $grid, $operator, $submitOnChange = true) { return $this->renderBlock($environment, 'grid_column_operator', ['grid' => $grid, 'column' => $column, 'submitOnChange' => $submitOnChange, 'op' => $operator]); } @@ -271,6 +334,15 @@ public function getGridUrl($section, $grid, $param = null) } } + /** + * @param Twig_Environment $environment + * @param unknown $grid + * @param unknown $theme + * @param string $id + * @param array $params + * + * @return string + */ public function getGridSearch(\Twig_Environment $environment, $grid, $theme = null, $id = '', array $params = []) { $this->initGrid($grid, $theme, $id, $params); @@ -278,6 +350,9 @@ public function getGridSearch(\Twig_Environment $environment, $grid, $theme = nu return $this->renderBlock($environment, 'grid_search', ['grid' => $grid]); } + /** + * @param unknown $grid + */ public function getPagerfanta($grid) { $adapter = new NullAdapter($grid->getTotalCount()); @@ -300,18 +375,18 @@ public function getPagerfanta($grid) /** * Render block. * - * @param \Twig_Environment $environment - * @param string $name - * @param array $parameters + * @param Twig_Environment $environment + * @param string $name + * @param array $parameters * * @throws \InvalidArgumentException If the block could not be found * * @return string */ - protected function renderBlock(\Twig_Environment $environment, $name, $parameters) + protected function renderBlock(Twig_Environment $environment, $name, $parameters) { foreach ($this->getTemplates($environment) as $template) { - if ($template->hasBlock($name)) { + if ($template->hasBlock($name, [])) { return $template->renderBlock($name, array_merge($environment->getGlobals(), $parameters, $this->params)); } } @@ -322,15 +397,16 @@ protected function renderBlock(\Twig_Environment $environment, $name, $parameter /** * Has block. * - * @param \Twig_Environment $environment - * @param string $name + * @param Twig_Environment $environment + * @param $name string * * @return bool */ - protected function hasBlock(\Twig_Environment $environment, $name) + protected function hasBlock(Twig_Environment $environment, $name) { foreach ($this->getTemplates($environment) as $template) { - if ($template->hasBlock($name)) { + /** @var $template Twig_Template */ + if ($template->hasBlock($name, [])) { return true; } } @@ -341,16 +417,16 @@ protected function hasBlock(\Twig_Environment $environment, $name) /** * Template Loader. * - * @param \Twig_Environment $environment + * @param Twig_Environment $environment * * @throws \Exception * - * @return \Twig_Template[] + * @return Twig_Template[] */ - protected function getTemplates(\Twig_Environment $environment) + protected function getTemplates(Twig_Environment $environment) { if (empty($this->templates)) { - if ($this->theme instanceof \Twig_Template) { + if ($this->theme instanceof Twig_Template) { $this->templates[] = $this->theme; $this->templates[] = $environment->loadTemplate($this->defaultTemplate); } elseif (is_string($this->theme)) { @@ -365,7 +441,13 @@ protected function getTemplates(\Twig_Environment $environment) return $this->templates; } - protected function getTemplatesFromString(\Twig_Environment $environment, $theme) + /** + * @param Twig_Environment $environment + * @param unknown $theme + * + * @return array|Twig_Template[] + */ + protected function getTemplatesFromString(Twig_Environment $environment, $theme) { $this->templates = []; @@ -377,9 +459,4 @@ protected function getTemplatesFromString(\Twig_Environment $environment, $theme return $this->templates; } - - public function getName() - { - return 'datagrid_twig_extension'; - } } diff --git a/composer.json b/composer.json index be9f8bcc..4ebf898b 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "apy/datagrid-bundle", - "description": "Symfony2 Datagrid Bundle", + "description": "Symfony Datagrid Bundle", "keywords": ["Symfony", "datagrid"], - "homepage": "https://github.com/Abhoryo/APYDataGridBundle", + "homepage": "https://github.com/apy/APYDataGridBundle", "type": "symfony-bundle", "license": "MIT", "authors": [ @@ -20,9 +20,9 @@ } ], "require": { - "php": ">=5.4", - "symfony/symfony": "~2.3", - "twig/twig": ">=1.23.0" + "php": ">=5.6", + "symfony/symfony": "~2.8|~3.0", + "twig/twig": ">=1.5.0" }, "require-dev": { "phpunit/phpunit": "~4.1.1", @@ -38,7 +38,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "3.0-dev" } } }