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\Company; |
17
|
|
|
|
18
|
|
|
use DateTime; |
19
|
|
|
use Veslo\AnthillBundle\Dto\Vacancy\RawDto; |
20
|
|
|
use Veslo\AnthillBundle\Entity\Company; |
21
|
|
|
use Veslo\AppBundle\Entity\Repository\BaseEntityRepository; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Creates and persists a new company in local storage |
25
|
|
|
*/ |
26
|
|
|
class Creator |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Company repository |
30
|
|
|
* |
31
|
|
|
* @var BaseEntityRepository |
32
|
|
|
*/ |
33
|
|
|
private $companyRepository; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Creator constructor. |
37
|
|
|
* |
38
|
|
|
* @param BaseEntityRepository $companyRepository Company repository |
39
|
|
|
*/ |
40
|
|
|
public function __construct(BaseEntityRepository $companyRepository) |
41
|
|
|
{ |
42
|
|
|
$this->companyRepository = $companyRepository; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Creates and returns a new company entity by specified vacancy data |
47
|
|
|
* |
48
|
|
|
* @param RawDto $vacancy Context of raw vacancy data from website |
49
|
|
|
* @param bool $isCascadeChild Whenever entity creation is a part of the entity-owner creation and entity manager |
50
|
|
|
* should not be instantly flushed (for transaction purposes) |
51
|
|
|
* |
52
|
|
|
* @return Company |
53
|
|
|
*/ |
54
|
|
|
public function createByVacancyRawDto(RawDto $vacancy, bool $isCascadeChild = false): Company |
55
|
|
|
{ |
56
|
|
|
$company = new Company(); |
57
|
|
|
|
58
|
|
|
$company->setName($vacancy->getCompanyName()); |
59
|
|
|
$company->setUrl($vacancy->getCompanyUrl()); |
60
|
|
|
$company->setLogoUrl($vacancy->getCompanyLogoUrl()); |
61
|
|
|
$company->setSynchronizationDate(new DateTime()); |
62
|
|
|
|
63
|
|
|
$this->companyRepository->save($company, !$isCascadeChild); |
64
|
|
|
|
65
|
|
|
return $company; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|