2017 © Pedro Peláez
 

symfony-bundle grid

Trinity Grid bundle

image

trinity/grid

Trinity Grid bundle

  • Saturday, December 2, 2017
  • by modpreneur
  • Repository
  • 28 Watchers
  • 2 Stars
  • 3,069 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Trinity Grid

Trinity grid is part of Trinity package., (*1)

Description:, (*2)

  • Converts an array of entities to array of strings.
  • Array of string is convert to JSON:

Documentation

Grid Template

1) Create Grid Template

Create class extended by BaseGrid. Add templates for change attributes value., (*3)

class ProductGrid extends BaseGrid
{
    public function setUp()
    {
        $this->addTemplate("ProductGrid.html.twig"); // add new twig template for changing values.
    }
}
Set up
addTemplate     - add new template for changing values. 
setColumnFormat - for basic change value of date or simple text edit. @todo Jancar example (dog eyes, nicely please)
Template:

For change value of cell use block cell_attributeName., (*4)

{% block cell_name %} Template edit - {{ value }} {% endblock %}

Available variables: - value = value of cell - row = entity object, (*5)

2) Register Grid Template

In services.yml, (*6)

services:
  trinity.grid.test.product:
    class: Trinity\Bundle\GridBundle\Tests\Functional\Grid\ProductGrid
    tags:
        - { name: trinity.grid, alias: product } // tag name have to be trinity.grid, alias is mandatory value for searching grids from entity name.

Grid filters

Filters are used to change the attribute values., (*7)

1) Create filter:

Filter have to inherit from BaseFilter or FilterInterface!, (*8)

class IdFilter extends BaseFilter
{
    /**
     * @var string
     */
    protected $name = 'id';  //mandatory for not global filter

    /**
     * @param string|object|int|bool $input
     * @param array $arguments
     * @return string
     */
    function process($input, array $arguments = []) : string
    {
        return $input.'.';
    }
}

2) Grid registration:

In services.yml, (*9)

trinity.grid.filter.id:
  class: Trinity\Bundle\GridBundle\Filter\IdFilter
  tags:
    - {name: "trinity.grid.filter"} //tag name have to be trinity.grid.filter

3) Set up filter for current grid:

 $this->setColumnFilter('columnName', 'filterName');

4) Global filters

For global filter must be set attribute 'global' to TRUE;, (*10)

Attribute 'name' is not necessary., (*11)

class ObjectFilter extends BaseFilter
{
    protected $global = true;

    /**
     * @param string|object|int|bool $input
     * @param array $arguments
     * @return string
     */
    function process($input, array $arguments = []) : string
    {
        if ((is_object($input) && method_exists($input, 'getName'))) {
            $input = $input->getName();
        } elseif (is_object($input)) {
            $input = (string)$input;
        }
        return $input;
    }
}

Parse entity array to array of strings

From container pull service 'trinity.grid.manager', (*12)

$manager = $container->get('trinity.grid.manager');

Parse array of entities:, (*13)

$stringArray = $manager->convertEntitiesToArray(
            $this->getArrayOfEntities(),                                        // array of entities
            ['id', 'name', 'description', 'nonexistentColumn', 'createdAt']     // columns
        );

From the entity name is found grid. $stringArray is must be convert to JSON., (*14)

The Versions