1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace seregazhuk\HeadHunterApi\Traits; |
4
|
|
|
|
5
|
|
|
trait EmployerManagers |
6
|
|
|
{ |
7
|
|
|
use ResolvesCurrentUser; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Reference types and the rights of the Manager |
11
|
|
|
* @param mixed $employerId |
12
|
|
|
* @return array |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
public function getManagerTypes($employerId = false) |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$employerId = $this->resolveEmployerId($employerId); |
17
|
|
|
|
18
|
|
|
$verb = sprintf("%s/manager_types", $employerId ); |
19
|
|
|
|
20
|
|
|
return $this->getResource($verb, []); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get employer managers |
26
|
|
|
* |
27
|
|
|
* @param mixed $employerId default resolved from profile |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
public function getManagers($employerId = false) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$employerId = $this->resolveEmployerId($employerId); |
33
|
|
|
|
34
|
|
|
$verb = sprintf("%s/managers", $employerId ); |
35
|
|
|
|
36
|
|
|
return $this->getResource($verb, []); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get manager information |
42
|
|
|
* |
43
|
|
|
* @param string $managerId |
44
|
|
|
* @param mixed $employerId default resolved from profile |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function getManager($managerId, $employerId = false) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$employerId = $this->resolveEmployerId($employerId); |
50
|
|
|
|
51
|
|
|
$verb = sprintf("%s/managers/%s", $employerId, $managerId ); |
52
|
|
|
|
53
|
|
|
return $this->getResource($verb, []); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param mixed $employerId default resolved from profile |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
public function getManagersWhoHasVacancies($employerId = false) |
61
|
|
|
{ |
62
|
|
|
$managers = $this->getManagers($employerId); |
63
|
|
|
|
64
|
|
|
if( !isset($managers['items']) ) { |
65
|
|
|
throw new \UnexpectedValueException("Failed to get employer managers"); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return array_filter($managers['items'], array($this, 'hasVacancies')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function hasVacancies($manager) |
72
|
|
|
{ |
73
|
|
|
return $manager['vacancies_count'] > 0; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function resolveEmployerId($employerId) |
77
|
|
|
{ |
78
|
|
|
return (false === $employerId) |
79
|
|
|
? $this->getCurrentEmployerId() |
80
|
|
|
: $employerId |
81
|
|
|
; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.