Passed
Push — 0.x ( fc5333...ca02fa )
by Pavel
03:09
created

VacancyController::listByCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[email protected]>.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\AnthillBundle\Controller;
17
18
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
19
use Symfony\Component\HttpFoundation\Response;
20
use Symfony\Component\Templating\EngineInterface;
21
use Veslo\AnthillBundle\Entity\Vacancy;
22
use Veslo\AnthillBundle\Entity\Vacancy\Category;
23
use Veslo\AnthillBundle\Enum\Route;
24
use Veslo\AnthillBundle\Vacancy\Provider\Journal;
25
26
/**
27
 * Vacancy controller.
28
 */
29
class VacancyController
30
{
31
    /**
32
     * Template engine
33
     *
34
     * @var EngineInterface
35
     */
36
    private $templateEngine;
37
38
    /**
39
     * Provides vacancies by a simple abstract concept of journal with pages, using pagination internally
40
     *
41
     * @var Journal
42
     */
43
    private $vacancyJournal;
44
45
    /**
46
     * VacancyController constructor.
47
     *
48
     * @param EngineInterface $templateEngine Template engine
49
     * @param Journal         $vacancyJournal Provides vacancies by a simple abstract concept of journal with pages
50
     */
51
    public function __construct(EngineInterface $templateEngine, Journal $vacancyJournal)
52
    {
53
        $this->templateEngine = $templateEngine;
54
        $this->vacancyJournal = $vacancyJournal;
55
    }
56
57
    /**
58
     * Renders a list of vacancies
59
     *
60
     * @param int $page Page in vacancy journal
61
     *
62
     * @return Response
63
     */
64
    public function list(int $page): Response
65
    {
66
        $pagination = $this->vacancyJournal->read($page);
67
68
        $content = $this->templateEngine->render(
69
            '@VesloAnthill/Vacancy/list.html.twig',
70
            [
71
                'pagination'         => $pagination,
72
                'route_vacancy_show' => Route::VACANCY_SHOW,
73
            ]
74
        );
75
76
        $response = new Response($content);
77
78
        return $response;
79
    }
80
81
    /**
82
     * Renders a list of vacancies for a target category
83
     *
84
     * @param Category $category Vacancy category
85
     * @param int      $page     Page in vacancy journal
86
     *
87
     * @return Response
88
     *
89
     * @ParamConverter(name="category", converter="doctrine.orm", options={"mapping"={"categoryName": "name"}})
90
     */
91
    public function listByCategory(Category $category, int $page): Response
92
    {
93
        $pagination = $this->vacancyJournal->readCategory($category, $page);
94
95
        $content = $this->templateEngine->render(
96
            '@VesloAnthill/Vacancy/list.html.twig',
97
            [
98
                'pagination'         => $pagination,
99
                'route_vacancy_show' => Route::VACANCY_SHOW,
100
            ]
101
        );
102
103
        $response = new Response($content);
104
105
        return $response;
106
    }
107
108
    /**
109
     * Renders a vacancy show page
110
     *
111
     * @param Vacancy $vacancy Vacancy entity
112
     *
113
     * @return Response
114
     *
115
     * @ParamConverter(name="vacancy", converter="doctrine.orm", options={"mapping"={"vacancySlug": "slug"}})
116
     */
117
    public function show(Vacancy $vacancy): Response
118
    {
119
        $content  = $this->templateEngine->render('@VesloAnthill/Vacancy/show.html.twig', ['vacancy' => $vacancy]);
120
        $response = new Response($content);
121
122
        return $response;
123
    }
124
}
125