1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Resources; |
4
|
|
|
|
5
|
|
|
use App\Models\Candidate; |
6
|
|
|
use App\Models\Stage; |
7
|
|
|
use App\Services\TenantManager; |
8
|
|
|
use Illuminate\Http\Resources\Json\JsonResource; |
9
|
|
|
|
10
|
|
|
class RecruitmentResource extends JsonResource |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var TenantManager |
14
|
|
|
*/ |
15
|
|
|
protected static $tenantManager; |
16
|
|
|
|
17
|
|
|
public static function setTenantManager($tenantManager) |
18
|
|
|
{ |
19
|
|
|
self::$tenantManager = $tenantManager; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Transform the resource into an array. |
24
|
|
|
* |
25
|
|
|
* @param \Illuminate\Http\Request $request |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function toArray($request) |
30
|
|
|
{ |
31
|
|
|
$array = parent::toArray($request); |
32
|
|
|
|
33
|
|
|
unset($array['deleted_at']); |
34
|
|
|
unset($array['is_draft']); |
35
|
|
|
|
36
|
|
|
//TODO ten kawałek do optymalizacji wydajnościowej |
37
|
|
|
$stages = Stage::where('recruitment_id', $array['id'])->orderBy('order', 'asc')->get(); |
38
|
|
|
|
39
|
|
|
foreach ($stages as $stage) { |
40
|
|
|
$count = Candidate::where('recruitment_id', $array['id'])->where('stage_id', $stage->id)->count(); |
41
|
|
|
$stage->count = $count; |
42
|
|
|
$array['stages'][] = $stage; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
foreach ($array['sources'] as $key => $source) { |
46
|
|
|
unset($array['sources'][$key]['created_at']); |
47
|
|
|
unset($array['sources'][$key]['updated_at']); |
48
|
|
|
unset($array['sources'][$key]['deleted_at']); |
49
|
|
|
unset($array['sources'][$key]['recruitment_id']); |
50
|
|
|
unset($array['sources'][$key]['key']); |
51
|
|
|
unset($array['sources'][$key]['url_path']); |
52
|
|
|
|
53
|
|
|
//TODO: zduplikowany kod z SourceResource |
54
|
|
|
$array['sources'][$key]['url'] = config('app.apply_url').'/'.static::$tenantManager->getTenant()->subdomain.'/'.$source['key'] |
55
|
|
|
.'-'.preg_replace("/[^A-Za-z0-9\-]/", '', str_replace(' ', '-', $array['job_title'])); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $array; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|