<?php
global $gdb;

$grid = new \grid( 'pp_shop_product_sets' );
$grid -> gdb_opt      = $gdb;
$grid -> limit = 10;
$grid -> sql          = 'SELECT *'
                            . 'FROM ( '
                              . 'SELECT '
                                . 'id, name, status '
                              . 'FROM '
                                . 'pp_shop_product_sets AS psps '
                              . ') AS q1 '
                          . 'WHERE '
                            . '1=1 [where] '
                          . 'ORDER BY '
                            . '[order_p1] [order_p2]';
$grid -> sql_count    = 'SELECT '
                            . 'COUNT(0) FROM ( '
                              . 'SELECT '
                                . 'id, name, status '
                              . 'FROM '
                                . 'pp_shop_product_sets AS psps '
                            . ') AS q1 '
                          . 'WHERE '
                            . '1=1 [where] ';
$grid -> debug        = true;
$grid -> order        = [ 'column' => 'name', 'type' => 'ASC' ];
$grid -> search       = [
                            [ 'name' => 'Nazwa', 'db' => 'name', 'type' => 'text' ],
                            [ 'name' => 'Aktywny', 'db' => 'status', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ]
                        ];
$grid -> columns_view = [
                          [
                            'name' => 'Lp.',
                            'th' => [ 'class' => 'g-lp' ],
                            'td' => [ 'class' => 'g-center' ],
                            'autoincrement' => true
                          ],
                          [
                            'name'  => 'Nazwa',
                            'db'    => 'name',
                            'sort'  => true,
                            'php'   => 'echo "<a href=\'/admin/shop_product_sets/set_edit/id=[id]\'>" . htmlspecialchars( \'[name]\' ) . "</a>";'
                          ],
                          [
                            'name' => 'Aktywny',
                            'db' => 'status',
                            'replace' => [ 'array' => [ 0 => '<span class="text-danger">nie</span>', 1 => 'tak' ] ],
                            'td' => [ 'class' => 'g-center' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
                            'sort' => true
                          ],
                          [
                            'name' => 'Edytuj',
                            'action' => [ 'type' => 'edit', 'url' => '/admin/shop_product_sets/set_edit/id=[id]' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
                            'td' => [ 'class' => 'g-center' ]
                          ],
                          [
                            'name' => 'Usuń',
                            'action' => [ 'type' => 'delete', 'url' => '/admin/shop_product_sets/set_delete/id=[id]' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
                            'td' => [ 'class' => 'g-center' ]
                          ]
                        ];
$grid -> buttons      = [
                          [
                            'label' => 'Dodaj komplet produktów',
                            'url'   => '/admin/shop_product_sets/set_edit/',
                            'icon'  => 'fa-plus-circle',
                            'class' => 'btn-success'
                          ]
                        ];
echo $grid -> draw();
?>