Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony3 compatibility #19

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
Expand Down
6 changes: 4 additions & 2 deletions Grid/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ public function __construct($container)

/**
* @param string $gridClassName The name of the Grid descendant class that will be instantiated
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \PedroTeixeira\Bundle\GridBundle\Grid\GridAbstract
*
*/
public function createGrid($gridClassName)
public function createGrid($gridClassName, \Symfony\Component\HttpFoundation\Request $request)
{
$gridClass = new \ReflectionClass($gridClassName);

/* @var \PedroTeixeira\Bundle\GridBundle\Grid\GridAbstract $grid */
$grid = $gridClass->newInstance($this->container);
$grid = $gridClass->newInstance($this->container, $request);
$grid->setupGrid();

return $grid;
Expand Down
3 changes: 2 additions & 1 deletion Grid/Filter/Operator/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PedroTeixeira\Bundle\GridBundle\Grid\Filter\Operator;

use Symfony\Component\Locale\Stub\DateFormat\FullTransformer;
use Symfony\Component\Intl\DateFormatter\DateFormat\FullTransformer;

/**
* Date
Expand All @@ -18,6 +18,7 @@ public function execute($value)
$this->container->getParameter('pedro_teixeira_grid.date.date_format'),
$this->container->getParameter('locale')
);

$date = new \DateTime();
$transformer->parse($date, $value);

Expand Down
2 changes: 1 addition & 1 deletion Grid/Filter/Operator/DateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PedroTeixeira\Bundle\GridBundle\Grid\Filter\Operator;

use Symfony\Component\Locale\Stub\DateFormat\FullTransformer;
use Symfony\Component\Intl\DateFormatter\DateFormat\FullTransformer;

/**
* DateRange
Expand Down
23 changes: 13 additions & 10 deletions Grid/GridAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
use Doctrine\ORM\Tools\Pagination\Paginator;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;

/**
* Grid Abstract
*/
abstract class GridAbstract
{
/**
* @var \Symfony\Component\DependencyInjection\Container
* @var Container
*/
protected $container;

Expand All @@ -25,7 +27,7 @@ abstract class GridAbstract
protected $router;

/**
* @var \Symfony\Component\HttpFoundation\Request
* @var Request
*/
protected $request;

Expand Down Expand Up @@ -80,16 +82,17 @@ abstract class GridAbstract
abstract public function setupGrid();

/**
* @param \Symfony\Component\DependencyInjection\Container $container
* @param Container $container
* @param Request $request
*
* @return \PedroTeixeira\Bundle\GridBundle\Grid\GridAbstract
*/
public function __construct(\Symfony\Component\DependencyInjection\Container $container)
public function __construct(Container $container, Request $request)
{
$this->container = $container;
$this->request = $request;

$this->router = $this->container->get('router');
$this->request = $this->container->get('request');
$this->templating = $this->container->get('templating');

$this->columns = array();
Expand All @@ -109,7 +112,7 @@ public function __construct(\Symfony\Component\DependencyInjection\Container $co
}

/**
* @return \Symfony\Component\DependencyInjection\Container
* @return Container
*/
public function getContainer()
{
Expand Down Expand Up @@ -369,24 +372,24 @@ public function getData()

$rowColumn = $row[$column->getField()];

// Array scalar
// Array scalar
} elseif (array_key_exists(0, $row) && array_key_exists($column->getField(), $row[0])) {

$rowColumn = $row[0][$column->getField()];

// Object
// Object
} elseif (method_exists($row, 'get' . ucfirst($column->getField()))) {

$method = 'get' . ucfirst($column->getField());
$rowColumn = $row->$method();

// Object scalar
// Object scalar
} elseif (array_key_exists(0, $row) && method_exists($row[0], 'get' . ucfirst($column->getField()))) {

$method = 'get' . ucfirst($column->getField());
$rowColumn = $row[0]->$method();

// Array
// Array
} elseif ($column->getTwig()) {

$rowColumn = $this->templating->render(
Expand Down
2 changes: 1 addition & 1 deletion Grid/Render/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PedroTeixeira\Bundle\GridBundle\Grid\Render;

use Symfony\Component\Locale\Stub\DateFormat\FullTransformer;
use Symfony\Component\Intl\DateFormatter\DateFormat\FullTransformer;

/**
* Render Date
Expand Down
2 changes: 1 addition & 1 deletion Grid/Render/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PedroTeixeira\Bundle\GridBundle\Grid\Render;

use Symfony\Component\Locale\Stub\DateFormat\FullTransformer;
use Symfony\Component\Intl\DateFormatter\DateFormat\FullTransformer;

/**
* Render Date
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# pedro-teixeira/grid-bundle
# pedro-teixeira/grid-bundle (Symfony3 fork)

[![Build Status](http://img.shields.io/travis/pedro-teixeira/grid-bundle.svg?style=flat)](https://travis-ci.org/pedro-teixeira/grid-bundle) [![Version](http://img.shields.io/packagist/v/pedro-teixeira/grid-bundle.svg?style=flat)](https://packagist.org/packages/pedro-teixeira/grid-bundle) [![Downloads](http://img.shields.io/packagist/dt/pedro-teixeira/grid-bundle.svg?style=flat)](https://packagist.org/packages/pedro-teixeira/grid-bundle) [![License](http://img.shields.io/packagist/l/pedro-teixeira/grid-bundle.svg?style=flat)](https://packagist.org/packages/pedro-teixeira/grid-bundle)

> Ajax grid for Symfony2
> Ajax grid for Symfony3

## Example

Expand Down Expand Up @@ -158,6 +158,7 @@
namespace PedroTeixeira\Bundle\TestBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
Expand All @@ -175,14 +176,14 @@
*
* @return array
*/
public function indexAction()
public function indexAction(Request $request)
{
/** @var \Doctrine\ORM\EntityRepository $repository */
$repository = $this->getDoctrine()->getRepository('PedroTeixeiraTestBundle:TestEntity');
$queryBuilder = $repository->createQueryBuilder('r');

/** @var \PedroTeixeira\Bundle\TestBundle\Grid\TestGrid $grid */
$grid = $this->get('pedroteixeira.grid')->createGrid('\PedroTeixeira\Bundle\TestBundle\Grid\TestGrid');
$grid = $this->get('pedroteixeira.grid')->createGrid('\PedroTeixeira\Bundle\TestBundle\Grid\TestGrid', $request);
$grid->setQueryBuilder($queryBuilder);

if ($grid->isResponseAnswer()) {
Expand Down
10 changes: 10 additions & 0 deletions Resources/public/js/grid.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var run = false;

!function ($) {

/* GRID PUBLIC CLASS DEFINITION
Expand Down Expand Up @@ -25,6 +27,12 @@

, ajax:function () {

console.log("run: " + run);
if(run) {
return;
}
run = true;

var filters = this.$element.find('form').serializeArray(),
tbody = this.$element.find('table').find('tbody.row-result'),
emptyTbody = this.$element.find('table').find('tbody.row-empty'),
Expand Down Expand Up @@ -84,6 +92,7 @@
}

tbody.html(html)
run = false;
},
error:function (error) {
thisClass.gridUnlock()
Expand All @@ -92,6 +101,7 @@
tbody.html('')

alert('Error: ' + error.statusText)
run = false;
}
})

Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "pedro-teixeira/grid-bundle",
"name" : "pedro-teixeira/grid-bundle-s3",
"type" : "symfony-bundle",
"description" : "Ajax grid for Symfony2",
"description" : "Ajax grid for Symfony3",
"keywords" : [
"datagrid",
"grid"
Expand All @@ -17,8 +17,9 @@
],
"require" : {
"php" : ">=5.3",
"symfony/framework-bundle" : "~2 | ~3.0",
"doctrine/orm" : "~2.2"
"symfony/framework-bundle" : "~3",
"symfony/intl": "~3",
"doctrine/orm" : "~2.5"
},
"require-dev" : {
"squizlabs/php_codesniffer" : "~1"
Expand Down