1 |
cc435e16
|
Petr Lukašík
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
namespace App\AdminModule\Presenters;
|
5 |
|
|
|
6 |
|
|
use App\AdminModule\Components\IBookEditFormFactory;
|
7 |
|
|
use App\AdminModule\Components\IBookGridFactory;
|
8 |
|
|
use App\Enum\EFlashMessage;
|
9 |
|
|
use App\Model\Repository\BookRepository;
|
10 |
|
|
|
11 |
|
|
class BookPresenter extends BaseUserPresenter
|
12 |
|
|
{
|
13 |
|
|
/**
|
14 |
|
|
* @var IBookGridFactory
|
15 |
|
|
*/
|
16 |
|
|
private $bookGridFactory;
|
17 |
|
|
/**
|
18 |
|
|
* @var IBookEditFormFactory
|
19 |
|
|
*/
|
20 |
|
|
private $bookEditFormFactory;
|
21 |
|
|
/**
|
22 |
|
|
* @var BookRepository
|
23 |
|
|
*/
|
24 |
|
|
private $bookRepository;
|
25 |
|
|
|
26 |
|
|
public function __construct(
|
27 |
|
|
IBookGridFactory $bookGridFactory,
|
28 |
|
|
IBookEditFormFactory $bookEditFormFactory,
|
29 |
|
|
BookRepository $bookRepository
|
30 |
|
|
)
|
31 |
|
|
{
|
32 |
|
|
parent::__construct();
|
33 |
|
|
|
34 |
|
|
$this->bookGridFactory = $bookGridFactory;
|
35 |
|
|
$this->bookEditFormFactory = $bookEditFormFactory;
|
36 |
|
|
$this->bookRepository = $bookRepository;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
public function actionEdit(int $id)
|
40 |
|
|
{
|
41 |
|
|
$this->template->id = $id;
|
42 |
|
|
$this['bookEditForm']->setId($id);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Akce pro odstranění knihy
|
47 |
|
|
*
|
48 |
|
|
* @param int $id
|
49 |
|
|
* @throws \Nette\Application\AbortException
|
50 |
|
|
*/
|
51 |
|
|
public function actionDelete(int $id)
|
52 |
|
|
{
|
53 |
|
|
$result = $this->bookRepository->findRow($id)->delete();
|
54 |
|
|
if ($result) {
|
55 |
|
|
$this->flashMessage('Book was successfully deleted.', EFlashMessage::SUCCESS);
|
56 |
|
|
} else {
|
57 |
|
|
$this->flashMessage('Book wasn\'t deleted.', EFlashMessage::ERROR);
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
$this->redirect('Book:default');
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
/**
|
64 |
|
|
* Handle používaný v BookGrid pro smazání knihy
|
65 |
|
|
*
|
66 |
|
|
* @param int $id : ID mazané knihy
|
67 |
|
|
*/
|
68 |
|
|
public function handleDeleteBook(int $id)
|
69 |
|
|
{
|
70 |
|
|
if ($this->isAjax()) {
|
71 |
|
|
$this->bookRepository->findRow($id)->delete();
|
72 |
|
|
$this['bookGrid']->reload();
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
public function createComponentBookGrid()
|
77 |
|
|
{
|
78 |
|
|
return $this->bookGridFactory->create();
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
public function createComponentBookEditForm()
|
82 |
|
|
{
|
83 |
|
|
return $this->bookEditFormFactory->create();
|
84 |
|
|
}
|
85 |
|
|
}
|