|
1
|
|
|
<?php namespace JobApis\Jobs\Client\Providers; |
|
2
|
|
|
|
|
3
|
|
|
use JobApis\Jobs\Client\Job; |
|
4
|
|
|
|
|
5
|
|
|
class UsajobsProvider extends AbstractProvider |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Returns the standardized job object |
|
9
|
|
|
* |
|
10
|
|
|
* NOTE: The following properties are not being set: |
|
11
|
|
|
* PositionID |
|
12
|
|
|
* DepartmentName |
|
13
|
|
|
* ApplyURI |
|
14
|
|
|
* UserArea |
|
15
|
|
|
* |
|
16
|
|
|
* @param array $payload Raw job payload from the API |
|
17
|
|
|
* |
|
18
|
|
|
* @return \JobApis\Jobs\Client\Job |
|
19
|
|
|
*/ |
|
20
|
4 |
|
public function createJobObject($payload = []) |
|
21
|
|
|
{ |
|
22
|
4 |
|
$id = $payload['MatchedObjectId']; |
|
23
|
4 |
|
$payload = $payload['MatchedObjectDescriptor']; |
|
24
|
|
|
|
|
25
|
4 |
|
$job = new Job([ |
|
26
|
4 |
|
'sourceId' => $id, |
|
27
|
4 |
|
'title' => $payload['PositionTitle'], |
|
28
|
4 |
|
'name' => $payload['PositionTitle'], |
|
29
|
4 |
|
'url' => $payload['PositionURI'], |
|
30
|
4 |
|
'qualifications' => $payload['QualificationSummary'], |
|
31
|
4 |
|
]); |
|
32
|
|
|
|
|
33
|
4 |
|
$job->setCompany($payload['OrganizationName']); |
|
34
|
|
|
|
|
35
|
4 |
|
$job = $this->setDates($payload, $job); |
|
36
|
4 |
|
$job = $this->setNestedProperties($payload, $job); |
|
37
|
4 |
|
$job = $this->setSalary($payload['PositionRemuneration'], $job); |
|
38
|
4 |
|
return $this->setLocation($payload['PositionLocation'], $job); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Job response object default keys that should be set |
|
43
|
|
|
* |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
4 |
|
public function getDefaultResponseFields() |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
|
|
|
|
|
49
|
4 |
|
'MatchedObjectId', |
|
50
|
4 |
|
'MatchedObjectDescriptor', |
|
51
|
4 |
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get listings path |
|
56
|
|
|
* |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
4 |
|
public function getListingsPath() |
|
60
|
|
|
{ |
|
61
|
4 |
|
return 'SearchResult.SearchResultItems'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Sets nested properties |
|
66
|
|
|
* |
|
67
|
|
|
* @param $payload array |
|
68
|
|
|
* @param $job \JobApis\Jobs\Client\Job |
|
69
|
|
|
* |
|
70
|
|
|
* @return \JobApis\Jobs\Client\Job |
|
71
|
|
|
*/ |
|
72
|
4 |
|
protected function setDates($payload, $job) |
|
73
|
|
|
{ |
|
74
|
|
|
$dateFields = [ |
|
75
|
4 |
|
'PublicationStartDate' => 'datePosted', |
|
76
|
4 |
|
'ApplicationCloseDate' => 'validThrough', |
|
77
|
4 |
|
'PositionStartDate' => 'startDate', |
|
78
|
4 |
|
'PositionEndDate' => 'endDate', |
|
79
|
4 |
|
]; |
|
80
|
4 |
|
foreach ($dateFields as $key => $field) { |
|
81
|
4 |
|
if (strtotime($payload[$key]) !== false) { |
|
82
|
4 |
|
$job->{'set'.ucfirst($field)}(new \DateTime($payload[$key])); |
|
83
|
4 |
|
} |
|
84
|
4 |
|
} |
|
85
|
|
|
|
|
86
|
4 |
|
return $job; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Sets nested properties |
|
91
|
|
|
* |
|
92
|
|
|
* @param $payload array |
|
93
|
|
|
* @param $job \JobApis\Jobs\Client\Job |
|
94
|
|
|
* |
|
95
|
|
|
* @return \JobApis\Jobs\Client\Job |
|
96
|
|
|
*/ |
|
97
|
4 |
|
protected function setNestedProperties($payload, $job) |
|
98
|
|
|
{ |
|
99
|
|
|
$nestedProperties = [ |
|
100
|
|
|
'PositionFormattedDescription' => [ |
|
101
|
4 |
|
'attribute' => 'Content', |
|
102
|
4 |
|
'property' => 'description', |
|
103
|
4 |
|
], |
|
104
|
|
|
'PositionSchedule' => [ |
|
105
|
4 |
|
'attribute' => 'Name', |
|
106
|
4 |
|
'property' => 'employmentType', |
|
107
|
4 |
|
], |
|
108
|
|
|
'JobCategory' => [ |
|
109
|
4 |
|
'attribute' => 'Name', |
|
110
|
4 |
|
'property' => 'occupationalCategory', |
|
111
|
4 |
|
], |
|
112
|
|
|
'PositionOfferingType' => [ |
|
113
|
4 |
|
'attribute' => 'Name', |
|
114
|
4 |
|
'property' => 'additionalType', |
|
115
|
4 |
|
], |
|
116
|
4 |
|
]; |
|
117
|
|
|
|
|
118
|
4 |
|
foreach ($nestedProperties as $property => $value) { |
|
119
|
4 |
|
if (isset($payload[$property]) |
|
120
|
4 |
|
&& isset($payload[$property][0]) |
|
121
|
4 |
|
&& isset($payload[$property][0][$value['attribute']]) |
|
122
|
4 |
|
) { |
|
123
|
4 |
|
$job->{"set".ucfirst($value['property'])}($payload[$property][0][$value['attribute']]); |
|
124
|
4 |
|
} |
|
125
|
4 |
|
} |
|
126
|
|
|
|
|
127
|
4 |
|
return $job; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Parses the salary range and adds it to the job |
|
132
|
|
|
* |
|
133
|
|
|
* @param $salaries array |
|
134
|
|
|
* @param $job \JobApis\Jobs\Client\Job |
|
135
|
|
|
* |
|
136
|
|
|
* @return \JobApis\Jobs\Client\Job |
|
137
|
|
|
*/ |
|
138
|
4 |
|
protected function setSalary($salaries, $job) |
|
139
|
|
|
{ |
|
140
|
4 |
|
if (isset($salaries[0]) && isset($salaries[0]['MinimumRange'])) { |
|
141
|
4 |
|
$job->setMinimumSalary($salaries[0]['MinimumRange']); |
|
142
|
4 |
|
} |
|
143
|
4 |
|
if (isset($salaries[0]) && isset($salaries[0]['MaximumRange'])) { |
|
144
|
4 |
|
$job->setMaximumSalary($salaries[0]['MaximumRange']); |
|
145
|
4 |
|
} |
|
146
|
|
|
// NOTE: Can also get pay shedule from $salaries[0]["RateIntervalCode"] |
|
147
|
4 |
|
return $job; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Parses the location and attaches it to the job |
|
152
|
|
|
* |
|
153
|
|
|
* @param $locations array |
|
154
|
|
|
* @param $job \JobApis\Jobs\Client\Job |
|
155
|
|
|
* |
|
156
|
|
|
* @return \JobApis\Jobs\Client\Job |
|
157
|
|
|
*/ |
|
158
|
4 |
|
protected function setLocation($locations, $job) |
|
159
|
|
|
{ |
|
160
|
4 |
|
if (isset($locations[0])) { |
|
161
|
4 |
|
if (isset($locations[0]['LocationName'])) { |
|
162
|
4 |
|
$job->setLocation($locations[0]['LocationName']); |
|
163
|
4 |
|
} |
|
164
|
4 |
|
if (isset($locations[0]['CountryCode'])) { |
|
165
|
4 |
|
$job->setCountry($locations[0]['CountryCode']); |
|
166
|
4 |
|
} |
|
167
|
4 |
|
if (isset($locations[0]['CountrySubDivisionCode'])) { |
|
168
|
4 |
|
$job->setState($locations[0]['CountrySubDivisionCode']); |
|
169
|
4 |
|
} |
|
170
|
4 |
|
if (isset($locations[0]['CityName'])) { |
|
171
|
4 |
|
$job->setCity($locations[0]['CityName']); |
|
172
|
4 |
|
} |
|
173
|
4 |
|
if (isset($locations[0]['Longitude'])) { |
|
174
|
4 |
|
$job->setLongitude($locations[0]['Longitude']); |
|
175
|
4 |
|
} |
|
176
|
4 |
|
if (isset($locations[0]['Latitude'])) { |
|
177
|
4 |
|
$job->setLatitude($locations[0]['Latitude']); |
|
178
|
4 |
|
} |
|
179
|
4 |
|
} |
|
180
|
4 |
|
return $job; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.