Created
November 21, 2013 16:45
-
-
Save pohy/7585242 to your computer and use it in GitHub Desktop.
Nette example application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Nette\Application\UI\Form; | |
class TaskPresenter extends BasePresenter | |
{ | |
private $listRepository; | |
private $userRepository; | |
private $taskRepository; | |
private $list; | |
protected function startup() | |
{ | |
parent::startup(); | |
if (!$this->getUser()->isLoggedIn()) { | |
$this->redirect('Sign:in'); | |
} | |
$this->listRepository = $this->context->listRepository; | |
$this->userRepository = $this->context->userRepository; | |
$this->taskRepository = $this->context->taskRepository; | |
} | |
public function actionDefault($id) | |
{ | |
$this->list = $this->listRepository->find($id); | |
if($this->list === FALSE) | |
$this->setView('notFound'); | |
} | |
public function renderDefault() | |
{ | |
$this->template->list = $this->list; | |
} | |
protected function createComponentTaskForm($name) | |
{ | |
$userPairs = $this->userRepository->findAll()->fetchPairs('id', 'name'); | |
$form = new Form($this, $name); | |
$form->addText('text', 'Úkol:', 40, 100)->addRule(Form::FILLED, 'Je nutné zadat text úkolu.'); | |
$form->addSelect('userId', 'Pro:', $userPairs)->setPrompt('- Vyberte -')->addRule(Form::FILLED, 'Je nutné vybrat, komu je úkol přirazen.'); | |
$form->addSubmit('create', 'Vytvořit'); | |
$form->onSuccess[] = $this->taskFormSubmitted; | |
} | |
public function taskFormSubmitted(Form $form) | |
{ | |
$this->taskRepository->createTask($this->list->id, $form->values->text, $form->values->userId); | |
$this->flashMessage('Úkol přidán.', 'success'); | |
$this->redirect('this'); | |
} | |
protected function createComponentTaskList() | |
{ | |
if($this->list === NULL) | |
$this->error('Wrong action'); | |
return new Todo\TaskListControl($this->listRepository->taskOf($this->list), $this->taskRepository); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment