PHP Classes

Universal PHP Data Grid: Display and process data to edit database records

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (54)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
StarStar 39%Total: 503 This week: 1All time: 5,797 This week: 560Up
Version License PHP version Categories
gd 2.0.3MIT/X Consortium ...7HTML, Databases, Libraries, PHP 7
Description 

Author

This package can display and process data to edit database records.

It provides several classes that can display data retrieved from database table records in a table grid and shows forms that can be used to edit the data in the view grid.

The package can be integrated in applications that use the frameworks Simfony, Laravel, Zend, Yii2 and others.

The package can be extend using plugins.

Innovation Award
PHP Programming Innovation award nominee
February 2019
Number 5
Data grids are way to display and edit data retrieved from databases in a grid that shows data in tables.

This package can display and process data in grids in a way that can work together modern PHP frameworks such as Simfony, Laravel, Zend, and Yii2.

Manuel Lemos
Picture of Ar Gabid
  Performance   Level  
Name: Ar Gabid <contact>
Classes: 1 package by
Country: Kazakhstan Kazakhstan
Age: ???
All time rank: 32574 in Kazakhstan Kazakhstan
Week rank: 416 Up1 in Kazakhstan Kazakhstan Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php
/**
 * @author GD Lab <dev.gdgrid@gmail.com>
 */

require_once 'init.php';

use
Seytar\Routing\Router;

use
Illuminate\Http\Request;

Router::bootstrap(function($ex)
{
   
header('Content-Type: text/html; charset=utf-8');
    echo
'404 - Page Not Found';
});

Route::get('/', function()
{
    include
'users.php';
});

Route::get('/delete/{id}', function($id)
{
    if (
$user = User::find($id))

       
$user->delete();

   
header('Location:/');

    exit;
});

Route::get('/create', function()
{
   
define('ROUTE', 'create');

   
$provider = new User;

    include
'form.php';
});

Route::get('/update/{id}', function($id)
{
   
define('ROUTE', 'update');

   
$provider = User::find($id);

    include
'form.php';
});

Route::post('/create', function()
{
   
define('ROUTE', 'create');

   
$provider = new User;

   
$request = Request::capture();

   
$validator = (new ValidatorFactory())->make($request->all(), $provider->rules());

   
$provider->loadData($request->all());

    if (
$validator->fails())
    {
       
$provider->setErrors($validator->messages()->toArray());
    }
    else
    {
       
$provider->save();

       
header('Location:/');

        exit;
    }

    include
'form.php';
});

Route::post('/update/{id}', function($id)
{
   
define('ROUTE', 'update');

   
$provider = User::find($id);

   
$request = Request::capture();

   
$validator = (new ValidatorFactory())->make($request->all(), $provider->rules());

   
$provider->loadData($request->all());

    if (
$validator->fails())
    {
       
$provider->setErrors($validator->messages()->toArray());
    }
    else
    {
       
$provider->save();

       
header('Location:/');

        exit;
    }

    include
'form.php';
});


Details

Grid-Data

The PHP 7 Grid-Data Library.

The main purpose of the Library is to automatically generate tables, forms and representations of certain entities in the views. If the form and column field settings of the entity are not specified, then these settings are taken from the column types and their names in the database table.

For all this, you need to implement a specific interface in the entity itself, or connect a separate class that implements the interface itself and pass it to the generator.

Install


If you want to run the test application (included in the "testapp" folder of the Library), therefor you will 
have to install all necessary dependencies from composer.json:

{ "require": {

"gdgrid/gd": "dev-master"

}, "require-dev": {

"illuminate/database": "5.7",
"illuminate/filesystem": "5.7",
"illuminate/translation": "5.7",
"illuminate/validation": "5.7",
"symfony/var-dumper": "^4.1",
"seytar/php-router": "dev-master"

}, "autoload": {

"classmap": [
  "testapp/models/"
]

} }


# Usage example

1. Using Entity itself.

``Your model Class:``

```php
<?php

use Illuminate\Database\Eloquent\Model as Eloquent;

use gdgrid\gd\IGridFormProvider;

use gdgrid\gd\IGridTableProvider;

class User extends Eloquent implements IGridFormProvider, IGridTableProvider
{
    protected $fillable = ['name', 'image', 'email', 'gender', 'character'];

    public $timestamps = false;

    protected $errors = [];
    
    ... 
    
    public function gridFields(): array
    {
        return [
            'name' => 'Hero',
            'email' => 'Email',
            'image' => 'Photo',
            'character' => 'Description',
            'gender' => 'Gender',
        ];
    }
    
    public function gridInputTypes(): array
    {
        return [
            'name' => 'text',
            'email' => 'email',
            'image' => 'text',
            'character' => 'textarea',
            'gender' => 'radio',
        ];
    }
    
    public function gridInputOptions(): array
    {
        return [
            'gender' => ['Female', 'Male'],
        ];
    }
    
    public function gridInputSizes(): array
    {
        return [
            'name' => 100,
            'email' => 100,
            'image' => 255,
            'character' => 1000,
        ];
    }
    
    public function gridSafeFields(): array
    {
        return ['id'];
    }
    
    public function gridInputErrors(): array
    {
        return $this->errors;
    }

    public function gridTableCellPrompts()
    {
        return '(no data)';
    }

    public function gridInputPrompts(): array
    {
        return [];
    }
}

```

