Projekt

Obecné

Profil

Stáhnout (2.1 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?php
2

    
3

    
4
namespace App\AdminModule\Presenters;
5

    
6
use App\AdminModule\Components\IMuseumEditFormFactory;
7
use App\AdminModule\Components\IMuseumGridFactory;
8
use App\Enum\EFlashMessage;
9
use App\Model\Repository\MuseumRepository;
10

    
11
class MuseumPresenter extends BaseAdminPresenter
12
{
13
    /**
14
     * @var IMuseumGridFactory
15
     */
16
    private $museumGridFactory;
17
    /**
18
     * @var IMuseumEditFormFactory
19
     */
20
    private $museumEditFormFactory;
21
    /**
22
     * @var MuseumRepository
23
     */
24
    private $museumRepository;
25

    
26
    public function __construct(IMuseumGridFactory $museumGridFactory,
27
                                IMuseumEditFormFactory $museumEditFormFactory,
28
                                MuseumRepository $museumRepository
29
    )
30
    {
31
        parent::__construct();
32

    
33
        $this->museumGridFactory = $museumGridFactory;
34
        $this->museumEditFormFactory = $museumEditFormFactory;
35
        $this->museumRepository = $museumRepository;
36
    }
37

    
38
    public function actionEdit(int $id)
39
    {
40
        $this['museumEditForm']->setMuseum($id);
41
        $this->template->id = $id;
42
    }
43

    
44
    /**
45
     * Handle používaný v MuseumGrid pro smazání muzea
46
     *
47
     * @param int $id : ID mazaného muzea
48
     */
49
    public function handleDeleteMuseum(int $id)
50
    {
51
        if ($this->isAjax())
52
        {
53
            $this->museumRepository->findRow($id)->delete();
54
            $this['museumGrid']->reload();
55
        }
56
    }
57

    
58
    /**
59
     * Akce pro odstranění muzea
60
     *
61
     * @param int $id
62
     * @throws \Nette\Application\AbortException
63
     */
64
    public function actionDeleteMuseum(int $id)
65
    {
66
        if($this->museumRepository->delete($id))
67
        {
68
            $this->flashMessage('Museum was deleted.', EFlashMessage::SUCCESS);
69
        }
70
        else
71
        {
72
            $this->flashMessage('Museum was not found.', EFlashMessage::ERROR);
73
        }
74
        $this->redirect('Museum:');
75
    }
76

    
77
    public function createComponentMuseumGrid()
78
    {
79
        return $this->museumGridFactory->create();
80
    }
81

    
82
    public function createComponentMuseumEditForm()
83
    {
84
        return $this->museumEditFormFactory->create();
85
    }
86
}
(6-6/12)