Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\AdminModule\Presenters;
- use App\Forms\UserFormFactory;
- use App\Model\Entities\User;
- /**
- * @author Daniel Martinec
- * Class UserPresenter
- * @package App\AdminModule\Presenters
- */
- class UserPresenter extends BasePresenter
- {
- /**
- * @var UserFormFactory
- * @inject
- */
- public $formFactory;
- /**
- * @var User
- */
- private $searchedUser;
- /**
- * Ověření práv uživatele
- *
- * @throws \Nette\Application\AbortException
- */
- public function startup()
- {
- parent::startup();
- if (!$this->userEntity->isSuperAdmin()) {
- $this->redirect("Homepage:default");
- }
- }
- /**
- * Připraví data pro editaci uživatele
- *
- * @param $id
- * @throws \Nette\Application\AbortException
- */
- public function actionEdit($id)
- {
- try {
- $this->searchedUser = $user = $this->userFacade->getUser($id, TRUE);
- $this["editUserForm"]->setDefaults(array(
- "userId" => $id,
- "name" => $user->name,
- "email" => $user->email,
- "role" => $user->role
- ));
- } catch (\App\Exceptions\UserDoesntExistException $e) {
- $this->flashMessage($this->translator->translate("exception.userDoesntExist"), self::MSG_ERROR);
- $this->redirect("userList");
- }
- }
- /**
- * Výpis uživatelů
- */
- public function renderUserList()
- {
- $this->template->users = $this->userFacade->getUsersList();
- }
- /**
- * Profil uživatele
- *
- * @param $id
- */
- public function renderProfile($id)
- {
- $this->template->searchedUser = $this->userFacade->getUser($id);
- }
- /**
- * Editace uživatele
- */
- public function renderEdit()
- {
- $this->template->searchedUser = $this->searchedUser;
- }
- /**
- * Formulář pro vytvoření uživatele
- *
- * @return \Nette\Application\UI\Form
- */
- public function createComponentAddUserForm()
- {
- $form = $this->formFactory->createAddUser();
- $form->onSuccess[] = function () {
- $this->flashMessage($this->translator->translate("user.userWasAdded"), self::MSG_SUCCESS);
- $this->redirect("userList");
- };
- return $form;
- }
- /**
- * Formulář pro editaci uživatele
- *
- * @return \Nette\Application\UI\Form
- */
- public function createComponentEditUserForm()
- {
- $form = $this->formFactory->createEditUser();
- $form->onSuccess[] = function () {
- $this->flashMessage($this->translator->translate("user.userWasEdited"), self::MSG_SUCCESS);
- $this->redirect("userList");
- };
- return $form;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement