Skip to content

Commit

Permalink
Merge pull request #877 from APY/symfony3
Browse files Browse the repository at this point in the history
Symfony 2.8|^3.0 Support
  • Loading branch information
Hüseyin Mert committed Mar 16, 2017
2 parents 2f4e029 + 2017028 commit a6bd37d
Show file tree
Hide file tree
Showing 23 changed files with 678 additions and 227 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0

Expand Down
14 changes: 7 additions & 7 deletions Grid/Column/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -80,7 +80,7 @@ abstract class Column
protected $params;
protected $isSorted = false;
protected $orderUrl;
protected $securityContext;
protected $authorizationChecker;
protected $data;
protected $operatorsVisible;
protected $operators;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions Grid/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@

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
{
protected $columns = [];
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)
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Grid/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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));
}
}
Expand Down
13 changes: 9 additions & 4 deletions Grid/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</call>
</service>

<service id="grid" class="%grid.class%" scope="prototype">
<service id="grid" class="%grid.class%" shared="false">
<argument type="service" id="service_container" />
<call method="setLimits">
<argument>%apy_data_grid.limits%</argument>
Expand Down Expand Up @@ -50,12 +50,13 @@
<argument type="service" id="annotation_reader" />
</service>

<service id="grid.mapping.manager" class="APY\DataGridBundle\Grid\Mapping\Metadata\Manager" scope="prototype">
<service id="grid.mapping.manager" class="APY\DataGridBundle\Grid\Mapping\Metadata\Manager" shared="false">
<argument type="service" id="form.factory"/>
<call method="addDriver">
<argument type="service" id="grid.metadata.driver.annotation" />
<argument>1</argument>
</call>
</service>
</services>

</container>
35 changes: 35 additions & 0 deletions Resources/doc/columns_configuration/index.md
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions Resources/doc/configuration.md
Original file line number Diff line number Diff line change
@@ -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: "<br />"
pagerfanta:
enable: false
view_class: "Pagerfanta\View\DefaultView"
options: ["prev_message" => "«", "next_message" => "»"]
```
35 changes: 35 additions & 0 deletions Resources/doc/export/index.md
Original file line number Diff line number Diff line change
@@ -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)

This file was deleted.

40 changes: 40 additions & 0 deletions Resources/doc/features.md
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit a6bd37d

Please sign in to comment.