1
|
<?php
|
2
|
|
3
|
|
4
|
namespace App\AdminModule\Presenters;
|
5
|
|
6
|
|
7
|
use App\AdminModule\Components\IOriginEditFormFactory;
|
8
|
use App\AdminModule\Components\IOriginGridFactory;
|
9
|
use App\Enum\EFlashMessage;
|
10
|
use App\Model\Repository\OriginRepository;
|
11
|
|
12
|
class OriginPresenter extends BaseUserPresenter
|
13
|
{
|
14
|
/**
|
15
|
* @var IOriginGridFactory
|
16
|
*/
|
17
|
private $originGridFactory;
|
18
|
/**
|
19
|
* @var IOriginEditFormFactory
|
20
|
*/
|
21
|
private $originEditFormFactory;
|
22
|
/**
|
23
|
* @var OriginRepository
|
24
|
*/
|
25
|
private $originRepository;
|
26
|
|
27
|
public function __construct(IOriginGridFactory $originGridFactory,
|
28
|
IOriginEditFormFactory $originEditFormFactory,
|
29
|
OriginRepository $originRepository)
|
30
|
{
|
31
|
parent::__construct();
|
32
|
|
33
|
$this->originGridFactory = $originGridFactory;
|
34
|
$this->originEditFormFactory = $originEditFormFactory;
|
35
|
$this->originRepository = $originRepository;
|
36
|
}
|
37
|
|
38
|
public function actionEdit(int $id)
|
39
|
{
|
40
|
$this->template->id = $id;
|
41
|
$this['originEditForm']->setOrigin($id);
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Akce pro odstranění místa původu
|
46
|
*
|
47
|
* @param int $id
|
48
|
* @throws \Nette\Application\AbortException
|
49
|
*/
|
50
|
public function actionDelete(int $id)
|
51
|
{
|
52
|
$result = $this->originRepository->findRow($id)->delete();
|
53
|
if ($result)
|
54
|
{
|
55
|
$this->flashMessage('Origin was successfully deleted.', EFlashMessage::SUCCESS);
|
56
|
} else
|
57
|
{
|
58
|
$this->flashMessage('Origin wasn\'t deleted.', EFlashMessage::ERROR);
|
59
|
}
|
60
|
|
61
|
$this->redirect('Origin:default');
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Handle používaný v OriginGrid pro smazání místa původu
|
66
|
*
|
67
|
* @param int $id : ID mazaného místa původu
|
68
|
*/
|
69
|
public function handleDeleteOrigin(int $id)
|
70
|
{
|
71
|
if ($this->isAjax())
|
72
|
{
|
73
|
$this->originRepository->findRow($id)->delete();
|
74
|
$this['originGrid']->reload();
|
75
|
}
|
76
|
}
|
77
|
|
78
|
public function createComponentOriginGrid()
|
79
|
{
|
80
|
return $this->originGridFactory->create();
|
81
|
}
|
82
|
|
83
|
public function createComponentOriginEditForm()
|
84
|
{
|
85
|
return $this->originEditFormFactory->create();
|
86
|
}
|
87
|
}
|