ACC SHELL

Path : /srv/www/vhosts/duklavysco/app/presenters/
File Upload :
Current File : //srv/www/vhosts/duklavysco/app/presenters/BasePresenter.php

<?php

/**
 * Base presenter for all application presenters.
 */
abstract class BasePresenter extends Nette\Application\UI\Presenter
{
    protected $db;
    protected $dnyVTydnu = array(
        1 => 'pondělí',
        2 => 'úterý',
        3 => 'středa',
        4 => 'čtvrtek',
        5 => 'pátek',
        6 => 'sobota',
        7 => 'neděle'
    );
    protected $dnyVTydnu2p = array(
        1 => 'pondělí',
        2 => 'úterý',
        3 => 'středu',
        4 => 'čtvrtek',
        5 => 'pátek',
        6 => 'sobotu',
        7 => 'neděli'
    );
    protected $typickaVlastnostProdleva = '3 day';
    
    public function __construct(\Nette\DI\Container $context = NULL)
    {
        parent::__construct($context);
        
        $this->db = $context->database->connection;
        
        function Form_addDatePicker(Nette\Application\UI\Form $_this, $name, $label, $cols = NULL, $maxLength = NULL)
        {
            return $_this[$name] = new DatePicker($label, $cols, $maxLength);
        }
        Nette\Application\UI\Form::extensionMethod('addDatePicker', 'Form_addDatePicker');
        function Form_addDateTimePicker(Nette\Application\UI\Form $_this, $name, $label, $cols = NULL, $maxLength = NULL)
        {
            return $_this[$name] = new DateTimePicker($label, $cols, $maxLength);
        }
        Nette\Application\UI\Form::extensionMethod('addDateTimePicker', 'Form_addDateTimePicker');
    }
    
    protected function startup() {
        parent::startup();
        $this->template->uzivatele = $this->db->table('uzivatele')->order('prijmeni, jmeno');
        $this->template->dnyVTydnu2p = $this->dnyVTydnu2p;
        $this->template->pristiZapas = $this->nextPlay();
        $this->template->casDoPristihoZapasu = $this->timeTillNextPlay($this->template->pristiZapas);
        $this->template->kdeHrajeme = $this->db->table('nastaveni')->fetch()->kdeHrajeme;
        $this->template->denVTydnu = $this->db->table('nastaveni')->fetch()->denVTydnu;
        $this->template->vKolikHrajeme = $this->db->table('nastaveni')->fetch()->cas;
        $this->template->hrajemeVubec = $this->db->table('nastaveni')->fetch()->hrajemeVubec;
        $this->template->pristiAkce = $this->db->table('akce')->where('datum >= (now() - INTERVAL 13 HOUR)')->order('datum')->fetch();
        $this->template->posledniZprava = $this->db->table('forum')->order('datum DESC')->fetch();
        
        $this->template->fotkyUzivatelu = array();
        foreach ($this->template->uzivatele as $uzivatel)
        {
            if (file_exists('images/hraci/' . $uzivatel->id . '.png'))
            {
                $this->template->fotkyUzivatelu[$uzivatel->id] = $uzivatel->id;
            }
            else
            {
                $this->template->fotkyUzivatelu[$uzivatel->id] = 'default-profile';
            }
        }
    }
    
    private function nextPlay()
    {
        $now = new DateTime();
        $future_date = new DateTime('2012-01-' . (1 + $this->db->table('nastaveni')->fetch()->denVTydnu) . ' ' . $this->db->table('nastaveni')->fetch()->cas->format('H:i'));
        
        while ($future_date < $now)
        {
            $future_date->add(DateInterval::createFromDateString('7 days'));
        }
        
        return $future_date;
    }
    
    private function timeTillNextPlay($future_date)
    {
        $now = new DateTime();

        $interval = $future_date->diff($now);
        
        return $interval->format("%d dny, %h hod, %i min");
    }
    
    protected function redirectToLogin($presenter = null, $parameters = null)
    {
        if ($presenter != null)
        {
            $url = '?presenter=' . strtolower($presenter);
            if ($parameters != null)
            {
                foreach ($parameters as $key => $param)
                {
                    $url .= '&' . $key . '=' . $param;
                }
            }
            $this->redirect('Prihlasit:se?url=' . urlencode($url));
        }
        else
        {
            $this->redirect('Prihlasit:se');
        }
    }
    
}

ACC SHELL 2018