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\Vacancy\Category; |
17
|
|
|
|
18
|
|
|
use Veslo\AnthillBundle\Dto\Vacancy\ConfigurableRoadmapDto; |
19
|
|
|
use Veslo\AnthillBundle\Dto\Vacancy\RoadmapDto; |
20
|
|
|
use Veslo\AnthillBundle\Entity\Vacancy\Category; |
21
|
|
|
use Veslo\AppBundle\Entity\Repository\BaseEntityRepository; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Extracts a category instance from the specified context |
25
|
|
|
*/ |
26
|
|
|
class Resolver |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Creates and persists a new category for vacancies in local storage |
30
|
|
|
* |
31
|
|
|
* @var Creator |
32
|
|
|
*/ |
33
|
|
|
private $categoryCreator; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Vacancy category repository |
37
|
|
|
* |
38
|
|
|
* @var BaseEntityRepository |
39
|
|
|
*/ |
40
|
|
|
private $categoryRepository; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Resolver constructor. |
44
|
|
|
* |
45
|
|
|
* @param Creator $categoryCreator Creates and persists a new category for vacancies |
46
|
|
|
* @param BaseEntityRepository $categoryRepository Vacancy category repository |
47
|
|
|
*/ |
48
|
|
|
public function __construct(Creator $categoryCreator, BaseEntityRepository $categoryRepository) |
49
|
|
|
{ |
50
|
|
|
$this->categoryCreator = $categoryCreator; |
51
|
|
|
$this->categoryRepository = $categoryRepository; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns related category entity if exists or calls the category creator to build a new one by roadmap |
56
|
|
|
* |
57
|
|
|
* @param RoadmapDto $roadmap Context of roadmap by which the vacancy was found |
58
|
|
|
* |
59
|
|
|
* @return Category|null |
60
|
|
|
*/ |
61
|
|
|
public function resolveByRoadmap(RoadmapDto $roadmap): ?Category |
62
|
|
|
{ |
63
|
|
|
if (!$roadmap instanceof ConfigurableRoadmapDto) { |
64
|
|
|
return null; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$configuration = $roadmap->getConfiguration(); |
68
|
|
|
$categoryName = $configuration->getKey(); |
69
|
|
|
$category = $this->categoryRepository->findOneByName($categoryName); |
|
|
|
|
70
|
|
|
|
71
|
|
|
if (!$category instanceof Category) { |
72
|
|
|
$category = $this->categoryCreator->createByRoadmapConfigurationDto($configuration, true); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $category; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|