1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace seregazhuk\HeadHunterApi\Traits; |
4
|
|
|
|
5
|
|
|
use UnexpectedValueException; |
6
|
|
|
|
7
|
|
|
trait EmployerManagers |
8
|
|
|
{ |
9
|
|
|
use ResolvesCurrentUser; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Reference types and the rights of the Manager |
13
|
|
|
* @param string|bool $employerId |
14
|
|
|
* @return array |
15
|
|
|
*/ |
16
|
|
|
public function getManagerTypes($employerId = false) |
17
|
|
|
{ |
18
|
|
|
$employerId = $this->resolveEmployerId($employerId); |
19
|
|
|
|
20
|
|
|
return $this->getResource("$employerId/manager_types", []); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get employer managers |
25
|
|
|
* |
26
|
|
|
* @param string|bool $employerId default resolved from profile |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function getManagers($employerId = false) |
30
|
|
|
{ |
31
|
|
|
$employerId = $this->resolveEmployerId($employerId); |
32
|
|
|
|
33
|
|
|
return $this->getResource("$employerId/managers", []); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get manager information |
38
|
|
|
* |
39
|
|
|
* @param string $managerId |
40
|
|
|
* @param string|bool $employerId default resolved from profile |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getManager($managerId, $employerId = false) |
44
|
|
|
{ |
45
|
|
|
$employerId = $this->resolveEmployerId($employerId); |
46
|
|
|
|
47
|
|
|
return $this->getResource("$employerId/managers/$managerId", []); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string|bool $employerId default resolved from profile |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function getManagersWhoHasVacancies($employerId = false) |
55
|
|
|
{ |
56
|
|
|
$managers = $this->getManagers($employerId); |
57
|
|
|
|
58
|
|
|
if(!isset($managers['items']) ) { |
59
|
|
|
throw new UnexpectedValueException('Failed to get employer managers'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return array_filter($managers['items'], [$this, 'hasVacancies']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param array $manager |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
protected function hasVacancies(array $manager) |
70
|
|
|
{ |
71
|
|
|
return $manager['vacancies_count'] > 0; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string|bool $employerId |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
protected function resolveEmployerId($employerId) |
79
|
|
|
{ |
80
|
|
|
return (false === $employerId) |
81
|
|
|
? $this->getCurrentEmployerId() |
82
|
|
|
: $employerId |
83
|
|
|
; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.