Guest User

Untitled

a guest
Jul 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <?php
  2.  
  3. use Nette\Application\AppForm;
  4. use Nette\Application\Control;
  5. use Nette\Environment;
  6.  
  7. class Questions extends Control
  8. {
  9.  
  10. const YES = 'yes';
  11. const NO = 'no';
  12.  
  13. /** @var array */
  14. private $questions;
  15.  
  16. public function setQuestions(array $questions)
  17. {
  18. $this->questions = $questions;
  19. }
  20.  
  21. public function render()
  22. {
  23. $template = $this->getTemplate();
  24. $template->setFile(__DIR__ . '/questions.latte');
  25.  
  26. $template->questions = $this->questions;
  27. $template->answered = Environment::getSession('questions');
  28.  
  29. $template->render();
  30. }
  31.  
  32. public function handleAnswer($question, $response)
  33. {
  34. $storage = Environment::getSession('questions');
  35. $storage->$question = $response ? self::YES : self::NO;
  36.  
  37. $this->invalidateControl('questions');
  38. }
  39.  
  40. public function handleRefresh()
  41. {
  42. Environment::getSession('questions')->remove();
  43.  
  44. $this->invalidateControl('questions');
  45. }
  46.  
  47.  
  48. }
Add Comment
Please, Sign In to add comment