<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace FrontModule;
use \Nette\Application\UI\Form;
use \Nette\Utils\Image;

 
class VystavyPresenter extends BasePresenter {
    
    private $vystavyModel;
   
    
    //public $rokyk;
   
   /** @persistent */
    public $rok;
 
    public function __construct(\VystavyModel $vystavyModel) {
    $this->vystavyModel = $vystavyModel;
    }
    
    public function beforeRender() {
        $this->template->title = 'Výsledky výstav';
        $this->template->description = "Výsledky výstav chovných jedinců plemene velššpringršpaněl.";
    }
   
    
    public function renderList() {
      
        if ($this->rok == null) { $this->rok=date('Y'); } // aktualni rok
     
        $this->template->vystavy = $this->vystavyModel->getVystavyByYear($this->rok); 
        
        
 }
  protected function createComponentVybratRokForm() {
    $form = new form();
    $roky = $this->vystavyModel->getRoky();
    $rokyAsoc;
    foreach ($roky as $r) {
      $rokyAsoc[$r->rok] = $r->rok;  
    }
    //$roky = array('2016' => '2016', '2015' => '2015');
    $form->addSelect("rok", "Rok:", $rokyAsoc)
    ->setPrompt('Zvolte rok');
    $form->addSubmit("send", "Zvolit rok");
    $form->onSuccess[] = $this->vybratRokFormSucceeded;
    return $form;
}
 
 public function vybratRokFormSucceeded(Form $form) {
    $valu = $form->getValues();
    $this->rok = $valu->rok;
    //$this->rok = 2016;
    
    $this->redirect("Vystavy:list");// renderList();
    //$this->novinkyModel->getNovinkyByYear($values->rok);
}
  
    public function renderDetailVystavy($id) {
        $this->template->vystava = $this->vystavyModel->getVystava($id);
        $this->template->tridy = $this->vystavyModel->getTridyByVystavaId($id);
        $this->template->psi = $this->vystavyModel->getPsy();;
    }
    
 
    
}