``View File:``

```php
<?php

use gdgrid\gd\GridTable;
use gdgrid\gd\GridForm;

$provider = new User;

$items = $provider->filter(Request::capture()->all())->get()->all();

$table = (new GridTable($provider))->loadColumns();

$table->plugin()->setConfig('bulk-actions', ['view' => false, 'set_query' => false]);

$table->plugin()->hook('filter', function(GridForm $plugin)
{
    $plugin->loadInputs()->setValues(Request::capture()->all());
});

$table->disableEmbedPlugin('pagination');

$table->setProviderItems($items)->setCell('image', function($data)
{
    return $data->image ? '<img src="' . $data->image . '" />' : null;
});

echo $table->render();

```

2. Using Data Provider.

``In this case it is not neccessary to implement interfaces in your entity class.``

``Your model Class:``

```php
<?php

use Illuminate\Database\Eloquent\Model as Eloquent;

class User extends Eloquent
{
    protected $fillable = ['name', 'image', 'email', 'gender', 'character'];

    public $timestamps = false;

    protected $errors = [];
    
    ... 
}

```

``View File:``

```php
<?php

use gdgrid\gd\bundle\Grid as BundleGrid;
use gdgrid\gd\Grid;
use gdgrid\gd\GridData;
use gdgrid\gd\GridDataProvider;
use gdgrid\gd\GridForm;
use gdgrid\gd\GridTable;
use Illuminate\Http\Request;

$provider = new User;

# The "isStoreOutdated" method checks if the current dataProvider`s instance is outdated in the BundleGrid`s cache:

$items = BundleGrid::capture()->isStoreOutdated('someStoreKey') 
    
    ? $provider->filter(Request::capture()->all())->get()->all() : [];

$dataProvider = new GridDataProvider($provider);

$dataProvider->setDataProvider((new GridData)
    ->setPdo(DB::capsule()->getConnection()->getPdo())
    ->setTable('users')
    ->setLocale('en'));

$dataProvider->fetchData();

$dataProvider->mergeData([
    'safeFields'   => [
        'id',
    ],
    'inputOptions' => [
        'gender' => ['Female', 'Male']
    ]
]);

$table = (new GridTable($dataProvider))->loadColumns();

if (sizeof($items)) $table->setProviderItems($items);

# Use of the Bundle Grid simplifies all initializations produced above in a single line:
//    $table = BundleGrid::capture() # method "capture" for create/access the GridBundle`s singleton.
//          ->store('someStoreKey') # method "store" (optional) for serialization/access the current GridBundle instance.
//          ->setProvider($provider)
//          ->fetchData(DB::capsule()->getConnection()->getPdo(), 'users')
//          ->mergeData([
//              'inputOptions' => [
//                  'gender' => ['FEMALE', 'MALE']
//              ]
//          ])->table();

# Serialize changes in the current BundleGrid`s instance
# (The methods "store/restore" brings ability for further access the dataProvider`s instance from BundleGrid`s cache):
//    if (BundleGrid::capture()->isStoreOutdated('someStoreKey')) BundleGrid::capture()->restore('someStoreKey', 3600);

$table->plugin()->setConfig('bulk-actions', ['view' => false, 'set_query' => false]);

$table->plugin()->hook('filter', function(GridForm $plugin, Grid $grid)
{
    $plugin->loadInputs()->setValues(Request::capture()->all());
});

# Can Disable the Embedded Plugins:
//    $table->disableEmbedPlugins();

# Pagination disabled. To enable it, you must specify quantity of records
# in the "totalCount" configuration parameter:
//    $table->plugin()->setConfig('pagination', ['totalCount' => ???]);

$table->disableEmbedPlugin('pagination');

# Can Format the values in the data table cells:
//    $table->setFormatAll(['truncate' => 5]);
//    $table->formatter()->mergeFormats([['strtoupper', []]]);
//    $table->setFormat([
//        [['name', 'email'], ['trim', 'strip_tags']],
//        ['character', ['strip_html']],
//    ]);

$table->setCell('image', function($data)
{
    return $data->image ? '<img src="' . $data->image . '" />' : null;
});

echo $table->render();

