<commit_before><?php

namespace App\Presenters;

use App\Model\SongbookManager;
use App\Model\SongbookItem;
use App\Model\SongManager;
use Nette;
use App\Forms;




class SongbookPresenter extends BasePresenter
{
	/** @var Forms\SongbookFormFactory @inject */
	public $songbookFactory;

	public function beforeRender() {
		parent::beforeRender();

		if (!$this->getUser()->loggedIn) {
			$this->redirect('Sign:in');
		}
	}

	/**
	 * Render songbook detail
	 */
	public function renderDetail($id)
	{
		$songbookItem = new SongbookItem($this->database);
		$songbookItem->getSongbook($id);

		$ids = $songbookItem->getSongsIDFromSongbook($id);

		$songsManager = new SongManager($this->database);

		$this->template->title = $songbookItem->title;
		$this->template->id = $songbookItem->id;
		$this->template->songs = $songsManager->getSongsById($ids);
	}

	/**
	 * Render songbook with uncategorized songs
	 *
	 */
	public function renderOthers($user)
	{
		$songManager = new SongManager($this->database);
		$this->template->songs = $songManager->getOthersSongs($user);
		$this->template->title = 'Ostatní';

		$this->setView('detail');

	}

	/**
	 * Songbook form factory.
	 * @return Nette\Application\UI\Form
	 */
	protected function createComponentSongbookForm()
	{
		$user = $this->getUser()->id;

		return $this->songbookFactory->create(function ($guid) {
			$this->redirect('Songbook:detail', $guid);
		}, $user);
	}

}<commit_msg>Songbook: add sign in redirect<commit_after><?php

namespace App\Presenters;

use App\Model\SongbookManager;
use App\Model\SongbookItem;
use App\Model\SongManager;
use Nette;
use App\Forms;




class SongbookPresenter extends BasePresenter
{
	/** @var Forms\SongbookFormFactory @inject */
	public $songbookFactory;

	/**
	 * Render songbook add page
	 */
	public function renderAdd()
	{
		if (!$this->user->isLoggedIn()) {
			$this->flashMessage('Nejdřív se musíš přihlásit.');
			$this->redirect('Sign:in', ['backlink' => $this->storeRequest()]);
		}
	}

	/**
	 * Render songbook edit page
	 */
	public function renderEdit($id)
	{
		if (!$this->user->isLoggedIn()) {
			$this->flashMessage('Nejdřív se musíš přihlásit.');
			$this->redirect('Sign:in', ['backlink' => $this->storeRequest()]);
		}

		$songbook = new SongbookItem($this->database);
		$songbook->getSongbook($id);

		if ($songbook->user->id !== $this->user->id) {
			$this->flashMessage('Píseň může editovat pouze vlastník');
			$this->redirect('Song:detail', $id);
		}
	}

	/**
	 * Render songbook detail
	 */
	public function renderDetail($id)
	{
		$songbookItem = new SongbookItem($this->database);
		$songbookItem->getSongbook($id);

		$ids = $songbookItem->getSongsIDFromSongbook($id);

		$songsManager = new SongManager($this->database);

		$this->template->title = $songbookItem->title;
		$this->template->id = $songbookItem->id;
		$this->template->songs = $songsManager->getSongsById($ids);
	}

	/**
	 * Render songbook with uncategorized songs
	 *
	 */
	public function renderOthers($user)
	{
		$songManager = new SongManager($this->database);
		$this->template->songs = $songManager->getOthersSongs($user);
		$this->template->title = 'Ostatní';
		$this->template->id = false;

		$this->setView('detail');

	}

	/**
	 * Songbook form factory.
	 * @return Nette\Application\UI\Form
	 */
	protected function createComponentSongbookForm()
	{
		$user = $this->getUser()->id;

		return $this->songbookFactory->create(function ($guid) {
			$this->redirect('Songbook:detail', $guid);
		}, $user);
	}

}
{'fraction_non_alphanumeric': 0.17470739366257493, 'fraction_numerical': 0.0, 'mean_word_length': 4.44945567651633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 78, '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': '3381371', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1179, 'n_words': 209}