1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\ViewComposers; |
4
|
|
|
|
5
|
|
|
use App\Models\Applicant; |
6
|
|
|
use App\Models\JobApplication; |
7
|
|
|
use App\Models\JobPoster; |
8
|
|
|
use App\Models\Manager; |
9
|
|
|
use Facades\App\Services\WhichPortal; |
10
|
|
|
use Illuminate\View\View; |
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
use Illuminate\Support\Facades\Lang; |
13
|
|
|
use Illuminate\Support\Facades\Log; |
14
|
|
|
|
15
|
|
|
class BreadcrumbsComposer |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* The request instance. |
19
|
|
|
* |
20
|
|
|
* @var \Illuminate\Http\Request |
21
|
|
|
*/ |
22
|
|
|
protected $request; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Initialize a new composer instance. |
26
|
|
|
* |
27
|
|
|
* @param \Illuminate\Http\Request $request |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Request $request) |
31
|
|
|
{ |
32
|
|
|
$this->request = $request; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Bind data to the view. |
37
|
|
|
* |
38
|
|
|
* @param \Illuminate\View\View $view |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function compose(View $view) |
42
|
|
|
{ |
43
|
|
|
$segments = $this->parseSegments(); |
44
|
|
|
$breadcrumbs_lang = Lang::get('common/breadcrumbs'); |
45
|
|
|
$portal_specific_lang = []; |
46
|
|
|
|
47
|
|
|
if (WhichPortal::isManagerPortal()) { |
48
|
|
|
$segments = $segments->slice(1); |
49
|
|
|
$portal_specific_lang = $breadcrumbs_lang['managerPortal']; |
50
|
|
|
} elseif (WhichPortal::isHrPortal()) { |
51
|
|
|
$segments = $segments->slice(1); |
52
|
|
|
$portal_specific_lang = $breadcrumbs_lang['hrPortal']; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$view->with('breadcrumbs', $segments); |
56
|
|
|
$view->with('breadcrumbs_lang', $breadcrumbs_lang); |
57
|
|
|
$view->with('portal_specific_lang', $portal_specific_lang); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Parse the request route segments. |
62
|
|
|
* |
63
|
|
|
* @return \Illuminate\Support\Collection |
64
|
|
|
*/ |
65
|
|
|
protected function parseSegments() |
66
|
|
|
{ |
67
|
|
|
return collect($this->request->segments())->mapWithKeys(function ($segment, $key) { |
|
|
|
|
68
|
|
|
// Replaces any segment ID in url with the objects name or title. |
69
|
|
|
if ($this->request->jobPoster === $segment) { |
70
|
|
|
$poster = JobPoster::find($this->request->jobPoster); |
71
|
|
|
if ($poster !== null) { |
72
|
|
|
$segment = $poster->title; |
73
|
|
|
} |
74
|
|
|
} elseif (is_object($this->request->jobPoster) && $this->request->jobPoster->id == $segment) { |
75
|
|
|
$segment = $this->request->jobPoster->title; |
76
|
|
|
} |
77
|
|
|
if ($this->request->manager === $segment) { |
78
|
|
|
$poster = Manager::find($this->request->manager); |
79
|
|
|
if ($poster !== null) { |
80
|
|
|
$segment = $poster->title; |
81
|
|
|
} |
82
|
|
|
} elseif (is_object($this->request->manager) && $this->request->manager->id == $segment) { |
83
|
|
|
$segment = $this->request->manager->title; |
84
|
|
|
} |
85
|
|
|
if ($this->request->applicant === $segment) { |
86
|
|
|
$poster = Applicant::find($this->request->applicant); |
87
|
|
|
if ($poster !== null) { |
88
|
|
|
$segment = $poster->title; |
89
|
|
|
} |
90
|
|
|
} elseif (is_object($this->request->applicant) && $this->request->applicant->id == $segment) { |
91
|
|
|
$segment = $this->request->applicant->title; |
92
|
|
|
} |
93
|
|
|
if ($this->request->application === $segment) { |
94
|
|
|
$poster = JobApplication::find($this->request->application); |
95
|
|
|
if ($poster !== null) { |
96
|
|
|
$segment = $poster->title; |
97
|
|
|
} |
98
|
|
|
} elseif (is_object($this->request->application) && $this->request->application->id == $segment) { |
99
|
|
|
$segment = $this->request->application->title; |
100
|
|
|
} |
101
|
|
|
return [ |
102
|
|
|
$segment => implode('/', array_slice($this->request->segments(), 0, $key + 1)), |
103
|
|
|
]; |
104
|
|
|
}); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|