```

The full code of the represented examples you can find in the "testapp" directory of the Library.
Just copy/paste files to the document root of your application.

Screenshots  
  • GridTable
  Files folder image Files  
File Role Description
Files folder imagesrc (12 files, 5 directories)
Files folder imagetestapp (6 files, 3 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imagebootstrap (1 file)
Files folder imagebundle (4 files, 1 directory)
Files folder imagedrv (4 files)
Files folder imageplugin (2 files, 1 directory)
Files folder imagerender (1 directory)
  Plain text file Grid.php Class Class source
  Plain text file GridData.php Class Class source
  Plain text file GridDataFormatter.php Class Class source
  Plain text file GridDataProvider.php Class Class source
  Plain text file GridForm.php Class Class source
  Plain text file GridTable.php Class Class source
  Plain text file GridView.php Class Class source
  Plain text file IGrid.php Class Class source
  Plain text file IGridData.php Class Class source
  Plain text file IGridFormProvider.php Class Class source
  Plain text file IGridProvider.php Class Class source
  Plain text file IGridTableProvider.php Class Class source

  Files folder image Files  /  src  /  bootstrap  
File Role Description
  Accessible without login Plain text file autoload.php Example Example script

  Files folder image Files  /  src  /  bundle  
File Role Description
Files folder imageconnectors (4 files)
  Plain text file Adapter.php Class Class source
  Plain text file Asset.php Class Class source
  Plain text file Grid.php Class Class source
  Plain text file TAdapter.php Class Class source

  Files folder image Files  /  src  /  bundle  /  connectors  
File Role Description
  Plain text file AssetConnector.php Class Class source
  Plain text file GridConnector.php Class Class source
  Plain text file IConnector.php Class Class source
  Plain text file TConnector.php Class Class source

  Files folder image Files  /  src  /  drv  
File Role Description
  Plain text file GridDataMysqlDriver.php Class Class source
  Plain text file GridDataPgsqlDriver.php Class Class source
  Plain text file GridDataSqliteDriver.php Class Class source
  Plain text file IGridDataDriver.php Class Class source

  Files folder image Files  /  src  /  plugin  
File Role Description
Files folder imagecomponents (4 directories)
  Plain text file GridPlugin.php Class Class source
  Plain text file IGridPlugin.php Class Class source

  Files folder image Files  /  src  /  plugin  /  components  
File Role Description
Files folder imageassets (1 file)
Files folder imagebulk-actions (1 file)
Files folder imagefilter (1 file, 1 directory)
Files folder imagepagination (3 files)

  Files folder image Files  /  src  /  plugin  /  components  /  assets  
File Role Description
  Accessible without login Plain text file init.php Example Example script

  Files folder image Files  /  src  /  plugin  /  components  /  bulk-actions  
File Role Description
  Accessible without login Plain text file init.php Example Example script

  Files folder image Files  /  src  /  plugin  /  components  /  filter  
File Role Description
Files folder imageassets (2 files)
  Accessible without login Plain text file init.php Example Example script

  Files folder image Files  /  src  /  plugin  /  components  /  filter  /  assets  
File Role Description
  Accessible without login Plain text file filter.css Data Auxiliary data
  Accessible without login Plain text file filter.js Data Auxiliary data

  Files folder image Files  /  src  /  plugin  /  components  /  pagination  
File Role Description
  Accessible without login Plain text file init.php Example Example script
  Accessible without login Plain text file pagination-template.php Example Example script
  Plain text file Pagination.php Class Class source

  Files folder image Files  /  src  /  render  
File Role Description
Files folder imagehtml (3 directories)

  Files folder image Files  /  src  /  render  /  html  
File Role Description
Files folder imageform (1 file)
Files folder imagetable (1 file)
Files folder imageview (2 files)

  Files folder image Files  /  src  /  render  /  html  /  form  
File Role Description
  Accessible without login Plain text file form.php Example Example script

  Files folder image Files  /  src  /  render  /  html  /  table  
File Role Description
  Accessible without login Plain text file table.php Example Example script

  Files folder image Files  /  src  /  render  /  html  /  view  
File Role Description
  Accessible without login Plain text file view-items.php Example Example script
  Accessible without login Plain text file view.php Example Example script

  Files folder image Files  /  testapp  
File Role Description
Files folder imagegd-assets (1 directory)
Files folder imagemodels (3 files)
Files folder imagestorage (1 directory)
  Accessible without login Plain text file form.php Example Example script
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file init.php Aux. Auxiliary script
  Accessible without login Plain text file schema.php Example Example script
  Accessible without login Plain text file seed.php Aux. Auxiliary script
  Accessible without login Plain text file users.php Example Example script

  Files folder image Files  /  testapp  /  gd-assets  
File Role Description
Files folder imagefilter (2 files)

  Files folder image Files  /  testapp  /  gd-assets  /  filter  
File Role Description
  Accessible without login Plain text file filter.css Data Auxiliary data
  Accessible without login Plain text file filter.js Data Auxiliary data

  Files folder image Files  /  testapp  /  models  
File Role Description
  Plain text file DB.php Class Class source
  Plain text file User.php Class Class source
  Plain text file ValidatorFactory.php Class Class source

  Files folder image Files  /  testapp  /  storage  
File Role Description
Files folder imagelang (1 directory)

  Files folder image Files  /  testapp  /  storage  /  lang  
File Role Description
Files folder imageen (1 file)

  Files folder image Files  /  testapp  /  storage  /  lang  /  en  
File Role Description
  Accessible without login Plain text file validation.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 98%
Total:503
This week:1
All time:5,797
This week:560Up
User Ratings User Comments (1)
 All time
Utility:58%StarStarStar
Consistency:66%StarStarStarStar
Documentation:-
Examples:41%StarStarStar
Tests:-
Videos:-
Overall:39%StarStar
Rank:3787
 
You cn't install this package errors in .
5 years ago (adriano ghezzi)
0%Star