Projekt

Obecné

Profil

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

    
3

    
4
namespace App\AdminModule\Presenters;
5

    
6

    
7
use App\AdminModule\Components\IUserEditFormFactory;
8
use App\AdminModule\Components\IUserGridFactory;
9
use App\Enum\EFlashMessage;
10
use App\Model\Facade\UserFacade;
11

    
12
class UserPresenter extends BaseAdminPresenter
13
{
14
    /**
15
     * @var IUserGridFactory
16
     */
17
    private $userGridFactory;
18
    /**
19
     * @var IUserEditFormFactory
20
     */
21
    private $userEditFormFactory;
22
    /**
23
     * @var UserFacade
24
     */
25
    private $userFacade;
26

    
27
    public function __construct(IUserGridFactory $userGridFactory,
28
                                IUserEditFormFactory $userEditFormFactory,
29
                                UserFacade $userFacade
30
    )
31
    {
32
        parent::__construct();
33

    
34
        $this->userGridFactory = $userGridFactory;
35
        $this->userEditFormFactory = $userEditFormFactory;
36
        $this->userFacade = $userFacade;
37
    }
38

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

    
45
    public function handleDeleteUser(int $id)
46
    {
47
        if ($this->isAjax())
48
        {
49
            $this->userFacade->deleteUser($id);
50
            $this['userGrid']->reload();
51
        }
52
    }
53

    
54
    /**
55
     * Akce pro odstranění uživatele
56
     *
57
     * @param int $id
58
     * @throws \Nette\Application\AbortException
59
     */
60
    public function actionDeleteUser(int $id)
61
    {
62
        if($this->userFacade->deleteUser($id))
63
        {
64
            $this->flashMessage('User was deleted.', EFlashMessage::SUCCESS);
65
        }
66
        else
67
        {
68
            $this->flashMessage('User was not found.', EFlashMessage::ERROR);
69
        }
70
        $this->redirect('User:');
71
    }
72

    
73
    public function createComponentUserGrid()
74
    {
75
        return $this->userGridFactory->create();
76
    }
77

    
78
    public function createComponentUserEditForm()
79
    {
80
        return $this->userEditFormFactory->create();
81
    }
82
}
(12-12/12)