Projekt

Obecné

Profil

Stáhnout (2.18 KB) Statistiky
| Větev: | Tag: | Revize:
1 d052c689 Jan Šedivý
<?php
2
3
namespace App\AdminModule\Presenters;
4
5
6 80b17f46 Jan Šedivý
use App\AdminModule\Components\IObjectTypeEditFormFactory;
7 d052c689 Jan Šedivý
use App\AdminModule\Components\IObjectTypeGridFactory;
8 80b17f46 Jan Šedivý
use App\Enum\EFlashMessage;
9 d052c689 Jan Šedivý
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 80b17f46 Jan Šedivý
    /** @var IObjectTypeEditFormFactory */
20
    private $objectTypeEditFormFactory;
21
22
    private $typeId;
23
24 d052c689 Jan Šedivý
    /**
25
     * ObjectPresenter constructor.
26
     * @param ObjectTypeRepository $objectTypeRepository
27 80b17f46 Jan Šedivý
     * @param IObjectTypeGridFactory $objectTypeGridFactory
28
     * @param IObjectTypeEditFormFactory $objectTypeEditFormFactory
29 d052c689 Jan Šedivý
     */
30
    public function __construct(
31
        ObjectTypeRepository $objectTypeRepository,
32 80b17f46 Jan Šedivý
        IObjectTypeGridFactory $objectTypeGridFactory,
33
        IObjectTypeEditFormFactory $objectTypeEditFormFactory
34 d052c689 Jan Šedivý
    )
35
    {
36
        $this->objectTypeRepository = $objectTypeRepository;
37
        $this->objectTypeGridFactory = $objectTypeGridFactory;
38 80b17f46 Jan Šedivý
        $this->objectTypeEditFormFactory = $objectTypeEditFormFactory;
39 d052c689 Jan Šedivý
40
        parent::__construct();
41
    }
42
43
    public function actionDefault()
44
    {
45
46
    }
47
48
    public function actionEditType(int $id)
49
    {
50 80b17f46 Jan Šedivý
        if(!$this->objectTypeRepository->findRow($id))
51
        {
52
            $this->flashMessage('Object type was not found.', EFlashMessage::ERROR);
53
            $this->redirect('Object:');
54
        }
55 d052c689 Jan Šedivý
56 80b17f46 Jan Šedivý
        $this->typeId = $id;
57
        $this->template->id = $id;
58 d052c689 Jan Šedivý
    }
59
60
    public function actionDeleteType(int $id)
61
    {
62 80b17f46 Jan Šedivý
        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 d052c689 Jan Šedivý
    }
72
73
    public function createComponentObjectTypeGrid()
74
    {
75
        return $this->objectTypeGridFactory->create();
76
    }
77
78 80b17f46 Jan Šedivý
    public function createComponentObjectTypeEditForm()
79
    {
80
        return $this->objectTypeEditFormFactory->create($this->typeId);
81
    }
82 d052c689 Jan Šedivý
}