Skip to content

Commit

Permalink
used PostFacade
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 20, 2024
1 parent 6f79b01 commit 81f1387
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
25 changes: 25 additions & 0 deletions app/Model/PostFacade.php
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Model;

use Nette;


final class PostFacade
{
public function __construct(
private Nette\Database\Explorer $database,
) {
}


public function getPublicArticles()
{
return $this->database
->table('posts')
->where('created_at < ', new \DateTime)
->order('created_at DESC');
}
}
8 changes: 4 additions & 4 deletions app/UI/Home/HomePresenter.php
Expand Up @@ -4,22 +4,22 @@

namespace App\UI\Home;

use App\Model\PostFacade;
use Nette;


final class HomePresenter extends Nette\Application\UI\Presenter
{
public function __construct(
private Nette\Database\Explorer $database,
private PostFacade $facade,
) {
}


public function renderDefault(): void
{
$this->template->posts = $this->database
->table('posts')
->order('created_at DESC')
$this->template->posts = $this->facade
->getPublicArticles()
->limit(5);
}
}
3 changes: 2 additions & 1 deletion app/UI/Post/PostPresenter.php
Expand Up @@ -4,14 +4,15 @@

namespace App\UI\Post;

use App\Model\PostFacade;
use Nette;
use Nette\Application\UI\Form;


final class PostPresenter extends Nette\Application\UI\Presenter
{
public function __construct(
private Nette\Database\Explorer $database,
private PostFacade $facade,
) {
}

Expand Down

0 comments on commit 81f1387

Please sign in to comment.