-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobOfferManager.php
More file actions
91 lines (79 loc) · 2.63 KB
/
JobOfferManager.php
File metadata and controls
91 lines (79 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace App\Manager\Project;
use Doctrine\ORM\EntityManagerInterface;
use App\Utils\Slugger;
use App\Entity\Project\Project;
use App\Entity\Project\JobOffer;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use App\Exception\ValidationException;
use App\Entity\Skill;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use App\Entity\Project\Skill as JobSkill;
class JobOfferManager
{
/** @var EntityManagerInterface */
protected $em;
/** @var ValidatorInterface */
protected $validator;
/** @var Slugger */
protected $slugger;
public function __construct(EntityManagerInterface $em, ValidatorInterface $validator, Slugger $slugger)
{
$this->em = $em;
$this->validator = $validator;
$this->slugger = $slugger;
}
public function get(int $id): ?JobOffer
{
return $this->em->getRepository(JobOffer::class)->find($id);
}
public function getProjectJobOffers(Project $project): array
{
return $this->em->getRepository(JobOffer::class)->findByProject($project);
}
public function create(Project $project, array $data): JobOffer
{
$jobOffer =
(new JobOffer())
->setTitle($data['title'])
->setSlug($this->slugger->slugify($data['title']))
->setContent($data['content'])
->setProject($project)
;
if (count($errors = $this->validator->validate($jobOffer)) > 0) {
throw new ValidationException($errors);
}
$this->em->persist($jobOffer);
$this->em->flush();
return $jobOffer;
}
public function addSkill(JobOffer $jobOffer, Skill $skill, int $level)
{
$jobSkill =
(new JobSkill())
->setJobOffer($jobOffer)
->setSkill($skill)
->setLevel($level)
;
$this->em->persist($jobSkill);
$this->em->flush();
return $jobSkill;
}
public function removeSkill(JobOffer $jobOffer, Skill $skill)
{
if (($jobOfferSkill = $jobOffer->findSkill($skill)) === null) {
throw new NotFoundHttpException('projects.job_offers.skills.not_found');
}
$jobOffer->removeSkill($jobOfferSkill);
$this->em->remove($jobOfferSkill);
$this->em->flush();
}
public function updateSkillLevel(JobOffer $jobOffer, Skill $skill, int $level)
{
if (($jobOfferSkill = $jobOffer->findSkill($skill)) === null) {
throw new NotFoundHttpException('projects.job_offers.skills.not_found');
}
$jobOfferSkill->setLevel($level);
$this->em->flush();
}
}