HosipLan

Untitled

Jun 13th, 2011
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2. use Nette\Environment,
  3.     Nette\Forms\Form;
  4.        
  5.    
  6.    
  7. final class TodolistPresenter extends BasePresenter
  8. {
  9.     private $model;
  10.  
  11.  
  12.  
  13.     public function __construct()
  14.     {
  15.         parent::__construct();
  16.  
  17.         $this->model = new TodoManager();
  18.     }
  19.  
  20.  
  21.    
  22.     public function actionShow($showDoneTasks)    
  23.     {
  24.       $done =  $showDoneTasks == TRUE ? 'yes' : 'no';
  25.       $this->template->showDone = $showDoneTasks;
  26.       $this->template->todos = $this->model->findAllTodos(null, array( "done" => $done));
  27.     }
  28.  
  29.  
  30.  
  31.     public function renderShow()
  32.     {
  33.         //$this->template->showDone = true;
  34.         //$this->template->todos = $this->model->findAllTodos();
  35.        
  36.     }
  37.  
  38.  
  39.  
  40.     public function actionAdd()
  41.     {
  42.      
  43.     }
  44.  
  45.  
  46.  
  47.     public function renderAdd()
  48.     {
  49.      
  50.     }
  51.  
  52.  
  53.     public function handleDelete($id)
  54.     {      
  55.         if ($todo = $this->model->findTodo($id)) {
  56.             try{
  57.                 $todo->delete();
  58.                 $this->flashMessage('Úkol smazán.');
  59.             }catch(Exception $e ){ }
  60.         }
  61.         $this->redirect('this');
  62.     }
  63.    
  64.  
  65.  
  66.     public function handleChangeState($id)
  67.     {
  68.         $this->flashMessage('Stav byl změněn.');
  69.         if($todo = $this->model->findTodo($id)) {
  70.             $todo->changeState();
  71.         }
  72.         $this->redirect('this', $todo->done === 'yes' ? TRUE : FALSE);
  73.     }
  74.  
  75.  
  76.        
  77.     public function createComponentTodoForm()
  78.     {
  79.         $form = new Form;
  80.         $form->addText('text', 'Úkol', 60, 100)
  81.             ->addRule(Form::FILLED, 'Musíte vyplnit text!');
  82.  
  83.         $form->addSubmit('save', 'Uložit')
  84.             ->onClick[] = callback($this, 'TodoFormSaveClicked');
  85.         $form->addSubmit('back', 'Zpět')->setValidationScope(NULL);
  86.  
  87.         return $form;
  88.     }
  89.  
  90.  
  91.  
  92.     public function TodoFormSaveClicked(Form $form)
  93.     {
  94.         $values = $form->getValues();
  95.         $todo = new Todo;
  96.         $todo->text = $values['text'];
  97.         $todo->added = new DateTime;
  98.         $this->model->createTodo($todo);
  99.        
  100.         $this->flashMessage('Úkol vložen.');
  101.         $this->redirect('TodoList:show');
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment