|
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; |
|
17
|
|
|
|
|
18
|
|
|
use Veslo\AnthillBundle\Dto\Vacancy\Parser\ParsedDto; |
|
19
|
|
|
use Veslo\AnthillBundle\Entity\Repository\VacancyRepository; |
|
20
|
|
|
use Veslo\AnthillBundle\Entity\Vacancy; |
|
21
|
|
|
use Veslo\AnthillBundle\Entity\Vacancy\Category; |
|
22
|
|
|
use Veslo\AnthillBundle\Vacancy\Category\Resolver as CategoryResolver; |
|
23
|
|
|
use Veslo\AnthillBundle\Vacancy\Resolver as VacancyResolver; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Adds a vacancy to the specified category |
|
27
|
|
|
*/ |
|
28
|
|
|
class CategoryAssigner |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Extracts a vacancy instance from the specified context |
|
32
|
|
|
* |
|
33
|
|
|
* @var VacancyResolver |
|
34
|
|
|
*/ |
|
35
|
|
|
private $vacancyResolver; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Extracts a category instance from the specified context |
|
39
|
|
|
* |
|
40
|
|
|
* @var CategoryResolver |
|
41
|
|
|
*/ |
|
42
|
|
|
private $categoryResolver; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Vacancy repository |
|
46
|
|
|
* |
|
47
|
|
|
* @var VacancyRepository |
|
48
|
|
|
*/ |
|
49
|
|
|
private $vacancyRepository; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* CategoryAssigner constructor. |
|
53
|
|
|
* |
|
54
|
|
|
* @param VacancyResolver $vacancyResolver Extracts a vacancy instance from the specified context |
|
55
|
|
|
* @param CategoryResolver $categoryResolver Extracts a category instance from the specified context |
|
56
|
|
|
* @param VacancyRepository $vacancyRepository Vacancy repository |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct( |
|
59
|
|
|
VacancyResolver $vacancyResolver, |
|
60
|
|
|
CategoryResolver $categoryResolver, |
|
61
|
|
|
VacancyRepository $vacancyRepository |
|
62
|
|
|
) { |
|
63
|
|
|
$this->vacancyResolver = $vacancyResolver; |
|
64
|
|
|
$this->categoryResolver = $categoryResolver; |
|
65
|
|
|
$this->vacancyRepository = $vacancyRepository; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Adds a vacancy to the specified category and saves a relation in the local storage |
|
70
|
|
|
* |
|
71
|
|
|
* @param Vacancy $vacancy Vacancy entity |
|
72
|
|
|
* @param Category $category Category entity |
|
73
|
|
|
* |
|
74
|
|
|
* @return void |
|
75
|
|
|
*/ |
|
76
|
|
|
public function assign(Vacancy $vacancy, Category $category): void |
|
77
|
|
|
{ |
|
78
|
|
|
$vacancy->addCategory($category); |
|
79
|
|
|
|
|
80
|
|
|
$this->vacancyRepository->save($vacancy); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Examines a parsed data from website and adds an additional category to the existent vacancy |
|
85
|
|
|
* |
|
86
|
|
|
* @param ParsedDto $scanResult Context of parsed vacancy data |
|
87
|
|
|
* |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
|
public function expandByParsedDto(ParsedDto $scanResult): void |
|
91
|
|
|
{ |
|
92
|
|
|
$vacancy = $this->vacancyResolver->resolveByParsedDto($scanResult); |
|
93
|
|
|
|
|
94
|
|
|
if (!$vacancy instanceof Vacancy) { |
|
95
|
|
|
return; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$location = $scanResult->getLocation(); |
|
99
|
|
|
$roadmap = $location->getRoadmap(); |
|
100
|
|
|
|
|
101
|
|
|
$category = $this->categoryResolver->resolveByRoadmap($roadmap); |
|
102
|
|
|
|
|
103
|
|
|
if (!$category instanceof Category) { |
|
104
|
|
|
return; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$this->assign($vacancy, $category); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|