Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Nette\Environment,
- Nette\Forms\Form;
- final class TodolistPresenter extends BasePresenter
- {
- private $model;
- public function __construct()
- {
- parent::__construct();
- $this->model = new TodoManager();
- }
- public function actionShow($showDoneTasks)
- {
- $done = $showDoneTasks == TRUE ? 'yes' : 'no';
- $this->template->showDone = $showDoneTasks;
- $this->template->todos = $this->model->findAllTodos(null, array( "done" => $done));
- }
- public function renderShow()
- {
- //$this->template->showDone = true;
- //$this->template->todos = $this->model->findAllTodos();
- }
- public function actionAdd()
- {
- }
- public function renderAdd()
- {
- }
- public function handleDelete($id)
- {
- if ($todo = $this->model->findTodo($id)) {
- try{
- $todo->delete();
- $this->flashMessage('Úkol smazán.');
- }catch(Exception $e ){ }
- }
- $this->redirect('this');
- }
- public function handleChangeState($id)
- {
- $this->flashMessage('Stav byl změněn.');
- if($todo = $this->model->findTodo($id)) {
- $todo->changeState();
- }
- $this->redirect('this', $todo->done === 'yes' ? TRUE : FALSE);
- }
- public function createComponentTodoForm()
- {
- $form = new Form;
- $form->addText('text', 'Úkol', 60, 100)
- ->addRule(Form::FILLED, 'Musíte vyplnit text!');
- $form->addSubmit('save', 'Uložit')
- ->onClick[] = callback($this, 'TodoFormSaveClicked');
- $form->addSubmit('back', 'Zpět')->setValidationScope(NULL);
- return $form;
- }
- public function TodoFormSaveClicked(Form $form)
- {
- $values = $form->getValues();
- $todo = new Todo;
- $todo->text = $values['text'];
- $todo->added = new DateTime;
- $this->model->createTodo($todo);
- $this->flashMessage('Úkol vložen.');
- $this->redirect('TodoList:show');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment