ACC SHELL
<?php
namespace App\Presenters;
use Nette,
App\Model,
\Authorizator;
/**
* Base presenter for all application presenters.
*/
abstract class BugsBasePresenter extends Nette\Application\UI\Presenter
{
const LANG_COLUMN = 'lang';
const UPLOAD_FOLDER = 'upload';
const DELETED_COLUMN = 'deleted';
/** @persistent */
public $lang;
protected $db;
/* ***** EDIT HERE - BEGIN */
private $languages = array('cs', 'en');
private $locale = array('cs' => 'cs_CZ', 'en' => 'en_US');
private $dateFormat = array('cs' => '%e. %B %Y', 'en' => '%B %e, %Y');
/* ***** EDIT HERE - END */
public function __construct(\Nette\DI\Container $context = NULL)
{
parent::__construct($context);
$this->db = $context->database->context;
}
/* translator */
protected function translate($msg)
{
return $this->translator->translate($msg);
}
protected function startup()
{
parent::startup();
if (!isset($this->lang))
{
$this->lang = $this->getHttpRequest()->detectLanguage($this->languages);
}
// list of files to be used in tinyMCE (see @layout.latte)
$basePath = $this->template->basePath;
$files = $this->db->table(Authorizator::FILES_TABLE)->where(array(
self::DELETED_COLUMN => FALSE
))->fetchAll();
usort($files, array($this, 'sortFilesByName'));
$economy = $this->db->table(Authorizator::ECONOMY_TABLE)->where(array(
self::DELETED_COLUMN => FALSE
))->fetchAll();
usort($economy, array($this, 'sortFilesByName'));
$filesJSON = array_map(function($file) use($basePath) {
$obj = array();
$obj['title'] = $file->name;
$obj['value'] = $basePath . "/files/get/" . $file->id;
return $obj;
}, $files);
$economyJSON = array_map(function($file) use($basePath) {
$obj = array();
$obj['title'] = $file->name;
$obj['value'] = $basePath . "/economy/get/" . $file->id;
return $obj;
}, $economy);
$this->template->filesList = json_encode(array_merge($filesJSON, $economyJSON)) ?: array();
setlocale(LC_ALL, ($this->locale[$this->lang] . '.UTF-8'));
$this->template->dateFormat = $this->dateFormat[$this->lang];
$this->template->lang = $this->lang;
$this->template->langs = $this->languages;
$this->template->presenter = $this->getName();
$this->template->setTranslator($this->context->translator->setLang($this->lang));
}
protected function redirectHere($action = '', $id = NULL)
{
if ($id == NULL)
{
$this->redirect($this->getName() . ':' . $action);
}
else
{
$this->redirect($this->getName() . ':' . $action, $id);
}
}
protected function redirectHome()
{
$this->redirect('Homepage:');
}
protected function redirectToLogin($presenter = NULL)
{
$this->redirect('Sign:in?redirectTo=' . $presenter);
}
public function cancel(\Nette\Forms\Controls\SubmitButton $button)
{
$this->redirectHere();
}
protected function sortFilesByName($a, $b)
{
return strcmp($a->name, $b->name);
}
protected function sortFilesByUploadedDate($a, $b)
{
return $a->uploaded > $b->uploaded;
}
}
ACC SHELL 2018