<?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 AdminModule;
use \Nette\Application\UI\Form;
 
class BasePresenter extends \Nette\Application\UI\Presenter {
    protected $aktualizaceModel;
    
  
 
    public function inject(\AktualizaceModel $aktualizaceModel) {
    $this->aktualizaceModel = $aktualizaceModel;
   
    }
   
 
   public function beforeRender() {
    $this->setLayout('layoutAdmin');
    if (!$this->getUser()->isLoggedIn()) {
        $this->redirect(':Front:Sign:in');
    }
    $this->template->akt = $this->aktualizaceModel->getAktualizace();
}


public function handleLogOut() {
    $this->user->logout();
    $this->flashMessage('Byl jste odhlášen', 'info');
    $this->redirect(':Front:Homepage:default');
 
}

protected function createComponentEditAktualizaceForm() {
    $form = new Form();
    $akt = $this->aktualizaceModel->getAktualizace();
    $form->addText('text','Text aktualizace:')->setDefaultValue($akt->text);
    $form->addSubmit("send", "Uložit");
    $form->onSuccess[] = $this->editAktualizaceFormSucceeded;
    return $form;
}

public function editAktualizaceFormSucceeded(Form $form) {
    $values = $form->getValues();
    $values->id = 1;
    $values->datum = new \Nette\Utils\DateTime();
    $this->aktualizaceModel->updateAktualizace($values->id, $values);
    $this->flashMessage('Aktualizace byla editována', 'info');
    $this->redirect('this');
}

public function createComponentVisualPaginator(){
        $visualPaginator = new \VisualPaginator();
        return $visualPaginator;
    }


}


