1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Resources; |
4
|
|
|
|
5
|
|
|
use App\Repositories\CandidatesRepository; |
6
|
|
|
use App\Utils\PhoneFormatter; |
7
|
|
|
use Illuminate\Http\Resources\Json\JsonResource; |
8
|
|
|
|
9
|
|
|
class CandidateResource extends JsonResource |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Transform the resource into an array. |
13
|
|
|
* |
14
|
|
|
* @param \Illuminate\Http\Request $request |
15
|
|
|
* |
16
|
|
|
* @return array |
17
|
|
|
*/ |
18
|
|
|
public function toArray($request) |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
|
|
'id' => $this->id, |
|
|
|
|
22
|
|
|
'created_at' => $this->created_at, |
|
|
|
|
23
|
|
|
'updated_at' => $this->updated_at, |
|
|
|
|
24
|
|
|
'name' => $this->name, |
|
|
|
|
25
|
|
|
'email' => $this->email, |
|
|
|
|
26
|
|
|
'phone_number' => PhoneFormatter::format($this->phone_number), |
|
|
|
|
27
|
|
|
'future_agreement' => $this->future_agreement, |
|
|
|
|
28
|
|
|
'path_to_cv' => $this->path_to_cv, |
|
|
|
|
29
|
|
|
'source_id' => $this->source_id, |
|
|
|
|
30
|
|
|
'recruitment_id' => $this->recruitment_id, |
|
|
|
|
31
|
|
|
'source_recruitment_id' => $this->source_recruitment_id, |
|
|
|
|
32
|
|
|
'stage_id' => $this->stage_id, |
|
|
|
|
33
|
|
|
'rate' => $this->rate, |
|
|
|
|
34
|
|
|
'otherApplications' => $this->otherApplications(), |
35
|
|
|
'source' => $this->source, |
|
|
|
|
36
|
|
|
'recruitment' => $this->recruitment, |
|
|
|
|
37
|
|
|
'stage' => $this->stage, |
|
|
|
|
38
|
|
|
'custom_fields' => json_decode($this->custom_fields), |
|
|
|
|
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function otherApplications() |
43
|
|
|
{ |
44
|
|
|
$allowedFields = ['id', 'created_at', 'recruitment_id', 'stage_id', 'recruitment']; |
45
|
|
|
|
46
|
|
|
$otherApplications = CandidatesRepository::getOtherApplications($this->resource); |
47
|
|
|
$filtered = []; |
48
|
|
|
|
49
|
|
|
foreach ($otherApplications as $application) { |
50
|
|
|
$filtered[] = array_intersect_key($application->toArray(), array_flip($allowedFields)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $filtered; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|