Skip to content

Commit

Permalink
First template
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreiser committed Mar 6, 2016
0 parents commit c71bf50
Show file tree
Hide file tree
Showing 86 changed files with 5,326 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
app/config/config.local.neon
.idea/
vendor
21 changes: 21 additions & 0 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

$configurator = new Nette\Configurator;

//$configurator->setDebugMode('23.75.345.200'); // enable for your remote IP
$configurator->enableDebugger(__DIR__ . '/../log');

$configurator->setTempDirectory(__DIR__ . '/../temp');

$configurator->createRobotLoader()
->addDirectory(__DIR__)
->register();

$configurator->addConfig(__DIR__ . '/config/config.neon');
$configurator->addConfig(__DIR__ . '/config/config.local.neon');

$container = $configurator->createContainer();

return $container;
40 changes: 40 additions & 0 deletions app/components/ArticleForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Components;

use Nette\Application\UI\Control;
use Nette\Application\UI\Form;

/**
* Class ArticleForm
* @package App\Components
* @author Jakub Hadamčík <[email protected]>
*/
abstract class ArticleForm extends Control
{
/**
* @return Form
*/
protected function createComponentArticleForm()
{
$form = new Form();

$form->addText('title', 'Nadpis:')
->setRequired('Zadejte prosím nadpis článku.');

$form->addTextArea('text', 'Text:')
->setRequired('Zadejte prosím text článku.');

$form->addSubmit('save', 'Uložit');

$form->onSuccess[] = $this->processArticleForm;

return $form;
}

/**
* @param Form $form
* @return void
*/
public abstract function processArticleForm(Form $form);
}
5 changes: 5 additions & 0 deletions app/components/ArticlePreview/ArticlePreview.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<h3>{$article->getTitle()}</h3>
<small>Komentářů: {$article->getCommentsCount()}</small>
<p>{$article->getText()|truncate: 140}</p>
</div>
26 changes: 26 additions & 0 deletions app/components/ArticlePreview/ArticlePreview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Components\ArticlePreview;

use App\Model\Entity\Article;
use Nette\Application\UI\Control;
use Ulozenka\Components\FileTemplateTrait;

/**
* Class ArticlePreview
* @package App\Components\ArticlePreview
* @author Jakub Hadamčík <[email protected]>
*/
class ArticlePreview extends Control
{
use FileTemplateTrait;

/**
* @param Article $article
*/
public function render(Article $article)
{
$this->template->article = $article;
$this->template->render();
}
}
15 changes: 15 additions & 0 deletions app/components/ArticlePreview/IArticlePreviewFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Components\ArticlePreview;

/**
* Interface IArticlePreviewFactory
* @package App\Components\ArticlePreview
*/
interface IArticlePreviewFactory
{
/**
* @return ArticlePreview
*/
public function create();
}
10 changes: 10 additions & 0 deletions app/components/ArticlesPreview/ArticlesPreview.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{snippet articles}
{if count($articles) !== 0}
{control paginator, $paginator, $getPageLink}
{foreach $articles as $article}
<a href="{$article|getLink}">{control articlePreview, $article}</a>
{/foreach}
{else}
<p>Žádné nové články</p>
{/if}
{/snippet}
127 changes: 127 additions & 0 deletions app/components/ArticlesPreview/ArticlesPreview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace App\Components\ArticlesPreview;

use App\Components\ArticlePreview\ArticlePreview;
use App\Components\ArticlePreview\IArticlePreviewFactory;
use App\Components\Paginator\IPaginatorFactory;
use App\Model\Entity\Article;
use Kdyby\Doctrine\ResultSet;
use Nette\Application\UI\Control;
use Nette\Utils\Paginator;
use Ulozenka\Components\FileTemplateTrait;

/**
* Class ArticlesPreview
* @package App\Components\ArticlesPreview
* @author Jakub Hadamčík <[email protected]>
*/
class ArticlesPreview extends Control
{
use FileTemplateTrait;

/** @var ResultSet */
private $articles;

/** @var callable */
public $getDetailLink;

/** @var IArticlePreviewFactory */
private $articlePreviewFactory;

/** @var Paginator */
private $paginator;

/** @var IPaginatorFactory */
private $paginatorFactory;

/**
* NewArticles constructor.
* @param ResultSet $articles
* @param int $articlesPerPage
* @param IArticlePreviewFactory $articlePreviewFactory
* @param IPaginatorFactory $paginatorFactory
*/
public function __construct(ResultSet $articles, $articlesPerPage, IArticlePreviewFactory $articlePreviewFactory, IPaginatorFactory $paginatorFactory)
{
parent::__construct();
$this->articles = $articles;
$this->articlePreviewFactory = $articlePreviewFactory;
$this->paginator = new Paginator();
$this->paginator->setItemsPerPage($articlesPerPage);
$this->paginatorFactory = $paginatorFactory;
}

/**
* @param int $page
* @return string
*/
public function getPageLink($page)
{
return $this->link('changePage!', [
'page' => $page
]);
}

/**
* @param int $page
*/
public function handleChangePage($page = 1)
{
$this->paginator->setPage($page);
$this->template->articles = $this->articles->applyPaginator($this->paginator)->toArray();
$this->redrawControl('articles');
}

/**
* @return void
*/
public function render()
{
if(!isset($this->template->articles)) {
$this->paginator->setPage(1);
$this->template->articles = $this->articles->applyPaginator($this->paginator)->toArray();
}
$this->template->paginator = $this->paginator;
$this->template->getPageLink = $this->getPageLink;
$hasLink = !empty($this->getDetailLink);
$this->template->hasLink = $hasLink;
if($hasLink) {
$this->template->addFilter('getLink', function (Article $article) {
return $this->getDetailLink($article);
});
}
$this->template->render();
}

/**
* @param $presenter
* @throws \LogicException
*/
protected function attached($presenter)
{
parent::attached($presenter);
if(empty($this->getDetailLink)) {
throw new \LogicException('getDetailLink callback has to be set up.');
}
}


/**
* @return ArticlePreview
*/
protected function createComponentArticlePreview()
{
$articlePreview = $this->articlePreviewFactory->create();
return $articlePreview;
}

/**
* @return \App\Components\Paginator\Paginator
*/
protected function createComponentPaginator()
{
$paginator = $this->paginatorFactory->create();
return $paginator;
}
}
18 changes: 18 additions & 0 deletions app/components/ArticlesPreview/IArticlesPreviewFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Components\ArticlesPreview;
use Kdyby\Doctrine\ResultSet;

/**
* Interface IArticlesPreviewFactory
* @package App\Components\ArticlesPreview
*/
interface IArticlesPreviewFactory
{
/**
* @param ResultSet $articles
* @param int $articlesPerPage
* @return ArticlesPreview
*/
public function create(ResultSet $articles, $articlesPerPage);
}
13 changes: 13 additions & 0 deletions app/components/CommentDetail/CommentDetail.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div>
<h3>{$comment->getAuthor()->getSignature()}</h3>
<small>Přidáno: {$comment->getAdded()|date: 'j.n.Y v H:i'}</small>
<p>
{$comment->getText()}
</p>
{if !$comment->isPublished() && $canPublish && !$comment->isRemoved()}
<a href="{link publish!, 'commentId' => $comment->getId()}">Zveřejnit komentář</a>
{/if}
{if !$comment->isRemoved() && $canRemove}
<a href="{link remove!, 'commentId' => $comment->getId()}">Smazat komentář</a>
{/if}
</div>
Loading

0 comments on commit c71bf50

Please sign in to comment.