Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\AdminModule\Presenters;
  4.  
  5. use App\Forms\UserFormFactory;
  6. use App\Model\Entities\User;
  7.  
  8.  
  9. /**
  10.  * @author  Daniel Martinec
  11.  * Class UserPresenter
  12.  * @package App\AdminModule\Presenters
  13.  */
  14. class UserPresenter extends BasePresenter
  15. {
  16.     /**
  17.      * @var UserFormFactory
  18.      * @inject
  19.      */
  20.     public $formFactory;
  21.  
  22.     /**
  23.      * @var User
  24.      */
  25.     private $searchedUser;
  26.  
  27.  
  28.     /**
  29.      * Ověření práv uživatele
  30.      *
  31.      * @throws \Nette\Application\AbortException
  32.      */
  33.     public function startup()
  34.     {
  35.         parent::startup();
  36.         if (!$this->userEntity->isSuperAdmin()) {
  37.             $this->redirect("Homepage:default");
  38.         }
  39.     }
  40.  
  41.  
  42.     /**
  43.      * Připraví data pro editaci uživatele
  44.      *
  45.      * @param $id
  46.      * @throws \Nette\Application\AbortException
  47.      */
  48.     public function actionEdit($id)
  49.     {
  50.         try {
  51.             $this->searchedUser = $user = $this->userFacade->getUser($id, TRUE);
  52.             $this["editUserForm"]->setDefaults(array(
  53.                 "userId" => $id,
  54.                 "name" => $user->name,
  55.                 "email" => $user->email,
  56.                 "role" => $user->role
  57.             ));
  58.         } catch (\App\Exceptions\UserDoesntExistException $e) {
  59.             $this->flashMessage($this->translator->translate("exception.userDoesntExist"), self::MSG_ERROR);
  60.             $this->redirect("userList");
  61.         }
  62.     }
  63.  
  64.  
  65.     /**
  66.      *  Výpis uživatelů
  67.      */
  68.     public function renderUserList()
  69.     {
  70.         $this->template->users = $this->userFacade->getUsersList();
  71.     }
  72.  
  73.  
  74.     /**
  75.      * Profil uživatele
  76.      *
  77.      * @param $id
  78.      */
  79.     public function renderProfile($id)
  80.     {
  81.         $this->template->searchedUser = $this->userFacade->getUser($id);
  82.     }
  83.  
  84.  
  85.     /**
  86.      * Editace uživatele
  87.      */
  88.     public function renderEdit()
  89.     {
  90.         $this->template->searchedUser = $this->searchedUser;
  91.     }
  92.  
  93.    
  94.     /**
  95.      * Formulář pro vytvoření uživatele
  96.      *
  97.      * @return \Nette\Application\UI\Form
  98.      */
  99.     public function createComponentAddUserForm()
  100.     {
  101.         $form = $this->formFactory->createAddUser();
  102.         $form->onSuccess[] = function () {
  103.             $this->flashMessage($this->translator->translate("user.userWasAdded"), self::MSG_SUCCESS);
  104.             $this->redirect("userList");
  105.         };
  106.         return $form;
  107.     }
  108.  
  109.  
  110.     /**
  111.      * Formulář pro editaci uživatele
  112.      *
  113.      * @return \Nette\Application\UI\Form
  114.      */
  115.     public function createComponentEditUserForm()
  116.     {
  117.         $form = $this->formFactory->createEditUser();
  118.         $form->onSuccess[] = function () {
  119.             $this->flashMessage($this->translator->translate("user.userWasEdited"), self::MSG_SUCCESS);
  120.             $this->redirect("userList");
  121.         };
  122.         return $form;
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement