1
|
<?php
|
2
|
|
3
|
namespace App\AdminModule\Presenters;
|
4
|
|
5
|
|
6
|
use App\AdminModule\Components\IObjectTypeEditFormFactory;
|
7
|
use App\AdminModule\Components\IObjectTypeGridFactory;
|
8
|
use App\Enum\EFlashMessage;
|
9
|
use App\Model\Repository\ObjectTypeRepository;
|
10
|
|
11
|
class ObjectPresenter extends BaseUserPresenter
|
12
|
{
|
13
|
/** @var ObjectTypeRepository */
|
14
|
private $objectTypeRepository;
|
15
|
|
16
|
/** @var IObjectTypeGridFactory */
|
17
|
private $objectTypeGridFactory;
|
18
|
|
19
|
/** @var IObjectTypeEditFormFactory */
|
20
|
private $objectTypeEditFormFactory;
|
21
|
|
22
|
private $typeId;
|
23
|
|
24
|
/**
|
25
|
* ObjectPresenter constructor.
|
26
|
* @param ObjectTypeRepository $objectTypeRepository
|
27
|
* @param IObjectTypeGridFactory $objectTypeGridFactory
|
28
|
* @param IObjectTypeEditFormFactory $objectTypeEditFormFactory
|
29
|
*/
|
30
|
public function __construct(
|
31
|
ObjectTypeRepository $objectTypeRepository,
|
32
|
IObjectTypeGridFactory $objectTypeGridFactory,
|
33
|
IObjectTypeEditFormFactory $objectTypeEditFormFactory
|
34
|
)
|
35
|
{
|
36
|
$this->objectTypeRepository = $objectTypeRepository;
|
37
|
$this->objectTypeGridFactory = $objectTypeGridFactory;
|
38
|
$this->objectTypeEditFormFactory = $objectTypeEditFormFactory;
|
39
|
|
40
|
parent::__construct();
|
41
|
}
|
42
|
|
43
|
public function actionDefault()
|
44
|
{
|
45
|
|
46
|
}
|
47
|
|
48
|
public function actionEditType(int $id)
|
49
|
{
|
50
|
if(!$this->objectTypeRepository->findRow($id))
|
51
|
{
|
52
|
$this->flashMessage('Object type was not found.', EFlashMessage::ERROR);
|
53
|
$this->redirect('Object:');
|
54
|
}
|
55
|
|
56
|
$this->typeId = $id;
|
57
|
$this->template->id = $id;
|
58
|
}
|
59
|
|
60
|
public function actionDeleteType(int $id)
|
61
|
{
|
62
|
if($this->objectTypeRepository->delete($id))
|
63
|
{
|
64
|
$this->flashMessage('Object type was deleted.', EFlashMessage::SUCCESS);
|
65
|
}
|
66
|
else
|
67
|
{
|
68
|
$this->flashMessage('Object type was not found.', EFlashMessage::ERROR);
|
69
|
}
|
70
|
$this->redirect('Object:');
|
71
|
}
|
72
|
|
73
|
public function handleDeleteType(int $id)
|
74
|
{
|
75
|
if($this->isAjax())
|
76
|
{
|
77
|
$this->objectTypeRepository->delete($id);
|
78
|
$this['objectTypeGrid']->reload();
|
79
|
}
|
80
|
}
|
81
|
|
82
|
public function createComponentObjectTypeGrid()
|
83
|
{
|
84
|
return $this->objectTypeGridFactory->create();
|
85
|
}
|
86
|
|
87
|
public function createComponentObjectTypeEditForm()
|
88
|
{
|
89
|
return $this->objectTypeEditFormFactory->create($this->typeId);
|
90
|
}
|
91
|
}
|