@@ 8-43 (lines=36) @@ | ||
5 | use Albert221\Blog\Repository\CategoryRepositoryInterface; |
|
6 | use Twig_Environment; |
|
7 | ||
8 | class RecentCategories implements WidgetInterface |
|
9 | { |
|
10 | /** |
|
11 | * @var CategoryRepositoryInterface |
|
12 | */ |
|
13 | private $categories; |
|
14 | ||
15 | /** |
|
16 | * @var Twig_Environment |
|
17 | */ |
|
18 | private $twig; |
|
19 | ||
20 | /** |
|
21 | * @var int |
|
22 | */ |
|
23 | private $count; |
|
24 | ||
25 | public function __construct(CategoryRepositoryInterface $categories, Twig_Environment $twig, $count) |
|
26 | { |
|
27 | $this->categories = $categories; |
|
28 | $this->twig = $twig; |
|
29 | $this->count = $count; |
|
30 | } |
|
31 | ||
32 | public function getName() |
|
33 | { |
|
34 | return 'Ostatnie kategorie'; |
|
35 | } |
|
36 | ||
37 | public function getHTML() |
|
38 | { |
|
39 | $categories = $this->categories->last($this->count); |
|
40 | ||
41 | return $this->twig->render('widgets/recent_categories.twig', compact('categories')); |
|
42 | } |
|
43 | } |
|
44 |
@@ 9-47 (lines=39) @@ | ||
6 | use Doctrine\Common\Collections\Criteria; |
|
7 | use Twig_Environment; |
|
8 | ||
9 | class RecentPosts implements WidgetInterface |
|
10 | { |
|
11 | /** |
|
12 | * @var PostRepositoryInterface |
|
13 | */ |
|
14 | private $posts; |
|
15 | ||
16 | /** |
|
17 | * @var Twig_Environment |
|
18 | */ |
|
19 | private $twig; |
|
20 | ||
21 | /** |
|
22 | * @var int |
|
23 | */ |
|
24 | private $count; |
|
25 | ||
26 | public function __construct(PostRepositoryInterface $posts, Twig_Environment $twig, $count) |
|
27 | { |
|
28 | $this->posts = $posts; |
|
29 | $this->twig = $twig; |
|
30 | $this->count = $count; |
|
31 | } |
|
32 | ||
33 | public function getName() |
|
34 | { |
|
35 | return 'Ostatnie posty'; |
|
36 | } |
|
37 | ||
38 | public function getHTML() |
|
39 | { |
|
40 | $criteria = Criteria::create() |
|
41 | ->setMaxResults($this->count); |
|
42 | ||
43 | $posts = $this->posts->paginated($criteria); |
|
44 | ||
45 | return $this->twig->render('widgets/recent_posts.twig', compact('posts')); |
|
46 | } |
|
47 | } |
|
48 |