<commit_before><?php

namespace App\Presenters;

use App\Components\ColumnChart;
use App\Components\GistRenderer;
use App\Components\Search;
use App\DeprecatedException;
use App\InvalidArgumentException;
use App\Model\EventList;
use App\Rme\BadgeUserBridge;
use App\Rme\RepositoryContainer;
use App\Rme\User;
use App\Services\Translator;
use Kdyby\Events\EventArgsList;
use Kdyby\Events\EventManager;
use Kdyby\Events\Subscriber;
use Monolog\Logger;
use Nette;
use Nette\Http\Session;


/**
 * @property-read RepositoryContainer $orm
 * @property-read Translator $translator
 * @property-read Logger $log
 * @property-read Nette\Templating\FileTemplate $template
 * @property-read User $userEntity
 */
abstract class BasePresenter extends Nette\Application\UI\Presenter implements Subscriber
{

	const FLASH_ERROR = 'danger';
	const FLASH_INFO = 'info';
	const FLASH_SUCCESS = 'success';

	public function startup()
	{
		parent::startup();
		$this->translator->setLanguage('cs');
		$this->getEventManager()->addEventSubscriber($this);
	}

	public function getSubscribedEvents()
	{
		return [EventList::BADGE_AWARDED];
	}

	public function onBadgeAwarded(BadgeUserBridge $bridge)
	{
		$this->flashSuccess('badges.awarded', [
			'badge' => $bridge->title
		]);
	}

	/**
	 * @return RepositoryContainer
	 */
	public function getOrm()
	{
		return $this->context->getService('orm');
	}

	/**
	 * @return Translator
	 */
	public function getTranslator()
	{
		return $this->context->getByType('App\Services\Translator');
	}

	/**
	 * @return EventManager
	 */
	private function getEventManager()
	{
		return $this->context->getByType('Kdyby\Events\EventManager');
	}

	/**
	 * Does not flush automatically!
	 * @param $event
	 * @param array $args
	 */
	protected function trigger($event, array $args = [])
	{
		$this->getEventManager()->dispatchEvent($event, new EventArgsList($args));
	}

	/**
	 * @return Logger
	 */
	public function getLog()
	{
		return $this->context->getService('log');
	}

	/**
	 * @return User
	 */
	public function getUserEntity()
	{
		$userEntity = $this->orm->users->getById($this->user->id);
		if ($this->user->loggedIn && !$userEntity)
		{
			$this->user->logout(TRUE);
		}

		return $userEntity;
	}

	public function beforeRender()
	{
		parent::beforeRender();
		$this->template->setTranslator($this->translator);
		$this->template->userEntity = $this->userEntity;
	}
<commit_msg>add href link directly by entity<commit_after><?php

namespace App\Presenters;

use App\Components\ColumnChart;
use App\Components\GistRenderer;
use App\Components\Search;
use App\DeprecatedException;
use App\InvalidArgumentException;
use App\Model\EventList;
use App\Orm\ContentEntity;
use App\Rme\BadgeUserBridge;
use App\Rme\Blueprint;
use App\Rme\RepositoryContainer;
use App\Rme\User;
use App\Services\Translator;
use Kdyby\Events\EventArgsList;
use Kdyby\Events\EventManager;
use Kdyby\Events\Subscriber;
use Monolog\Logger;
use Nette;
use Nette\Application\UI\destination;
use Nette\Application\UI\InvalidLinkException;
use Nette\Application\UI\Presenter;
use Nette\Http\Session;
use Nette\Templating\FileTemplate;


/**
 * @property-read RepositoryContainer $orm
 * @property-read Translator $translator
 * @property-read Logger $log
 * @property-read Nette\Templating\FileTemplate $template
 * @property-read User $userEntity
 */
abstract class BasePresenter extends Nette\Application\UI\Presenter implements Subscriber
{

	const FLASH_ERROR = 'danger';
	const FLASH_INFO = 'info';
	const FLASH_SUCCESS = 'success';

	public function startup()
	{
		parent::startup();
		$this->translator->setLanguage('cs');
		$this->getEventManager()->addEventSubscriber($this);
	}

	public function getSubscribedEvents()
	{
		return [EventList::BADGE_AWARDED];
	}

	public function onBadgeAwarded(BadgeUserBridge $bridge)
	{
		$this->flashSuccess('badges.awarded', [
			'badge' => $bridge->title
		]);
	}

	/**
	 * @return RepositoryContainer
	 */
	public function getOrm()
	{
		return $this->context->getService('orm');
	}

	/**
	 * @return Translator
	 */
	public function getTranslator()
	{
		return $this->context->getByType('App\Services\Translator');
	}

	/**
	 * @return EventManager
	 */
	private function getEventManager()
	{
		return $this->context->getByType('Kdyby\Events\EventManager');
	}

	/**
	 * Does not flush automatically!
	 * @param $event
	 * @param array $args
	 */
	protected function trigger($event, array $args = [])
	{
		$this->getEventManager()->dispatchEvent($event, new EventArgsList($args));
	}

	/**
	 * @return Logger
	 */
	public function getLog()
	{
		return $this->context->getService('log');
	}

	/**
	 * @return User
	 */
	public function getUserEntity()
	{
		$userEntity = $this->orm->users->getById($this->user->id);
		if ($this->user->loggedIn && !$userEntity)
		{
			$this->user->logout(TRUE);
		}

		return $userEntity;
	}

	public function link($destination, $args = [])
	{
		if ($destination instanceof ContentEntity)
		{
			$presenter = $type = $destination->getShortEntityName();
			$param = lcFirst($type) . 'Id';
			return parent::link("$presenter:", [$param => $destination->id]);
		}
		return parent::link($destination, $args);
	}

	public function beforeRender()
	{
		parent::beforeRender();
		$this->template->setTranslator($this->translator);
		$this->template->userEntity = $this->userEntity;
	}

{'fraction_non_alphanumeric': 0.15086932136848008, 'fraction_numerical': 0.0, 'mean_word_length': 4.625657202944269, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2991944', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1744, 'n_words': 336}