<?php
abstract class BasePresenter extends Presenter
{
public $oldLayoutMode = FALSE;
public $oldModuleMode = FALSE;
/*
* @array $site
* pole systemovych promennych
*/
public static $site;
protected function beforeRender()
{
self::$site = BaseModel::getHeaders();
$this->template->site = self::$site;
$this->template->viewName = $this->view;
$a = strrpos($this->name, ':');
if ($a === FALSE) {
$this->template->moduleName = '';
$this->template->presenterName = $this->name;
} else {
$this->template->moduleName = substr($this->name, 0, $a + 1);
$this->template->presenterName = substr($this->name, $a + 1);
}
$this->template->baseMenu = BaseModel::baseMenu(substr($this->name, 0, $a));
$user = Environment::getUser();
}
/*
* Vytvareni hlavicek,
* pridavani sdilenych souboru
*/
protected function createComponentHeader() {
$header = new HeaderControl(HeaderControl::HTML_5, 'cs', self::$site->site_name);
$header->setTitleSeparator(' | ')
->setTitlesReverseOrder(true)
->addKeywords(self::$site->keywords)
->setDescription(self::$site->description)
->setRobots('index,follow');
$css = $header['css'];
$css->sourcePath = WWW_DIR . '/document_root/css';
$css->sourceUri = Environment::getVariable('baseUri') . 'document_root/temp';
$css->tempUri = $css->sourceUri;
$css->tempPath = WWW_DIR . '/document_root/temp';
$js = $header['js'];
$js->sourcePath = WWW_DIR . '/document_root/js';
$js->tempUri = Environment::getVariable('baseUri') . 'document_root/temp';
$js->tempPath = WWW_DIR . '/document_root/temp';
return $header;
}
protected function createComponentLoginForm($name)
{
$form = new BaseForm($this,$name);
$form->addText('email', 'E-mail:');
$form->addPassword('pass', 'Heslo:');
$form->addCheckbox('remember', 'Zapamatovat si');
$form->addSubmit('login', 'Přihlásit se');
$form->onSubmit[] = callback($this, 'loginFormSubmitted');
return $form;
}
public function loginFormSubmitted($form)
{
try {
$values = $form->values;
if ($values['remember']) {
$this->getUser()->setExpiration('+ 14 days', FALSE);
} else {
$this->getUser()->setExpiration('+ 20 minutes', TRUE);
}
$this->getUser()->login($values['email'], $values['pass']);
$this->redirect('this');
} catch (AuthenticationException $e) {
$form->addError($e->getMessage());
}
}
public function actionLogout()
{
Environment::getUser()->logout();
$this->flashMessage('Byli jste úspěšně odhlášeni');
$this->redirect('Front:Page:default');
}
}