1 |
cc435e16
|
Petr Lukašík
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
namespace App\AdminModule\Components;
|
5 |
|
|
|
6 |
|
|
use App\Model\Repository\BookRepository;
|
7 |
|
|
use App\Utils\DataGrid\DataGrid;
|
8 |
|
|
use Ublaboo\DataGrid\Exception\DataGridException;
|
9 |
|
|
|
10 |
|
|
class BookGrid extends DataGrid
|
11 |
|
|
{
|
12 |
|
|
/**
|
13 |
|
|
* @var BookRepository
|
14 |
|
|
*/
|
15 |
|
|
private $bookRepository;
|
16 |
|
|
|
17 |
|
|
public function __construct(BookRepository $bookRepository)
|
18 |
|
|
{
|
19 |
|
|
$this->bookRepository = $bookRepository;
|
20 |
|
|
|
21 |
|
|
parent::__construct(false);
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Abstraktní metoda, slouží k nastavení primárního klíče a nastavení datasource
|
26 |
|
|
* 1. $this->setPrimaryKey();
|
27 |
|
|
* 2. $this->setDataSource();
|
28 |
|
|
*
|
29 |
|
|
* @throws DataGridException
|
30 |
|
|
*/
|
31 |
|
|
public function init()
|
32 |
|
|
{
|
33 |
|
|
$this->setPrimaryKey(BookRepository::COLUMN_ID);
|
34 |
|
|
$this->setDataSource($this->bookRepository->findAll()->order(BookRepository::COLUMN_BOOK_ABREV));
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
/**
|
38 |
|
|
* Definice sloupečků, akcí, vyhledávácích filtrů gridu
|
39 |
|
|
*
|
40 |
|
|
* @throws DataGridException
|
41 |
|
|
*/
|
42 |
|
|
public function define()
|
43 |
|
|
{
|
44 |
|
|
// Definice sloupečků
|
45 |
|
|
$this->addColumnNumber(BookRepository::COLUMN_ID, 'ID')->setDefaultHide(TRUE);
|
46 |
|
|
$this->addColumnText(BookRepository::COLUMN_BOOK_ABREV, 'Abbreviation')->setAlign('center');
|
47 |
|
|
$this->addColumnText(BookRepository::COLUMN_BOOK_AUTHOR, 'Author')->addAttributes(["width" => "10%"])->setAlign('center');
|
48 |
|
|
$this->addColumnText(BookRepository::COLUMN_BOOK_NAME, 'Name')->setAlign('center');
|
49 |
|
|
$this->addColumnText(BookRepository::COLUMN_BOOK_SUBTITLE, 'Alternate name')->setAlign('center');
|
50 |
|
|
$this->addColumnText(BookRepository::COLUMN_BOOK_DESCRIPTION, 'Description')->addAttributes(["width" => "20%"])->setAlign('center');
|
51 |
|
|
$this->addColumnText(BookRepository::COLUMN_PLACE_OF_PUB, 'Publication place')->setAlign('center');
|
52 |
|
|
$this->addColumnText(BookRepository::COLUMN_DATE_OF_PUB, 'Publication date')->setAlign('center');
|
53 |
|
|
$this->addColumnText(BookRepository::COLUMN_PAGES, 'Pages')->setAlign('center');
|
54 |
|
|
$this->addColumnText(BookRepository::COLUMN_VOLUME, 'Volume')->setAlign('center');
|
55 |
|
|
$this->addColumnText(BookRepository::COLUMN_VOLUME_NO, 'Volume No.')->setAlign('center');
|
56 |
|
|
|
57 |
|
|
// Definice filtrů
|
58 |
|
|
$this->addFilterText(BookRepository::COLUMN_BOOK_ABREV, 'Abbreviation');
|
59 |
|
|
$this->addFilterText(BookRepository::COLUMN_BOOK_AUTHOR, 'Author');
|
60 |
|
|
$this->addFilterText(BookRepository::COLUMN_BOOK_NAME, 'Name');
|
61 |
|
|
$this->addFilterText(BookRepository::COLUMN_BOOK_SUBTITLE, 'Alternate name');
|
62 |
|
|
$this->addFilterText(BookRepository::COLUMN_BOOK_DESCRIPTION, 'Description');
|
63 |
|
|
$this->addFilterText(BookRepository::COLUMN_PLACE_OF_PUB, 'Publication place');
|
64 |
|
|
$this->addFilterText(BookRepository::COLUMN_DATE_OF_PUB, 'Publication date');
|
65 |
|
|
$this->addFilterText(BookRepository::COLUMN_PAGES, 'Pages');
|
66 |
|
|
$this->addFilterText(BookRepository::COLUMN_VOLUME, 'Volume');
|
67 |
|
|
$this->addFilterText(BookRepository::COLUMN_VOLUME_NO, 'Volume No.');
|
68 |
|
|
|
69 |
|
|
// Definice akcí
|
70 |
|
|
$this->addAction('edit', 'edit', 'Book:edit', ['id' => BookRepository::COLUMN_ID])
|
71 |
|
|
->setTitle('Edit');
|
72 |
|
|
|
73 |
|
|
$this->addAction('delete', 'delete', 'deleteBook!', ['id' => BookRepository::COLUMN_ID])
|
74 |
|
|
->setConfirm('Do you really want to delete book %s.', BookRepository::COLUMN_BOOK_ABREV)
|
75 |
|
|
->setTitle('Delete')
|
76 |
|
|
->setClass('btn btn-xs btn-danger ajax');
|
77 |
|
|
}
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
interface IBookGridFactory
|
81 |
|
|
{
|
82 |
|
|
/**
|
83 |
|
|
* @return BookGrid
|
84 |
|
|
*/
|
85 |
|
|
public function create();
|
86 |
|
|
}
|