<?php

namespace App\Presenters;

use Nette;
use App\Model;


/**
 * Base presenter for all application presenters.
 */
abstract class SecureBasePresenter extends BasePresenter
{
	
	public function startup()
	{
		parent::startup();
		
		if(!$this->user->isLoggedIn())
		{	
			$this->flashMessage('Enter your key first!');
			$this->redirect('Homepage:');
		}
		
	}
	
	/**
	 * @inject
	 * @var \App\Model\GameManager
	 */
	public $GameM;
	
	public function beforeRender()
	{
		$start_time = '';
		$stop_time = '';
		
		if( !$this->isClass('third') ) {
		
		$row = $this->GameM->getStartTime($this->user->id);
		
		$start_time = isset($row->START_TIME) ? /*$row->START_TIME*/strtotime($row->START_TIME) * 1000 : '';
		
		$row = $this->GameM->getStopTime($this->user->id);
		$stop_time = isset($row->START_TIME) ? /*$row->START_TIME*/strtotime($row->START_TIME) * 1000 : '';
		}
		
		
		$this->template->start_time = $start_time;
		$this->template->stop_time = $stop_time;

        $allgames = $this->GameM->getNumberOfGames();
        $wingames = $this->GameM->getNumberOfWinGames();
        $lostgames = ($allgames-$wingames);

        $this->template->lostgames = $lostgames;
        $this->template->allgames = $allgames;
        $this->template->wingames = $wingames;
		$this->getMenu();
	}
	
	function isClass($class) {
		
		return strpos( strtolower( get_class($this->presenter) ), strtolower( $class) ) !== false;
		
	}
	
	
	
}
