-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dreiser
committed
Mar 6, 2016
0 parents
commit c71bf50
Showing
86 changed files
with
5,326 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
app/config/config.local.neon | ||
.idea/ | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
app/components/ArticlesPreview/IArticlesPreviewFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.